mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-04 06:54:45 +08:00
优化日志输出格式
This commit is contained in:
@@ -1,10 +1,10 @@
|
|||||||
package log
|
package log
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log/slog"
|
|
||||||
"io"
|
|
||||||
"path/filepath"
|
|
||||||
"context"
|
"context"
|
||||||
|
"io"
|
||||||
|
"log/slog"
|
||||||
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
"sync"
|
"sync"
|
||||||
@@ -35,21 +35,21 @@ type OriginJsonHandler struct {
|
|||||||
func getStrLevel(level slog.Level) string{
|
func getStrLevel(level slog.Level) string{
|
||||||
switch level {
|
switch level {
|
||||||
case LevelTrace:
|
case LevelTrace:
|
||||||
return "TRACE"
|
return "Trace"
|
||||||
case LevelDebug:
|
case LevelDebug:
|
||||||
return "DEBUG"
|
return "Debug"
|
||||||
case LevelInfo:
|
case LevelInfo:
|
||||||
return "INFO"
|
return "Info"
|
||||||
case LevelWarning:
|
case LevelWarning:
|
||||||
return "WARNING"
|
return "Warning"
|
||||||
case LevelError:
|
case LevelError:
|
||||||
return "ERROR"
|
return "Error"
|
||||||
case LevelStack:
|
case LevelStack:
|
||||||
return "STACK"
|
return "Stack"
|
||||||
case LevelDump:
|
case LevelDump:
|
||||||
return "DUMP"
|
return "Dump"
|
||||||
case LevelFatal:
|
case LevelFatal:
|
||||||
return "FATAL"
|
return "Fatal"
|
||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
@@ -98,6 +98,7 @@ func (oh *OriginTextHandler) Handle(context context.Context, record slog.Record)
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return oh.TextHandler.Handle(context, record)
|
return oh.TextHandler.Handle(context, record)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
17
log/log.go
17
log/log.go
@@ -489,23 +489,8 @@ func (logger *Logger) formatHeader(buf *Buffer,level slog.Level,calldepth int) {
|
|||||||
file = filepath.Base(file)
|
file = filepath.Base(file)
|
||||||
|
|
||||||
buf.AppendString("time=\"")
|
buf.AppendString("time=\"")
|
||||||
year, month, day := t.Date()
|
buf.AppendString(t.Format("2006/01/02 15:04:05"))
|
||||||
buf.AppendInt(int64(year))
|
|
||||||
buf.AppendByte('/')
|
|
||||||
buf.AppendInt(int64(month))
|
|
||||||
buf.AppendByte('/')
|
|
||||||
buf.AppendInt(int64(day))
|
|
||||||
buf.AppendByte(' ')
|
|
||||||
|
|
||||||
hour, min, sec := t.Clock()
|
|
||||||
buf.AppendInt(int64(hour))
|
|
||||||
buf.AppendByte(':')
|
|
||||||
buf.AppendInt(int64(min))
|
|
||||||
buf.AppendByte(':')
|
|
||||||
|
|
||||||
buf.AppendInt(int64(sec))
|
|
||||||
buf.AppendString("\"")
|
buf.AppendString("\"")
|
||||||
|
|
||||||
logger.sBuff.AppendString(" level=")
|
logger.sBuff.AppendString(" level=")
|
||||||
logger.sBuff.AppendString(getStrLevel(level))
|
logger.sBuff.AppendString(getStrLevel(level))
|
||||||
logger.sBuff.AppendString(" source=")
|
logger.sBuff.AppendString(" source=")
|
||||||
|
|||||||
Reference in New Issue
Block a user