add logger name

This commit is contained in:
kingecg 2023-03-11 21:40:33 +08:00
parent d50d4e7f1b
commit 343bc3e4ea
2 changed files with 6 additions and 4 deletions

View File

@ -22,6 +22,7 @@ func (c *ConsoleAppender) GetName() string {
func (c *ConsoleAppender) Append(logEvent LogEvent) { func (c *ConsoleAppender) Append(logEvent LogEvent) {
data := []interface{}{ data := []interface{}{
logEvent.Ts.Format("2006-01-02 15:04:05"), logEvent.Ts.Format("2006-01-02 15:04:05"),
"[" + logEvent.ELogger.Name + "]",
" ", " ",
} }
dmsg := fmt.Sprint(logEvent.Data) dmsg := fmt.Sprint(logEvent.Data)

View File

@ -25,9 +25,10 @@ type Logger struct {
} }
type LogEvent struct { type LogEvent struct {
Ts time.Time Ts time.Time
Level int Level int
Data []interface{} Data []interface{}
ELogger *Logger
} }
type LoggerAppender interface { type LoggerAppender interface {
@ -45,7 +46,7 @@ func (l *Logger) log(Level int, msg []interface{}) {
if Level <= l.Level { if Level <= l.Level {
now := time.Now() now := time.Now()
logEvent := LogEvent{now, Level, msg} logEvent := LogEvent{now, Level, msg, l}
l.Appender.Append(logEvent) l.Appender.Append(logEvent)
// fmt.Println(now.Format("2006-01-02 15:04:05"), " ", l.Name, ": ", msg) // fmt.Println(now.Format("2006-01-02 15:04:05"), " ", l.Name, ": ", msg)
} }