forked from thrasher-corp/gocryptotrader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger_types.go
103 lines (87 loc) · 2.47 KB
/
logger_types.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package log
import (
"io"
"sync"
)
const (
timestampFormat = " 02/01/2006 15:04:05 "
spacer = " | "
// DefaultMaxFileSize for logger rotation file
DefaultMaxFileSize int64 = 100
)
var (
logger = &Logger{}
// FileLoggingConfiguredCorrectly flag set during config check if file logging meets requirements
FileLoggingConfiguredCorrectly bool
// GlobalLogConfig holds global configuration options for logger
GlobalLogConfig = &Config{}
// GlobalLogFile hold global configuration options for file logger
GlobalLogFile = &Rotate{}
eventPool = &sync.Pool{
New: func() interface{} {
return &Event{
data: make([]byte, 0, 80),
}
},
}
// LogPath system path to store log files in
LogPath string
// RWM read/write mutex for logger
RWM = &sync.RWMutex{}
)
// Config holds configuration settings loaded from bot config
type Config struct {
Enabled *bool `json:"enabled"`
SubLoggerConfig
LoggerFileConfig *loggerFileConfig `json:"fileSettings,omitempty"`
AdvancedSettings advancedSettings `json:"advancedSettings"`
SubLoggers []SubLoggerConfig `json:"subloggers,omitempty"`
}
type advancedSettings struct {
ShowLogSystemName *bool `json:"showLogSystemName"`
Spacer string `json:"spacer"`
TimeStampFormat string `json:"timeStampFormat"`
Headers headers `json:"headers"`
}
type headers struct {
Info string `json:"info"`
Warn string `json:"warn"`
Debug string `json:"debug"`
Error string `json:"error"`
}
// SubLoggerConfig holds sub logger configuration settings loaded from bot config
type SubLoggerConfig struct {
Name string `json:"name,omitempty"`
Level string `json:"level"`
Output string `json:"output"`
}
type loggerFileConfig struct {
FileName string `json:"filename,omitempty"`
Rotate *bool `json:"rotate,omitempty"`
MaxSize int64 `json:"maxsize,omitempty"`
}
// Logger each instance of logger settings
type Logger struct {
ShowLogSystemName bool
Timestamp string
InfoHeader, ErrorHeader, DebugHeader, WarnHeader string
Spacer string
}
// Levels flags for each sub logger type
type Levels struct {
Info, Debug, Warn, Error bool
}
type subLogger struct {
name string
Levels
output io.Writer
}
// Event holds the data sent to the log and which multiwriter to send to
type Event struct {
data []byte
output io.Writer
}
type multiWriter struct {
writers []io.Writer
mu sync.RWMutex
}