Skip to content

Commit

Permalink
Merge pull request #369 from mikedanese/stdlog
Browse files Browse the repository at this point in the history
expose logBridge via NewStandardLog()
  • Loading branch information
k8s-ci-robot committed Mar 30, 2023
2 parents d7fc505 + 4de3d37 commit 2fdc76f
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions klog.go
Expand Up @@ -1228,6 +1228,19 @@ func CopyStandardLogTo(name string) {
stdLog.SetOutput(logBridge(sev))
}

// NewStandardLogger returns a Logger that writes to the klog logs for the
// named and lower severities.
//
// Valid names are "INFO", "WARNING", "ERROR", and "FATAL". If the name is not
// recognized, NewStandardLogger panics.
func NewStandardLogger(name string) *stdLog.Logger {
sev, ok := severity.ByName(name)
if !ok {
panic(fmt.Sprintf("klog.NewStandardLogger(%q): unknown severity", name))
}
return stdLog.New(logBridge(sev), "", stdLog.Lshortfile)
}

// logBridge provides the Write method that enables CopyStandardLogTo to connect
// Go's standard logs to the logs provided by this package.
type logBridge severity.Severity
Expand Down

0 comments on commit 2fdc76f

Please sign in to comment.