-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(log): Introduce Trace log level (#412)
* feat: add trace level to logger * fix: rework new trace logger implementation to build on tags Now building 2 different types of the Logger interface depending on a build tag Added implementations for printing the log level properly Moved the default log level back to Debug Removed tests that tried to test new trace functionality on a test file without the build tag --------- Co-authored-by: serkan.begar <serkan.begar@1nce.com>
- Loading branch information
1 parent
585ad1f
commit 9946e28
Showing
15 changed files
with
254 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package silentzap | ||
|
||
import ( | ||
"fmt" | ||
|
||
"go.uber.org/zap/zapcore" | ||
) | ||
|
||
func capitalLevelEncoder(l zapcore.Level, enc zapcore.PrimitiveArrayEncoder) { | ||
if l == logLevels["Trace"] { | ||
enc.AppendString("TRACE") | ||
return | ||
} | ||
|
||
zapcore.CapitalLevelEncoder(l, enc) | ||
} | ||
|
||
func capitalColorLevelEncoder(l zapcore.Level, enc zapcore.PrimitiveArrayEncoder) { | ||
if l == logLevels["Trace"] { | ||
enc.AppendString(fmt.Sprintf("\x1b[36m%s\x1b[0m", "TRACE")) // Cyan colored TRACE | ||
return | ||
} | ||
|
||
zapcore.CapitalColorLevelEncoder(l, enc) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
//go:build !tracelog | ||
|
||
package silentzap | ||
|
||
// allowedLevels returns allowed levels for the standard logger. | ||
const allowedLevels = `*"Debug" | "Info" | "Warn" | "Error" | "DPanic" | "Panic" | "Fatal"` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
//go:build tracelog | ||
|
||
package silentzap | ||
|
||
// allowedLevels returns allowed levels for the trace logger. | ||
const allowedLevels = `"Trace" | *"Debug" | "Info" | "Warn" | "Error" | "DPanic" | "Panic" | "Fatal"` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package zap | ||
|
||
import ( | ||
"fmt" | ||
|
||
"go.uber.org/zap/zapcore" | ||
) | ||
|
||
func capitalLevelEncoder(l zapcore.Level, enc zapcore.PrimitiveArrayEncoder) { | ||
if l == logLevels["Trace"] { | ||
enc.AppendString("TRACE") | ||
return | ||
} | ||
|
||
zapcore.CapitalLevelEncoder(l, enc) | ||
} | ||
|
||
func capitalColorLevelEncoder(l zapcore.Level, enc zapcore.PrimitiveArrayEncoder) { | ||
if l == logLevels["Trace"] { | ||
enc.AppendString(fmt.Sprintf("\x1b[36m%s\x1b[0m", "TRACE")) // Cyan colored TRACE | ||
return | ||
} | ||
|
||
zapcore.CapitalColorLevelEncoder(l, enc) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
//go:build !tracelog | ||
|
||
package zap | ||
|
||
// allowedLevels returns allowed levels for the standard logger. | ||
const allowedLevels = `*"Debug" | "Info" | "Warn" | "Error" | "DPanic" | "Panic" | "Fatal"` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
//go:build tracelog | ||
|
||
package zap | ||
|
||
// allowedLevels returns allowed levels for the trace logger. | ||
const allowedLevels = `"Trace" | *"Debug" | "Info" | "Warn" | "Error" | "DPanic" | "Panic" | "Fatal"` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//go:build !tracelog | ||
|
||
package flamingo | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
type ( | ||
// Logger defines the standard Flamingo logger interface | ||
Logger interface { | ||
WithContext(ctx context.Context) Logger | ||
|
||
Debug(args ...interface{}) | ||
Info(args ...interface{}) | ||
Warn(args ...interface{}) | ||
Error(args ...interface{}) | ||
Fatal(args ...interface{}) | ||
Panic(args ...interface{}) | ||
|
||
Debugf(log string, args ...interface{}) | ||
|
||
WithField(key LogKey, value interface{}) Logger | ||
WithFields(fields map[LogKey]interface{}) Logger | ||
|
||
Flush() | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.