-
Notifications
You must be signed in to change notification settings - Fork 911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Port previous NewTestLogger flags over #7432
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,9 +38,10 @@ import ( | |
const ( | ||
skipForZapLogger = 3 | ||
// we put a default message when it is empty so that the log can be searchable/filterable | ||
defaultMsgForEmpty = "none" | ||
testLogFormatEnvVar = "TEMPORAL_TEST_LOG_FORMAT" // set to "json" for json logs in tests | ||
testLogLevelEnvVar = "TEMPORAL_TEST_LOG_LEVEL" // set to "debug" for debug level logs in tests | ||
defaultMsgForEmpty = "none" | ||
// TODO: once `NewTestLogger` has been removed, move these vars into testlogger.TestLogger | ||
TestLogFormatEnvVar = "TEMPORAL_TEST_LOG_FORMAT" // set to "json" for json logs in tests | ||
TestLogLevelEnvVar = "TEMPORAL_TEST_LOG_LEVEL" // set to "debug" for debug level logs in tests | ||
) | ||
|
||
type ( | ||
|
@@ -54,14 +55,15 @@ type ( | |
var _ Logger = (*zapLogger)(nil) | ||
|
||
// NewTestLogger returns a logger for tests | ||
// Deprecated: Use testlogger.TestLogger instead. | ||
func NewTestLogger() *zapLogger { | ||
format := os.Getenv(testLogFormatEnvVar) | ||
format := os.Getenv(TestLogFormatEnvVar) | ||
if format == "" { | ||
format = "console" | ||
} | ||
|
||
logger := BuildZapLogger(Config{ | ||
Level: os.Getenv(testLogLevelEnvVar), | ||
Level: os.Getenv(TestLogLevelEnvVar), | ||
Format: format, | ||
Development: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we port this too? it looks like it controls whether it panics on dpanic There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new TestLogger already has a flag There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need envs to control test logger? Do we use it anywhere? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. David does to switch it to JSON format; and I noticed that I actually set up my IDE to log on error level instead of debug level. So that's two use cases already. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't know we have it. |
||
}) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
package testlogger | ||
|
||
import ( | ||
"cmp" | ||
"container/list" | ||
"fmt" | ||
"os" | ||
|
@@ -156,7 +157,6 @@ type sharedTestLoggerState struct { | |
} | ||
mode Mode | ||
logExpectations bool | ||
logCaller bool | ||
level zapcore.Level | ||
} | ||
|
||
|
@@ -204,18 +204,6 @@ func LogLevel(level zapcore.Level) LoggerOption { | |
} | ||
} | ||
|
||
func WithoutCaller() LoggerOption { | ||
return func(t *TestLogger) { | ||
t.state.logCaller = false | ||
} | ||
} | ||
|
||
func LogCaller() LoggerOption { | ||
return func(t *TestLogger) { | ||
t.state.logCaller = false | ||
} | ||
} | ||
|
||
Comment on lines
-207
to
-218
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't work together with |
||
// SetLogLevel overrides the temporal test log level during this test. | ||
func SetLogLevel(tt CleanupCapableT, level zapcore.Level) LoggerOption { | ||
return func(t *TestLogger) { | ||
|
@@ -239,7 +227,6 @@ func NewTestLogger(t TestingT, mode Mode, opts ...LoggerOption) *TestLogger { | |
t: t, | ||
logExpectations: false, | ||
level: zapcore.DebugLevel, | ||
logCaller: true, | ||
mode: mode, | ||
}, | ||
} | ||
|
@@ -255,14 +242,16 @@ func NewTestLogger(t TestingT, mode Mode, opts ...LoggerOption) *TestLogger { | |
opt(tl) | ||
} | ||
if tl.wrapped == nil { | ||
ztl := zaptest.NewLogger(t, | ||
zaptest.Level(tl.state.level), | ||
zaptest.WrapOptions( | ||
zap.AddStacktrace(zap.ErrorLevel), | ||
zap.WithCaller(tl.state.logCaller), | ||
), | ||
) | ||
tl.wrapped = log.NewZapLogger(ztl).Skip(1) | ||
tl.wrapped = log.NewZapLogger( | ||
log.BuildZapLogger( | ||
log.Config{ | ||
Level: cmp.Or(os.Getenv(log.TestLogLevelEnvVar), tl.state.level.String()), | ||
Format: cmp.Or(os.Getenv(log.TestLogFormatEnvVar), "console"), | ||
}). | ||
WithOptions( | ||
zap.AddStacktrace(zap.ErrorLevel), // only include stack traces for logs with level error and above | ||
)). | ||
Skip(1) | ||
} | ||
|
||
// Only possible with a *testing.T until *rapid.T supports `Cleanup` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a ticket to remove this function and replace it with testlogger.TestLogger.