Skip to content

Commit

Permalink
Add structured.
Browse files Browse the repository at this point in the history
  • Loading branch information
jortel committed May 2, 2023
1 parent 1a6fea8 commit 23477a3
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions logr/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ import (

const (
EnvDevelopment = "LOG_DEVELOPMENT"
EnvJson = "LOG_JSON"
EnvStructured = "LOG_STRUCTURED"
EnvLevel = "LOG_LEVEL"
)

//
// Sink -.
type Sink struct {
development bool
delegate *log.Logger
fields log.Fields
name string
json bool
development bool
structured bool
level int
}

Expand All @@ -49,9 +49,9 @@ func (s *Sink) Init(_ logr.RuntimeInfo) {
fmt.DisableQuote = true
s.delegate.SetFormatter(fmt)
}
v = os.Getenv(EnvJson)
s.json, _ = strconv.ParseBool(v)
if s.json {
v = os.Getenv(EnvStructured)
s.structured, _ = strconv.ParseBool(v)
if s.structured {
fmt := new(log.JSONFormatter)
fmt.PrettyPrint = true
s.delegate.Formatter = fmt
Expand Down Expand Up @@ -84,7 +84,7 @@ func (s *Sink) Error(err error, message string, kvpair ...interface{}) {
kvpair...)
kvpair = context
}
if s.json {
if s.structured {
fields := s.asFields(kvpair...)
fields["error"] = xErr.Error()
fields["stack"] = xErr.Stack()
Expand Down

0 comments on commit 23477a3

Please sign in to comment.