github.com/phuslu/log@v1.0.100/level.go (about)

     1  package log
     2  
     3  // Level defines log levels.
     4  type Level uint32
     5  
     6  const (
     7  	// TraceLevel defines trace log level.
     8  	TraceLevel Level = 1
     9  	// DebugLevel defines debug log level.
    10  	DebugLevel Level = 2
    11  	// InfoLevel defines info log level.
    12  	InfoLevel Level = 3
    13  	// WarnLevel defines warn log level.
    14  	WarnLevel Level = 4
    15  	// ErrorLevel defines error log level.
    16  	ErrorLevel Level = 5
    17  	// FatalLevel defines fatal log level.
    18  	FatalLevel Level = 6
    19  	// PanicLevel defines panic log level.
    20  	PanicLevel Level = 7
    21  	// NoLevel defines an absent log level.
    22  	noLevel Level = 8
    23  )
    24  
    25  // String return lowe case string of Level
    26  func (l Level) String() (s string) {
    27  	switch l {
    28  	case TraceLevel:
    29  		s = "trace"
    30  	case DebugLevel:
    31  		s = "debug"
    32  	case InfoLevel:
    33  		s = "info"
    34  	case WarnLevel:
    35  		s = "warn"
    36  	case ErrorLevel:
    37  		s = "error"
    38  	case FatalLevel:
    39  		s = "fatal"
    40  	case PanicLevel:
    41  		s = "panic"
    42  	default:
    43  		s = "????"
    44  	}
    45  	return
    46  }
    47  
    48  // ParseLevel converts a level string into a log Level value.
    49  func ParseLevel(s string) (level Level) {
    50  	switch s {
    51  	case "trace", "Trace", "TRACE", "TRC":
    52  		level = TraceLevel
    53  	case "debug", "Debug", "DEBUG", "DBG":
    54  		level = DebugLevel
    55  	case "info", "Info", "INFO", "INF":
    56  		level = InfoLevel
    57  	case "warn", "Warn", "WARN", "warning", "Warning", "WARNING", "WRN":
    58  		level = WarnLevel
    59  	case "error", "Error", "ERROR", "ERR":
    60  		level = ErrorLevel
    61  	case "fatal", "Fatal", "FATAL", "FTL":
    62  		level = FatalLevel
    63  	case "panic", "Panic", "PANIC", "PNC":
    64  		level = PanicLevel
    65  	default:
    66  		level = noLevel
    67  	}
    68  	return
    69  }