2019-02-10 13:04:11 -05:00
|
|
|
package conf
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
2021-02-16 15:31:50 -05:00
|
|
|
"github.com/v2fly/v2ray-core/v4/app/log"
|
|
|
|
clog "github.com/v2fly/v2ray-core/v4/common/log"
|
2019-02-10 13:04:11 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
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"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *LogConfig) Build() *log.Config {
|
|
|
|
if v == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
config := &log.Config{
|
|
|
|
ErrorLogType: log.LogType_Console,
|
|
|
|
AccessLogType: log.LogType_Console,
|
|
|
|
}
|
|
|
|
|
2019-07-12 02:34:38 -04:00
|
|
|
if v.AccessLog == "none" {
|
|
|
|
config.AccessLogType = log.LogType_None
|
|
|
|
} else if len(v.AccessLog) > 0 {
|
2019-02-10 13:04:11 -05:00
|
|
|
config.AccessLogPath = v.AccessLog
|
|
|
|
config.AccessLogType = log.LogType_File
|
|
|
|
}
|
2019-07-12 02:34:38 -04:00
|
|
|
if v.ErrorLog == "none" {
|
|
|
|
config.ErrorLogType = log.LogType_None
|
|
|
|
} else if len(v.ErrorLog) > 0 {
|
2019-02-10 13:04:11 -05:00
|
|
|
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
|
|
|
|
}
|