-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
log.go
63 lines (56 loc) · 1.41 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package conf
import (
"strings"
"github.com/xtls/xray-core/app/log"
clog "github.com/xtls/xray-core/common/log"
)
func DefaultLogConfig() *log.Config {
return &log.Config{
AccessLogType: log.LogType_None,
ErrorLogType: log.LogType_Console,
ErrorLogLevel: clog.Severity_Warning,
}
}
type LogConfig struct {
AccessLog string `json:"access"`
ErrorLog string `json:"error"`
LogLevel string `json:"loglevel"`
DNSLog bool `json:"dnsLog"`
}
func (v *LogConfig) Build() *log.Config {
if v == nil {
return nil
}
config := &log.Config{
ErrorLogType: log.LogType_Console,
AccessLogType: log.LogType_Console,
EnableDnsLog: v.DNSLog,
}
if v.AccessLog == "none" {
config.AccessLogType = log.LogType_None
} else if len(v.AccessLog) > 0 {
config.AccessLogPath = v.AccessLog
config.AccessLogType = log.LogType_File
}
if v.ErrorLog == "none" {
config.ErrorLogType = log.LogType_None
} else if len(v.ErrorLog) > 0 {
config.ErrorLogPath = v.ErrorLog
config.ErrorLogType = log.LogType_File
}
level := strings.ToLower(v.LogLevel)
switch level {
case "debug":
config.ErrorLogLevel = clog.Severity_Debug
case "info":
config.ErrorLogLevel = clog.Severity_Info
case "error":
config.ErrorLogLevel = clog.Severity_Error
case "none":
config.ErrorLogType = log.LogType_None
config.AccessLogType = log.LogType_None
default:
config.ErrorLogLevel = clog.Severity_Warning
}
return config
}