github.com/inazumav/sing-box@v0.0.0-20230926072359-ab51429a14f1/log/level.go (about)

     1  package log
     2  
     3  import (
     4  	E "github.com/sagernet/sing/common/exceptions"
     5  )
     6  
     7  type Level = uint8
     8  
     9  const (
    10  	LevelPanic Level = iota
    11  	LevelFatal
    12  	LevelError
    13  	LevelWarn
    14  	LevelInfo
    15  	LevelDebug
    16  	LevelTrace
    17  )
    18  
    19  func FormatLevel(level Level) string {
    20  	switch level {
    21  	case LevelTrace:
    22  		return "trace"
    23  	case LevelDebug:
    24  		return "debug"
    25  	case LevelInfo:
    26  		return "info"
    27  	case LevelWarn:
    28  		return "warn"
    29  	case LevelError:
    30  		return "error"
    31  	case LevelFatal:
    32  		return "fatal"
    33  	case LevelPanic:
    34  		return "panic"
    35  	default:
    36  		return "unknown"
    37  	}
    38  }
    39  
    40  func ParseLevel(level string) (Level, error) {
    41  	switch level {
    42  	case "trace":
    43  		return LevelTrace, nil
    44  	case "debug":
    45  		return LevelDebug, nil
    46  	case "info":
    47  		return LevelInfo, nil
    48  	case "warn", "warning":
    49  		return LevelWarn, nil
    50  	case "error":
    51  		return LevelError, nil
    52  	case "fatal":
    53  		return LevelFatal, nil
    54  	case "panic":
    55  		return LevelPanic, nil
    56  	default:
    57  		return LevelTrace, E.New("unknown log level: ", level)
    58  	}
    59  }