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:

<img width="1601" alt="Image_from_Databricks"
src="https://github.com/databricks/cli/assets/1850319/76aa852f-756f-4e0a-bc00-3a6e3224296a">

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)
This commit is contained in:
Miles Yucht 2024-01-03 10:39:33 +01:00 committed by GitHub
parent 167deec8c3
commit 8a1be76910
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 9 deletions

View File

@ -33,15 +33,11 @@ func (f *logFlags) makeLogHandler(opts slog.HandlerOptions) (slog.Handler, error
return slog.NewJSONHandler(f.file.Writer(), &opts), nil return slog.NewJSONHandler(f.file.Writer(), &opts), nil
case flags.OutputText: case flags.OutputText:
w := f.file.Writer() w := f.file.Writer()
if cmdio.IsTTY(w) {
return handler.NewFriendlyHandler(w, &handler.Options{ return handler.NewFriendlyHandler(w, &handler.Options{
Color: true, Color: cmdio.IsTTY(w),
Level: opts.Level, Level: opts.Level,
ReplaceAttr: opts.ReplaceAttr, ReplaceAttr: opts.ReplaceAttr,
}), nil }), nil
}
return slog.NewTextHandler(w, &opts), nil
default: default:
return nil, fmt.Errorf("invalid log output mode: %s", f.output) return nil, fmt.Errorf("invalid log output mode: %s", f.output)
} }