-
Notifications
You must be signed in to change notification settings - Fork 6
/
logger.go
38 lines (32 loc) · 863 Bytes
/
logger.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
package main
import (
"fmt"
"golang.zx2c4.com/wireguard/device"
)
// Use device package logger as the global logger for the application.
// device.Logger is effectively a collection of standard logging library loggers
var logger *device.Logger
// logLevel global var, defaults to error
var logLevel = device.LogLevelError
// Sets the logLevel global variable. Needs to be called before the
// initialisation of loggers
func setLogLevel(level string) {
switch level {
case "debug":
logLevel = device.LogLevelVerbose
case "error":
logLevel = device.LogLevelError
default:
fmt.Printf(
"No valid log level set, defaulting to \"error\": userSetLog=%s\n",
level,
)
}
}
// Returns a new logger using the global level variable
func newLogger(name string) *device.Logger {
return device.NewLogger(
logLevel,
fmt.Sprintf("%s: ", name),
)
}