v0.1.10 trace log level added avoiding toggle
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
|||||||
|
|
||||||
// Log level constants
|
// Log level constants
|
||||||
const (
|
const (
|
||||||
|
LevelTrace int64 = -8
|
||||||
LevelDebug int64 = -4
|
LevelDebug int64 = -4
|
||||||
LevelInfo int64 = 0
|
LevelInfo int64 = 0
|
||||||
LevelWarn int64 = 4
|
LevelWarn int64 = 4
|
||||||
|
|||||||
@@ -319,6 +319,8 @@ func (f *Formatter) appendValue(dst []byte, v any, serializer *sanitizer.Seriali
|
|||||||
// LevelToString converts integer level values to string
|
// LevelToString converts integer level values to string
|
||||||
func LevelToString(level int64) string {
|
func LevelToString(level int64) string {
|
||||||
switch level {
|
switch level {
|
||||||
|
case -8:
|
||||||
|
return "TRACE"
|
||||||
case -4:
|
case -4:
|
||||||
return "DEBUG"
|
return "DEBUG"
|
||||||
case 0:
|
case 0:
|
||||||
|
|||||||
+9
-2
@@ -6,6 +6,8 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
|
"github.com/lixenwraith/log/formatter"
|
||||||
)
|
)
|
||||||
|
|
||||||
// getTrace returns a function call trace string
|
// getTrace returns a function call trace string
|
||||||
@@ -83,6 +85,8 @@ func parseKeyValue(arg string) (string, string, error) {
|
|||||||
// Level converts level string to numeric constant
|
// Level converts level string to numeric constant
|
||||||
func Level(levelStr string) (int64, error) {
|
func Level(levelStr string) (int64, error) {
|
||||||
switch strings.ToLower(strings.TrimSpace(levelStr)) {
|
switch strings.ToLower(strings.TrimSpace(levelStr)) {
|
||||||
|
case "trace":
|
||||||
|
return LevelTrace, nil
|
||||||
case "debug":
|
case "debug":
|
||||||
return LevelDebug, nil
|
return LevelDebug, nil
|
||||||
case "info":
|
case "info":
|
||||||
@@ -98,6 +102,9 @@ func Level(levelStr string) (int64, error) {
|
|||||||
case "sys":
|
case "sys":
|
||||||
return LevelSys, nil
|
return LevelSys, nil
|
||||||
default:
|
default:
|
||||||
return 0, fmtErrorf("invalid level string: '%s' (use debug, info, warn, error, proc, disk, sys)", levelStr)
|
return 0, fmtErrorf("invalid level string: '%s' (use trace, debug, info, warn, error, proc, disk, sys)", levelStr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LevelToString renders a level constant as its display name
|
||||||
|
func LevelToString(level int64) string { return formatter.LevelToString(level) }
|
||||||
|
|||||||
Reference in New Issue
Block a user