From 9ff10d3aeabe9e5776448b9f30faff5c86a21f84 Mon Sep 17 00:00:00 2001 From: Michael Snowden Date: Sun, 20 Nov 2022 09:01:48 -0800 Subject: [PATCH] Improve test log format --- common/log/config.go | 4 ++++ common/log/zap_logger.go | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/common/log/config.go b/common/log/config.go index 2c4e0e343ef..4bb143d2572 100644 --- a/common/log/config.go +++ b/common/log/config.go @@ -33,5 +33,9 @@ type ( Level string `yaml:"level"` // OutputFile is the path to the log output file OutputFile string `yaml:"outputFile"` + // Format determines the format of each log file printed to the output. + // Acceptable values are "json" or "console". The default is "json". + // Use "console" if you want stack traces to appear on multiple lines. + Format string `yaml:"format"` } ) diff --git a/common/log/zap_logger.go b/common/log/zap_logger.go index ce3d152915f..119db9f4605 100644 --- a/common/log/zap_logger.go +++ b/common/log/zap_logger.go @@ -58,6 +58,7 @@ func NewTestLogger() *zapLogger { return NewZapLogger(BuildZapLogger(Config{ // Uncomment next line if you need debug level logging in tests. // Level: "debug", + Format: "console", })) } @@ -197,11 +198,16 @@ func buildZapLogger(cfg Config, disableCaller bool) *zap.Logger { outputPath = "stdout" } + encoding := "json" + if cfg.Format == "console" { + encoding = "console" + } + config := zap.Config{ Level: zap.NewAtomicLevelAt(parseZapLevel(cfg.Level)), Development: false, Sampling: nil, - Encoding: "json", + Encoding: encoding, EncoderConfig: encodeConfig, OutputPaths: []string{outputPath}, ErrorOutputPaths: []string{outputPath},