forked from v2ray/v2ray-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.go
43 lines (38 loc) · 893 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
43
package conf
import (
"strings"
"v2ray.com/core/common/log"
)
type LogConfig struct {
AccessLog string `json:"access"`
ErrorLog string `json:"error"`
LogLevel string `json:"loglevel"`
}
func (this *LogConfig) Build() *log.Config {
if this == nil {
return nil
}
config := new(log.Config)
if len(this.AccessLog) > 0 {
config.AccessLogPath = this.AccessLog
config.AccessLogType = log.LogType_File
}
if len(this.ErrorLog) > 0 {
config.ErrorLogPath = this.ErrorLog
config.ErrorLogType = log.LogType_File
}
level := strings.ToLower(this.LogLevel)
switch level {
case "debug":
config.ErrorLogLevel = log.LogLevel_Debug
case "info":
config.ErrorLogLevel = log.LogLevel_Info
case "error":
config.ErrorLogLevel = log.LogLevel_Error
case "none":
config.ErrorLogType = log.LogType_None
default:
config.ErrorLogLevel = log.LogLevel_Warning
}
return config
}