Skip to content

Commit

Permalink
log: golangci-lint fixes.
Browse files Browse the repository at this point in the history
Signed-off-by: Krisztian Litkey <[email protected]>
  • Loading branch information
klihub authored and askervin committed Dec 11, 2024
1 parent abeff17 commit 9aa2f96
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
2 changes: 0 additions & 2 deletions pkg/log/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ const (
debugEnvVar = "LOGGER_DEBUG"
// logSourceEnvVar is the environment variable used to seed source logging.
logSourceEnvVar = "LOGGER_LOG_SOURCE"
// configModule is our module name in the runtime configuration.
configModule = "logger"
)

// srcmap tracks debugging settings for sources.
Expand Down
9 changes: 6 additions & 3 deletions pkg/log/klogcontrol/klogcontrol.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"errors"
"flag"
"fmt"
"io/ioutil"
"io"
"os"
"strings"

Expand Down Expand Up @@ -69,7 +69,7 @@ func klogError(format string, args ...interface{}) error {

// init discovers klog flags and sets up dynamic control for them.
func init() {
ctl.SetOutput(ioutil.Discard)
ctl.SetOutput(io.Discard)
klog.InitFlags(ctl.FlagSet)
ctl.VisitAll(func(f *flag.Flag) {
if name, value, ok := getEnvForFlag(f.Name); ok {
Expand All @@ -84,7 +84,10 @@ func init() {
if f.Name == "skip_headers" {
if value, _ := os.LookupEnv("JOURNAL_STREAM"); value != "" {
klog.Infof("Logging to journald, forcing headers off...")
ctl.Set(f.Name, "true")
err := ctl.Set(f.Name, "true")
if err != nil {
klog.Warningf("failed to set klog flag %s to true: %v", f.Name, err)
}
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,10 @@ func DebugEnabled(source string) bool {
func SetLevel(level Level) {
log.Lock()
defer log.Unlock()
log.setLevel(level)
err := log.setLevel(level)
if err != nil {
Default().Warn("failed to set log level to %v: %v", level, err)
}
}

// Flush flushes any pending log messages.
Expand Down
7 changes: 1 addition & 6 deletions pkg/log/signal.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,7 @@ func SetupDebugToggleSignal(sig os.Signal) {
go func(sig <-chan os.Signal) {
state := map[bool]string{false: "off", true: "on"}
for {
select {
case _, ok := <-sig:
if !ok {
return
}
}
<-sig
log.forced = !log.forced
deflog.Warn("forced full debugging is now %s...", state[log.forced])
}
Expand Down

0 comments on commit 9aa2f96

Please sign in to comment.