From 8a1be76910ba4c773109ecd0fc0e172206725fbb Mon Sep 17 00:00:00 2001 From: Miles Yucht Date: Wed, 3 Jan 2024 10:39:33 +0100 Subject: [PATCH] Always log with text format by default (#1096) ## Changes The JSON logger is excellent as a machine-readable logger with lots of metadata, but the resulting logs are difficult to read: Image_from_Databricks Currently, we only use the friendly log printer when run from a TTY. This PR removes that restriction, so logs will be pretty-printed by default, regardless of TTY or not. If a user needs machine-readable logs, they can still use `--log-format JSON`. ## Tests Manual test: `databricks current-user me --debug | cat` uses the pretty-printing logger. ![Screenshot_02_01_2024__13_12](https://github.com/databricks/cli/assets/1850319/45fd5587-52f6-4864-b7d2-3708ed2ff87f) --- cmd/root/logger.go | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/cmd/root/logger.go b/cmd/root/logger.go index 494b28fc..48cb99a3 100644 --- a/cmd/root/logger.go +++ b/cmd/root/logger.go @@ -33,15 +33,11 @@ func (f *logFlags) makeLogHandler(opts slog.HandlerOptions) (slog.Handler, error return slog.NewJSONHandler(f.file.Writer(), &opts), nil case flags.OutputText: w := f.file.Writer() - if cmdio.IsTTY(w) { - return handler.NewFriendlyHandler(w, &handler.Options{ - Color: true, - Level: opts.Level, - ReplaceAttr: opts.ReplaceAttr, - }), nil - } - return slog.NewTextHandler(w, &opts), nil - + return handler.NewFriendlyHandler(w, &handler.Options{ + Color: cmdio.IsTTY(w), + Level: opts.Level, + ReplaceAttr: opts.ReplaceAttr, + }), nil default: return nil, fmt.Errorf("invalid log output mode: %s", f.output) }