2023-11-29 10:16:56 +08:00
|
|
|
package gologger
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2023-12-10 00:40:28 +08:00
|
|
|
const logTemplate = "[%s] %s : %s - %s\n"
|
2023-11-29 10:16:56 +08:00
|
|
|
|
|
|
|
func format(logEvent LogEvent) string {
|
|
|
|
data := logEvent.Ts.Format("2006-01-02 15:04:05")
|
|
|
|
msg := fmt.Sprint(logEvent.Data...)
|
2023-12-10 00:40:49 +08:00
|
|
|
ret := fmt.Sprintf(logTemplate, data, logEvent.Category, getLogLevelStr(logEvent.Level), msg)
|
2023-11-29 10:16:56 +08:00
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
|
|
|
func getLogLevelStr(level int) string {
|
|
|
|
for name, slevel := range logLevelMap {
|
|
|
|
if slevel == level {
|
|
|
|
return name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "Unknown"
|
|
|
|
}
|