github.com/Uhtred009/v2ray-core-1@v4.31.2+incompatible/infra/conf/log.go (about)

     1  package conf
     2  
     3  import (
     4  	"strings"
     5  
     6  	"v2ray.com/core/app/log"
     7  	clog "v2ray.com/core/common/log"
     8  )
     9  
    10  func DefaultLogConfig() *log.Config {
    11  	return &log.Config{
    12  		AccessLogType: log.LogType_None,
    13  		ErrorLogType:  log.LogType_Console,
    14  		ErrorLogLevel: clog.Severity_Warning,
    15  	}
    16  }
    17  
    18  type LogConfig struct {
    19  	AccessLog string `json:"access"`
    20  	ErrorLog  string `json:"error"`
    21  	LogLevel  string `json:"loglevel"`
    22  }
    23  
    24  func (v *LogConfig) Build() *log.Config {
    25  	if v == nil {
    26  		return nil
    27  	}
    28  	config := &log.Config{
    29  		ErrorLogType:  log.LogType_Console,
    30  		AccessLogType: log.LogType_Console,
    31  	}
    32  
    33  	if v.AccessLog == "none" {
    34  		config.AccessLogType = log.LogType_None
    35  	} else if len(v.AccessLog) > 0 {
    36  		config.AccessLogPath = v.AccessLog
    37  		config.AccessLogType = log.LogType_File
    38  	}
    39  	if v.ErrorLog == "none" {
    40  		config.ErrorLogType = log.LogType_None
    41  	} else if len(v.ErrorLog) > 0 {
    42  		config.ErrorLogPath = v.ErrorLog
    43  		config.ErrorLogType = log.LogType_File
    44  	}
    45  
    46  	level := strings.ToLower(v.LogLevel)
    47  	switch level {
    48  	case "debug":
    49  		config.ErrorLogLevel = clog.Severity_Debug
    50  	case "info":
    51  		config.ErrorLogLevel = clog.Severity_Info
    52  	case "error":
    53  		config.ErrorLogLevel = clog.Severity_Error
    54  	case "none":
    55  		config.ErrorLogType = log.LogType_None
    56  		config.AccessLogType = log.LogType_None
    57  	default:
    58  		config.ErrorLogLevel = clog.Severity_Warning
    59  	}
    60  	return config
    61  }