Skip to content

Commit

Permalink
Improve GetLogger(ctx).{Info,Warn,Error} with nil host (#1821)
Browse files Browse the repository at this point in the history
Instead of calling `glog.V(9).Infof("[%s]: %q", sev, msg)`, we just call
`glog`'s structured logging methods directly.
  • Loading branch information
iwahbe committed Apr 1, 2024
1 parent ba3fcc6 commit 4a13c5f
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions unstable/logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package logging

import (
"context"
"fmt"
"io"
"os"
"regexp"
Expand Down Expand Up @@ -162,21 +161,19 @@ func (l *host[L]) f(severity diag.Severity, msg string) {
}

// We failed to write out a clean error message, so lets write to glog.
var sev string
var logF func(args ...any)
switch severity {
case diag.Debug:
sev = "Debug"
case diag.Info:
sev = "Info"
logF = glog.Info
case diag.Warning:
sev = "Warning"
logF = glog.Warning
case diag.Error:
sev = "Error"
default:
sev = fmt.Sprintf("%#v", severity)
logF = glog.Error
default: // Includes Debug
logF = glog.V(9).Info
}

glog.V(9).Infof("[%s]: %q", sev, msg)
logF(msg)
}

func (l *host[L]) Status() L {
Expand Down

0 comments on commit 4a13c5f

Please sign in to comment.