Make TestLogger an InterceptLogger and use it a little more widely. (#22030)

This commit is contained in:
Nick Cabatoff
2023-07-24 09:35:39 -04:00
committed by GitHub
parent 050759f661
commit dc06bb9496
3 changed files with 14 additions and 11 deletions

View File

@@ -414,7 +414,7 @@ func (n *NoopAudit) RegisterNodesAndPipeline(broker *eventlogger.Broker, _ strin
}
type TestLogger struct {
hclog.Logger
hclog.InterceptLogger
Path string
File *os.File
sink hclog.SinkAdapter
@@ -446,6 +446,7 @@ func NewTestLogger(t testing.T) *TestLogger {
logger := hclog.NewInterceptLogger(&hclog.LoggerOptions{
Output: io.Discard,
IndependentLevels: true,
Name: t.Name(),
})
sink := hclog.NewSinkAdapter(&hclog.LoggerOptions{
Output: output,
@@ -454,13 +455,13 @@ func NewTestLogger(t testing.T) *TestLogger {
})
logger.RegisterSink(sink)
return &TestLogger{
Path: logPath,
File: logFile,
Logger: logger,
sink: sink,
Path: logPath,
File: logFile,
InterceptLogger: logger,
sink: sink,
}
}
func (tl *TestLogger) StopLogging() {
tl.Logger.(hclog.InterceptLogger).DeregisterSink(tl.sink)
tl.InterceptLogger.DeregisterSink(tl.sink)
}