mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
Add new logging
This commit is contained in:
parent
1308694711
commit
7cea7ea9e2
1 changed files with 48 additions and 0 deletions
48
logging.go
Normal file
48
logging.go
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
log "github.com/cihub/seelog"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
|
||||||
|
SetLogLevel("debug")
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetLogLevel determines the log level
|
||||||
|
func SetLogLevel(level string) (err error) {
|
||||||
|
|
||||||
|
// https://en.wikipedia.org/wiki/ANSI_escape_code#3/4_bit
|
||||||
|
// https://github.com/cihub/seelog/wiki/Log-levels
|
||||||
|
appConfig := `
|
||||||
|
<seelog minlevel="` + level + `">
|
||||||
|
<outputs formatid="stdout">
|
||||||
|
<filter levels="debug,trace">
|
||||||
|
<console formatid="debug"/>
|
||||||
|
</filter>
|
||||||
|
<filter levels="info">
|
||||||
|
<console formatid="info"/>
|
||||||
|
</filter>
|
||||||
|
<filter levels="critical,error">
|
||||||
|
<console formatid="error"/>
|
||||||
|
</filter>
|
||||||
|
<filter levels="warn">
|
||||||
|
<console formatid="warn"/>
|
||||||
|
</filter>
|
||||||
|
</outputs>
|
||||||
|
<formats>
|
||||||
|
<format id="stdout" format="%Date %Time [%LEVEL] %File %FuncShort:%Line %Msg %n" />
|
||||||
|
<format id="debug" format="%Date %Time %EscM(37)[%LEVEL]%EscM(0) %File %FuncShort:%Line %Msg %n" />
|
||||||
|
<format id="info" format="%EscM(36)[%LEVEL]%EscM(0) %Msg %n" />
|
||||||
|
<format id="warn" format="%Date %Time %EscM(33)[%LEVEL]%EscM(0) %File %FuncShort:%Line %Msg %n" />
|
||||||
|
<format id="error" format="%Date %Time %EscM(31)[%LEVEL]%EscM(0) %File %FuncShort:%Line %Msg %n" />
|
||||||
|
</formats>
|
||||||
|
</seelog>
|
||||||
|
`
|
||||||
|
logger, err := log.LoggerFromConfigAsBytes([]byte(appConfig))
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.ReplaceLogger(logger)
|
||||||
|
return
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue