Skip to content

Commit

Permalink
add helpers
Browse files Browse the repository at this point in the history
Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
  • Loading branch information
jsign committed Sep 8, 2021
1 parent f1c5d98 commit 4236f06
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions log.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
package log

import (
"encoding/json"
"time"

"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)

// StandardLogger provides API compatibility with standard printf loggers
Expand Down Expand Up @@ -73,3 +75,28 @@ func (logger *ZapEventLogger) Warningf(format string, args ...interface{}) {
func FormatRFC3339(t time.Time) string {
return t.UTC().Format(time.RFC3339Nano)
}

// SetLogLevels sets levels for the given systems.
func SetLogLevels(systems map[string]LogLevel) error {
for sys, level := range systems {
l := zapcore.Level(level)
if sys == "*" {
for _, s := range GetSubsystems() {
if err := SetLogLevel(s, l.CapitalString()); err != nil {
return err
}
}
}
if err := SetLogLevel(sys, l.CapitalString()); err != nil {
return err
}
}
return nil
}

// MustJSONIndent is an errorless method to json indent structs so they can be printed
// in log.XXXf in a single line.
func MustJSONIndent(b interface{}) string {
jsn, _ := json.MarshalIndent(b, "", " ")
return string(jsn)
}

0 comments on commit 4236f06

Please sign in to comment.