Skip to content

Commit

Permalink
add levels in the entry
Browse files Browse the repository at this point in the history
  • Loading branch information
francois.parquet committed Jul 12, 2018
1 parent 4a13cde commit 0299114
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
5 changes: 3 additions & 2 deletions entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import (
// Entry is the structure wrapping a pointer to the current encoder.
// It provides easy API to work with GoJay's encoder.
type Entry struct {
enc *Encoder
l *Logger
enc *Encoder
l *Logger
Level uint8
}

// String adds a string to the log entry.
Expand Down
39 changes: 26 additions & 13 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (l *Logger) Info(msg string) {
if INFO&l.levels == 0 {
return
}
e := Entry{}
e := Entry{Level: INFO}
// then call format on formatter
enc := gojay.BorrowEncoder(l.w)
e.enc = enc
Expand All @@ -105,7 +105,8 @@ func (l *Logger) InfoWith(msg string) ChainEntry {
// if none, stop
e := ChainEntry{
Entry: Entry{
l: l,
l: l,
Level: INFO,
},
}
e.disabled = INFO&e.l.levels == 0
Expand All @@ -129,7 +130,7 @@ func (l *Logger) InfoWithFields(msg string, fields func(Entry)) {
if INFO&l.levels == 0 {
return
}
e := Entry{}
e := Entry{Level: INFO}
// then call format on formatter
enc := gojay.BorrowEncoder(l.w)
e.enc = enc
Expand All @@ -149,7 +150,7 @@ func (l *Logger) Debug(msg string) {
if DEBUG&l.levels == 0 {
return
}
e := Entry{}
e := Entry{Level: DEBUG}
// then call format on formatter
enc := gojay.BorrowEncoder(l.w)
e.enc = enc
Expand Down Expand Up @@ -191,7 +192,7 @@ func (l *Logger) DebugWithFields(msg string, fields func(Entry)) {
if DEBUG&l.levels == 0 {
return
}
e := Entry{}
e := Entry{Level: DEBUG}
// then call format on formatter
enc := gojay.BorrowEncoder(l.w)
e.enc = enc
Expand All @@ -211,7 +212,7 @@ func (l *Logger) Warn(msg string) {
if WARN&l.levels == 0 {
return
}
e := Entry{}
e := Entry{Level: WARN}
// then call format on formatter
enc := gojay.BorrowEncoder(l.w)
e.enc = enc
Expand All @@ -229,7 +230,8 @@ func (l *Logger) WarnWith(msg string) ChainEntry {
// if none, stop
e := ChainEntry{
Entry: Entry{
l: l,
l: l,
Level: WARN,
},
}
e.disabled = WARN&e.l.levels == 0
Expand All @@ -251,7 +253,9 @@ func (l *Logger) WarnWithFields(msg string, fields func(Entry)) {
if WARN&l.levels == 0 {
return
}
e := Entry{}
e := Entry{
Level: WARN,
}
// then call format on formatter
enc := gojay.BorrowEncoder(l.w)
e.enc = enc
Expand All @@ -269,7 +273,9 @@ func (l *Logger) Error(msg string) {
if ERROR&l.levels == 0 {
return
}
e := Entry{}
e := Entry{
Level: ERROR,
}
// then call format on formatter
enc := gojay.BorrowEncoder(l.w)
e.enc = enc
Expand All @@ -287,7 +293,8 @@ func (l *Logger) ErrorWith(msg string) ChainEntry {
// if none, stop
e := ChainEntry{
Entry: Entry{
l: l,
l: l,
Level: ERROR,
},
}
e.disabled = ERROR&e.l.levels == 0
Expand All @@ -309,7 +316,9 @@ func (l *Logger) ErrorWithFields(msg string, fields func(Entry)) {
if ERROR&l.levels == 0 {
return
}
e := Entry{}
e := Entry{
Level: ERROR,
}
// then call format on formatter
enc := gojay.BorrowEncoder(l.w)
e.enc = enc
Expand All @@ -327,7 +336,9 @@ func (l *Logger) Fatal(msg string) {
if FATAL&l.levels == 0 {
return
}
e := Entry{}
e := Entry{
Level: FATAL,
}
// then call format on formatter
enc := gojay.BorrowEncoder(l.w)
e.enc = enc
Expand Down Expand Up @@ -367,7 +378,9 @@ func (l *Logger) FatalWithFields(msg string, fields func(Entry)) {
if FATAL&l.levels == 0 {
return
}
e := Entry{}
e := Entry{
Level: FATAL,
}
// then call format on formatter
enc := gojay.BorrowEncoder(l.w)
e.enc = enc
Expand Down

0 comments on commit 0299114

Please sign in to comment.