-
Notifications
You must be signed in to change notification settings - Fork 31
/
log.go
49 lines (42 loc) · 1.23 KB
/
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
43
44
45
46
47
48
49
package main
import (
"fmt"
"os"
"github.com/kaspanet/kaspad/infrastructure/logger"
"github.com/kaspanet/kaspad/util/panics"
)
var (
backendLog = logger.NewBackend()
log = backendLog.Logger("SEED")
spawn = panics.GoroutineWrapperFunc(log)
)
func initLog(noLogFiles bool, logLevel, logFile, errLogFile string) {
level, ok := logger.LevelFromString(logLevel)
if !ok {
fmt.Fprintf(os.Stderr, "Invalid loglevel: %s", logLevel)
os.Exit(1)
}
err := backendLog.AddLogWriter(os.Stdout, level)
if err != nil {
fmt.Fprintf(os.Stderr, "Error adding stdout to the logger for level %s: %s", logger.LevelWarn, err)
os.Exit(1)
}
if !noLogFiles {
err = backendLog.AddLogFile(logFile, logger.LevelTrace)
if err != nil {
fmt.Fprintf(os.Stderr, "Error adding log file %s as log rotator for level %s: %s", logFile, logger.LevelTrace, err)
os.Exit(1)
}
err = backendLog.AddLogFile(errLogFile, logger.LevelWarn)
if err != nil {
fmt.Fprintf(os.Stderr, "Error adding log file %s as log rotator for level %s: %s", errLogFile, logger.LevelWarn, err)
os.Exit(1)
}
}
err = backendLog.Run()
if err != nil {
fmt.Fprintf(os.Stderr, "Error starting the logger: %s ", err)
os.Exit(1)
}
log.SetLevel(logger.LevelDebug)
}