github.com/imannamdari/v2ray-core/v5@v5.0.5/infra/conf/synthetic/log/log.go (about)

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