Improve logging handling #57
3
main.go
3
main.go
|
@ -35,9 +35,6 @@ var Version = "0.1"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
// Init logging
|
|
||||||
log.InitLogger()
|
|
||||||
|
|
||||||
// Set Engine
|
// Set Engine
|
||||||
err := models.SetEngine()
|
err := models.SetEngine()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -34,11 +34,21 @@ const Fmt = `%{color}%{time:` + time.RFC3339Nano + `}: %{level}` + "\t" + `▶ %
|
||||||
// Log is the handler for the logger
|
// Log is the handler for the logger
|
||||||
var Log = logging.MustGetLogger("vikunja")
|
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
|
// Set the standard backend
|
||||||
func InitLogger() {
|
stdBackendFormatter := logging.NewBackendFormatter(stdBackend, logging.MustStringFormatter(Fmt+"\n"))
|
||||||
backend := logging.NewLogBackend(os.Stderr, "", 0)
|
|
||||||
backendFormatter := logging.NewBackendFormatter(backend, format)
|
// Only warnings and more severe messages should go to the error backend
|
||||||
logging.SetBackend(backendFormatter)
|
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)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user