From b6fd13a3022e2cf713e11dd7b5158d54f5a76516 Mon Sep 17 00:00:00 2001 From: Dery Rahman Ahaddienata Date: Tue, 7 Jan 2025 16:53:46 +0700 Subject: [PATCH] fix(mc2mc): print log with new line + execution project (#62) fix: print log with new line + execution project --- mc2mc/internal/client/client.go | 2 +- mc2mc/internal/client/setup.go | 3 +++ mc2mc/internal/logger/logger.go | 5 ++--- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/mc2mc/internal/client/client.go b/mc2mc/internal/client/client.go index 751da3b..a87c3e4 100644 --- a/mc2mc/internal/client/client.go +++ b/mc2mc/internal/client/client.go @@ -46,7 +46,7 @@ func (c *Client) Close() error { func (c *Client) Execute(ctx context.Context, query string) error { // execute query with odps client - c.logger.Info(fmt.Sprintf("execute: %s", query)) + c.logger.Info(fmt.Sprintf("query to execute:\n%s", query)) if err := c.OdpsClient.ExecSQL(ctx, query); err != nil { return errors.WithStack(err) } diff --git a/mc2mc/internal/client/setup.go b/mc2mc/internal/client/setup.go index e9ee6a7..818693d 100644 --- a/mc2mc/internal/client/setup.go +++ b/mc2mc/internal/client/setup.go @@ -15,6 +15,9 @@ func SetupDefaultProject(project string) SetupFn { if c.OdpsClient == nil { return errors.New("odps client is required") } + if project == "" { + return nil + } c.OdpsClient.SetDefaultProject(project) return nil } diff --git a/mc2mc/internal/logger/logger.go b/mc2mc/internal/logger/logger.go index f0099f1..14477ba 100644 --- a/mc2mc/internal/logger/logger.go +++ b/mc2mc/internal/logger/logger.go @@ -2,7 +2,6 @@ package logger import ( "log/slog" - "os" "github.com/pkg/errors" ) @@ -13,8 +12,8 @@ func NewLogger(logLevel string) (*slog.Logger, error) { return nil, errors.WithStack(err) } - writter := slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: level}) - return slog.New(writter), nil + slog.SetLogLoggerLevel(level) + return slog.Default(), nil } func NewDefaultLogger() *slog.Logger {