gosuki/logging/mode.go

56 lines
975 B
Go
Raw Normal View History

2022-11-24 13:50:15 +00:00
// It is possible to enable debugging for execution time that happens before
// the -debug cli arg is parsed. This is possible using the GOMARK_DEBUG=X env
// variable where X is an integer for the debug level
2018-11-10 11:47:30 +00:00
package logging
import (
"os"
"strconv"
2018-11-10 11:47:30 +00:00
glogging "github.com/op/go-logging"
)
var (
log = glogging.MustGetLogger("MODE")
2018-11-10 11:47:30 +00:00
//RELEASE: Change to Release for release mode
LoggingMode = Debug
)
const EnvGomarkDebug = "GOMARK_DEBUG"
const Test = -1
const (
Release = iota
Info
Debug
)
func SetMode(lvl int) {
if lvl > Debug || lvl < -1 {
log.Warningf("using wrong debug level: %v", lvl)
return
}
LoggingMode = lvl
setLogLevel(lvl)
}
func initRuntimeMode() {
2018-11-09 17:25:50 +00:00
envDebug := os.Getenv(EnvGomarkDebug)
2018-11-09 17:25:50 +00:00
if envDebug != "" {
mode, err := strconv.Atoi(os.Getenv(EnvGomarkDebug))
if err != nil {
log.Errorf("wrong debug level: %v\n%v", envDebug, err)
}
SetMode(mode)
}
2022-12-10 01:48:50 +00:00
//TODO: disable debug log when testing
2018-11-09 17:25:50 +00:00
}