2016-10-16 12:22:21 +00:00
|
|
|
package conf
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
2017-02-01 20:35:40 +00:00
|
|
|
"v2ray.com/core/app/log"
|
2016-10-16 12:22:21 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type LogConfig struct {
|
|
|
|
AccessLog string `json:"access"`
|
|
|
|
ErrorLog string `json:"error"`
|
|
|
|
LogLevel string `json:"loglevel"`
|
|
|
|
}
|
|
|
|
|
2016-11-27 20:39:09 +00:00
|
|
|
func (v *LogConfig) Build() *log.Config {
|
|
|
|
if v == nil {
|
2016-10-16 12:22:21 +00:00
|
|
|
return nil
|
|
|
|
}
|
2016-10-24 13:08:06 +00:00
|
|
|
config := &log.Config{
|
|
|
|
ErrorLogType: log.LogType_Console,
|
|
|
|
AccessLogType: log.LogType_Console,
|
|
|
|
}
|
|
|
|
|
2016-11-27 20:39:09 +00:00
|
|
|
if len(v.AccessLog) > 0 {
|
|
|
|
config.AccessLogPath = v.AccessLog
|
2016-10-16 12:22:21 +00:00
|
|
|
config.AccessLogType = log.LogType_File
|
|
|
|
}
|
2016-11-27 20:39:09 +00:00
|
|
|
if len(v.ErrorLog) > 0 {
|
|
|
|
config.ErrorLogPath = v.ErrorLog
|
2016-10-16 12:22:21 +00:00
|
|
|
config.ErrorLogType = log.LogType_File
|
|
|
|
}
|
|
|
|
|
2016-11-27 20:39:09 +00:00
|
|
|
level := strings.ToLower(v.LogLevel)
|
2016-10-16 12:22:21 +00:00
|
|
|
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
|
2016-10-24 13:08:06 +00:00
|
|
|
config.AccessLogType = log.LogType_None
|
2016-10-16 12:22:21 +00:00
|
|
|
default:
|
|
|
|
config.ErrorLogLevel = log.LogLevel_Warning
|
|
|
|
}
|
|
|
|
return config
|
|
|
|
}
|