-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.go
27 lines (23 loc) · 832 Bytes
/
log.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package main
import (
"github.com/op/go-logging"
"os"
)
// NewLogger creates instance of logger that should be used
// in all server handlers and routines. The idea is to have
// unified style of logging - logger is configured only once
// and at one place
func NewLogger(log_format string, level string) (*logging.Logger, error) {
backend := logging.NewLogBackend(os.Stderr, "", 0)
format := logging.MustStringFormatter(log_format)
backendFormatter := logging.NewBackendFormatter(backend, format)
backendLeveled := logging.AddModuleLevel(backendFormatter)
logLevel, err := logging.LogLevel(level)
if err != nil {
return nil, err
}
backendLeveled.SetLevel(logLevel, "")
logging.SetBackend(backendLeveled)
logger := logging.MustGetLogger("server")
return logger, nil
}