1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-09 11:51:02 -05:00
v2fly/infra/conf/synthetic/log/log.go

61 lines
1.4 KiB
Go
Raw Normal View History

2021-06-19 08:30:46 -04:00
package log
2019-02-10 13:04:11 -05:00
import (
"strings"
"github.com/v2fly/v2ray-core/v5/app/log"
clog "github.com/v2fly/v2ray-core/v5/common/log"
2019-02-10 13:04:11 -05:00
)
func DefaultLogConfig() *log.Config {
return &log.Config{
2021-10-02 17:29:37 -04:00
Access: &log.LogSpecification{Type: log.LogType_None},
Error: &log.LogSpecification{Type: log.LogType_Console, Level: clog.Severity_Warning},
2019-02-10 13:04:11 -05:00
}
}
type LogConfig struct { // nolint: revive
2019-02-10 13:04:11 -05:00
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{
2021-10-02 17:29:37 -04:00
Access: &log.LogSpecification{Type: log.LogType_Console},
Error: &log.LogSpecification{Type: log.LogType_Console},
2019-02-10 13:04:11 -05:00
}
if v.AccessLog == "none" {
2021-10-02 17:29:37 -04:00
config.Access.Type = log.LogType_None
} else if len(v.AccessLog) > 0 {
2021-10-02 17:29:37 -04:00
config.Access.Path = v.AccessLog
config.Access.Type = log.LogType_File
2019-02-10 13:04:11 -05:00
}
if v.ErrorLog == "none" {
2021-10-02 17:29:37 -04:00
config.Error.Type = log.LogType_None
} else if len(v.ErrorLog) > 0 {
2021-10-02 17:29:37 -04:00
config.Error.Path = v.ErrorLog
config.Error.Type = log.LogType_File
2019-02-10 13:04:11 -05:00
}
level := strings.ToLower(v.LogLevel)
switch level {
case "debug":
2021-10-02 17:29:37 -04:00
config.Error.Level = clog.Severity_Debug
2019-02-10 13:04:11 -05:00
case "info":
2021-10-02 17:29:37 -04:00
config.Error.Level = clog.Severity_Info
2019-02-10 13:04:11 -05:00
case "error":
2021-10-02 17:29:37 -04:00
config.Error.Level = clog.Severity_Error
2019-02-10 13:04:11 -05:00
case "none":
2021-10-02 17:29:37 -04:00
config.Error.Type = log.LogType_None
config.Error.Type = log.LogType_None
2019-02-10 13:04:11 -05:00
default:
2021-10-02 17:29:37 -04:00
config.Error.Level = clog.Severity_Warning
2019-02-10 13:04:11 -05:00
}
return config
}