24 lines
464 B
Go
24 lines
464 B
Go
package gologger
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
const logTemplate = "[%s] %s : %s - %s\n"
|
|
|
|
func format(logEvent LogEvent) string {
|
|
data := logEvent.Ts.Format("2006-01-02 15:04:05")
|
|
msg := fmt.Sprint(logEvent.Data...)
|
|
ret := fmt.Sprintf(logTemplate, data, logEvent.Category, getLogLevelStr(logEvent.Level), msg)
|
|
return ret
|
|
}
|
|
|
|
func getLogLevelStr(level int) string {
|
|
for name, slevel := range logLevelMap {
|
|
if slevel == level {
|
|
return name
|
|
}
|
|
}
|
|
return "Unknown"
|
|
}
|