Skip to content

Commit 5338f96

Browse files
authored
Add env vars to control log format and level for tests (#3836)
1 parent 4f53af9 commit 5338f96

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

common/log/zap_logger.go

+10-5
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ import (
4040
const (
4141
skipForZapLogger = 3
4242
// we put a default message when it is empty so that the log can be searchable/filterable
43-
defaultMsgForEmpty = "none"
43+
defaultMsgForEmpty = "none"
44+
testLogFormatEnvVar = "TEMPORAL_TEST_LOG_FORMAT" // set to "json" for json logs in tests
45+
testLogLevelEnvVar = "TEMPORAL_TEST_LOG_LEVEL" // set to "debug" for debug level logs in tests
4446
)
4547

4648
type (
@@ -53,12 +55,15 @@ type (
5355

5456
var _ Logger = (*zapLogger)(nil)
5557

56-
// NewTestLogger returns a logger at debug level and log into STDERR
58+
// NewTestLogger returns a logger for tests
5759
func NewTestLogger() *zapLogger {
60+
format := os.Getenv(testLogFormatEnvVar)
61+
if format == "" {
62+
format = "console"
63+
}
5864
return NewZapLogger(BuildZapLogger(Config{
59-
// Uncomment next line if you need debug level logging in tests.
60-
// Level: "debug",
61-
Format: "console",
65+
Level: os.Getenv(testLogLevelEnvVar),
66+
Format: format,
6267
Development: true,
6368
}))
6469
}

0 commit comments

Comments
 (0)