Skip to content

Commit

Permalink
all: legacy trace log
Browse files Browse the repository at this point in the history
  • Loading branch information
Mizzick committed Sep 30, 2024
1 parent 954d7d2 commit 86e7acf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
16 changes: 14 additions & 2 deletions log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ const (
ERROR
INFO
DEBUG
TRACE
)

// String implements fmt.Stringer for Level
func (l Level) String() string {
switch l {
case TRACE:
return "trace"
case DEBUG:
return "debug"
case INFO:
Expand Down Expand Up @@ -179,13 +182,20 @@ func Debug(format string, args ...any) {
}
}

// Tracef writes to debug log and adds the calling function's name
func Tracef(format string, args ...any) {
// Debugf writes to debug log and adds the calling function's name.
func Debugf(format string, args ...any) {
if atomic.LoadUint32(&level) >= uint32(DEBUG) {
writeLog("debug", getCallerName(), format, args...)
}
}

// Trace writes to trace log.
func Trace(format string, args ...any) {
if atomic.LoadUint32(&level) >= uint32(TRACE) {
writeLog("trace", "", format, args...)
}
}

// Get goroutine ID
// (https://blog.sgmansfield.com/2015/12/goroutine-ids/)
func goroutineID() uint64 {
Expand Down Expand Up @@ -256,6 +266,8 @@ func (w *stdLogWriter) Write(p []byte) (n int, err error) {
logFunc = Debug
case INFO:
logFunc = Info
case TRACE:
logFunc = Trace
}

if prefix := w.prefix; prefix == "" {
Expand Down
2 changes: 2 additions & 0 deletions logutil/slogutil/legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ type logFunction func(format string, args ...any)
// returned.
func logFuncForLevel(lvl slog.Level) (logFunc logFunction, warnStr string, err error) {
switch lvl {
case LevelTrace:
return aglog.Trace, "", nil
case slog.LevelDebug:
return aglog.Debug, "", nil
case slog.LevelInfo:
Expand Down

0 comments on commit 86e7acf

Please sign in to comment.