More options for logger
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
kolaente 2019-01-23 15:54:29 +01:00
parent 2c615774b4
commit d0987510d7
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
2 changed files with 16 additions and 9 deletions

View File

@ -35,9 +35,6 @@ var Version = "0.1"
func main() {
// Init logging
log.InitLogger()
// Set Engine
err := models.SetEngine()
if err != nil {

View File

@ -34,11 +34,21 @@ const Fmt = `%{color}%{time:` + time.RFC3339Nano + `}: %{level}` + "\t" + `▶ %
// Log is the handler for the logger
var Log = logging.MustGetLogger("vikunja")
var format = logging.MustStringFormatter(Fmt + "\n")
// Initializes the global log handler
func init() {
// We define our two backends
errBackend := logging.NewLogBackend(os.Stderr, "", 0)
stdBackend := logging.NewLogBackend(os.Stdout, "", 0)
// InitLogger initializes the global log handler
func InitLogger() {
backend := logging.NewLogBackend(os.Stderr, "", 0)
backendFormatter := logging.NewBackendFormatter(backend, format)
logging.SetBackend(backendFormatter)
// Set the standard backend
stdBackendFormatter := logging.NewBackendFormatter(stdBackend, logging.MustStringFormatter(Fmt+"\n"))
// Only warnings and more severe messages should go to the error backend
errBackendLeveled := logging.AddModuleLevel(errBackend)
errBackendLeveled.SetLevel(logging.WARNING, "")
// TODO: make a setting to define where logging should go (file, stdout)
// Set our backends
logging.SetBackend(stdBackendFormatter, errBackendLeveled)
}