log.go 893 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package conf
  2. import (
  3. "strings"
  4. "v2ray.com/core/common/log"
  5. )
  6. type LogConfig struct {
  7. AccessLog string `json:"access"`
  8. ErrorLog string `json:"error"`
  9. LogLevel string `json:"loglevel"`
  10. }
  11. func (this *LogConfig) Build() *log.Config {
  12. if this == nil {
  13. return nil
  14. }
  15. config := new(log.Config)
  16. if len(this.AccessLog) > 0 {
  17. config.AccessLogPath = this.AccessLog
  18. config.AccessLogType = log.LogType_File
  19. }
  20. if len(this.ErrorLog) > 0 {
  21. config.ErrorLogPath = this.ErrorLog
  22. config.ErrorLogType = log.LogType_File
  23. }
  24. level := strings.ToLower(this.LogLevel)
  25. switch level {
  26. case "debug":
  27. config.ErrorLogLevel = log.LogLevel_Debug
  28. case "info":
  29. config.ErrorLogLevel = log.LogLevel_Info
  30. case "error":
  31. config.ErrorLogLevel = log.LogLevel_Error
  32. case "none":
  33. config.ErrorLogType = log.LogType_None
  34. default:
  35. config.ErrorLogLevel = log.LogLevel_Warning
  36. }
  37. return config
  38. }