mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-30 01:08:33 +00:00
v1.0.0
This commit is contained in:
parent
47d23e9972
commit
c7f7c08ead
711 changed files with 82154 additions and 2 deletions
61
infra/conf/log.go
Normal file
61
infra/conf/log.go
Normal file
|
@ -0,0 +1,61 @@
|
|||
package conf
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/xtls/xray-core/v1/app/log"
|
||||
clog "github.com/xtls/xray-core/v1/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"`
|
||||
}
|
||||
|
||||
func (v *LogConfig) Build() *log.Config {
|
||||
if v == nil {
|
||||
return nil
|
||||
}
|
||||
config := &log.Config{
|
||||
ErrorLogType: log.LogType_Console,
|
||||
AccessLogType: log.LogType_Console,
|
||||
}
|
||||
|
||||
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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue