Skip to content

Commit

Permalink
Add some tee logging to the logger
Browse files Browse the repository at this point in the history
  • Loading branch information
banjoh committed Feb 8, 2023
1 parent 85da9f9 commit 63900dc
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion pkg/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (l *pipeLogOuput) Output(calldepth int, logline string) error {
// TODO: Pipe logs downstream to a file
// TODO: Do we need to buffer the logs and flush them periodically,
// or will klog do this for us?
fmt.Println(logline)
fmt.Println("TEE'd LOG: ", logline)
return nil
}

Expand All @@ -77,16 +77,36 @@ type logger struct {
var _ logr.LogSink = &logger{}
var _ logr.CallDepthLogSink = &logger{}

// Tee logs downstream
// Copied from stdr.go
func (l logger) teeInfo(level int, msg string, kvList ...interface{}) {
prefix, args := l.FormatInfo(level, msg, kvList)
if prefix != "" {
args = prefix + ": " + args
}
_ = l.std.Output(l.Formatter.GetDepth()+1, args)
}

func (l logger) teeError(err error, msg string, kvList ...interface{}) {
prefix, args := l.FormatError(err, msg, kvList)
if prefix != "" {
args = prefix + ": " + args
}
_ = l.std.Output(l.Formatter.GetDepth()+1, args)
}

func (l logger) Enabled(level int) bool {
return l.verbosity >= level
}

func (l logger) Info(level int, msg string, kvList ...interface{}) {
l.lgr.GetSink().Info(level, msg, kvList...)
l.teeInfo(level, msg, kvList...)
}

func (l logger) Error(err error, msg string, kvList ...interface{}) {
l.lgr.GetSink().Error(err, msg, kvList...)
l.teeError(err, msg, kvList...)
}

func (l logger) WithName(name string) logr.LogSink {
Expand Down

0 comments on commit 63900dc

Please sign in to comment.