forked from vguardbc/vguardbft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.go
62 lines (55 loc) · 1.66 KB
/
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"fmt"
"github.com/sirupsen/logrus"
"os"
"path"
"runtime"
"strconv"
)
func setLogger() {
log.SetLevel(logrus.Level(LogLevel))
if PlainStorage {
e := os.RemoveAll(fmt.Sprintf("./logs/s%d", ServerID))
if e != nil {
log.Fatal(e)
}
log.Infof(">> old logs removed at " + fmt.Sprintf("./logs/s%d", ServerID))
if err := os.Mkdir(fmt.Sprintf("./logs/s%d", ServerID), os.ModePerm); err != nil {
log.Error(err)
}
log.Infof(">> new log folder created at " + fmt.Sprintf("./logs/s%d", ServerID))
log.Formatter = &logrus.TextFormatter{
ForceColors: false,
DisableColors: true,
ForceQuote: false,
EnvironmentOverrideColors: false,
DisableTimestamp: true,
FullTimestamp: false,
TimestampFormat: "",
DisableSorting: false,
SortingFunc: nil,
DisableLevelTruncation: false,
PadLevelText: false,
QuoteEmptyFields: false,
FieldMap: nil,
CallerPrettyfier: nil,
}
log.Out = os.Stdout
fileName := fmt.Sprintf("./logs/s%d/n_%d_b%d_d%d.log", ServerID, NumOfConn, BatchSize, Delay)
file, err := os.OpenFile(fileName, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
if err != nil {
log.Info("Failed to log to file, using default stderr")
}
log.Out = file
return
}
log.SetReportCaller(true)
log.SetFormatter(&logrus.TextFormatter{
CallerPrettyfier: func(frame *runtime.Frame) (function string, file string) {
fileName := path.Base(frame.File) + ":" + strconv.Itoa(frame.Line) + ""
//return frame.Function, fileName
return "", fileName + " >>"
},
})
}