You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
The current fxtest logger provided by fxtest.WithTestLogger is quite verbose, printing everything. When something fails in tests, I have to scroll down all the log messages until I find information about the actual error.
Describe the solution you'd like
An option that would print only errors, akin to how fxevent.SlogLogger where we can do:
Describe alternatives you've considered
Implementing a package like so:
// tbWriter is a io.Writer that writes to the provided test logger.typetbWriterstruct {
t testing.TB
}
// Write writes the provided bytes to the underlying testing.TB.func (wtbWriter) Write(bs []byte) (int, error) {
w.t.Logf("%s", bs)
returnlen(bs), nil
}
// QuietConsoleLogger is a fx logger that only logs errors.typeQuietConsoleLoggerstruct {
fxevent.ConsoleLogger
}
// LogEvent logs the provided event if it is an error.func (mQuietConsoleLogger) LogEvent(event fxevent.Event) {
rv:=reflect.Indirect(reflect.ValueOf(event))
errRv:=rv.FieldByName("Err")
if!errRv.IsValid() {
return
}
err, ok:=errRv.Interface().(error)
ifok&&err!=nil {
m.ConsoleLogger.LogEvent(event)
}
}
// WithQuietTestLogger provides a fx logger for tests that is silent except on errors.funcWithQuietTestLogger(t testing.TB) fxevent.Logger {
returnQuietConsoleLogger{
ConsoleLogger: fxevent.ConsoleLogger{
W: tbWriter{t},
},
}
}
Is this a breaking change?
No.
Additional context
N/A
The text was updated successfully, but these errors were encountered:
FWIW at my work we've implemented something closer to #1167:
It buffers all the events in memory, and flushes them only if there was an error.
To determine that there was an error, it uses logic similar to what you have above.
Thinking out loud: It might make sense for events to report a severity, which would translate directly to log levels.
Each event could pick its severity based on whether Err is nil or not for its fields.
Is your feature request related to a problem? Please describe.
The current fxtest logger provided by
fxtest.WithTestLogger
is quite verbose, printing everything. When something fails in tests, I have to scroll down all the log messages until I find information about the actual error.Describe the solution you'd like
An option that would print only errors, akin to how
fxevent.SlogLogger
where we can do:To suppress every log, except errors.
Describe alternatives you've considered
Implementing a package like so:
Is this a breaking change?
No.
Additional context
N/A
The text was updated successfully, but these errors were encountered: