forked from wailsapp/wails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.go
42 lines (36 loc) · 892 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package wails
import (
"os"
"strings"
log "github.com/sirupsen/logrus"
)
// Global logger reference
var logger = log.New()
// Fields is used by the customLogger object to output
// fields along with a message
type Fields map[string]interface{}
// Default options for the global logger
func init() {
logger.SetOutput(os.Stdout)
logger.SetLevel(log.DebugLevel)
}
// Sets the log level to the given level
func setLogLevel(level string) {
switch strings.ToLower(level) {
case "info":
logger.SetLevel(log.InfoLevel)
case "debug":
logger.SetLevel(log.DebugLevel)
case "warn":
logger.SetLevel(log.WarnLevel)
case "error":
logger.SetLevel(log.ErrorLevel)
case "fatal":
logger.SetLevel(log.FatalLevel)
case "panic":
logger.SetLevel(log.PanicLevel)
default:
logger.SetLevel(log.DebugLevel)
logger.Warnf("Log level '%s' not recognised. Setting to Debug.", level)
}
}