github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/log/level.go (about)

     1  package log
     2  
     3  import "strings"
     4  
     5  type Level int
     6  
     7  const (
     8  	TRACE = Level(iota)
     9  	DEBUG
    10  	INFO
    11  	WARN
    12  	ERROR
    13  	FATAL
    14  
    15  	QUIET
    16  )
    17  
    18  type Mapper interface {
    19  	MapLogLevel(level Level) Level
    20  }
    21  
    22  const (
    23  	lblTrace = "TRACE"
    24  	lblDebug = "DEBUG"
    25  	lblInfo  = "INFO"
    26  	lblWarn  = "WARN"
    27  	lblError = "ERROR"
    28  	lblFatal = "FATAL"
    29  	lblQuiet = "QUIET"
    30  )
    31  
    32  const (
    33  	colorReset = "\033[0m"
    34  
    35  	colorTrace = "\033[38m"
    36  	colorDebug = "\033[37m"
    37  	colorInfo  = "\033[36m"
    38  	colorWarn  = "\033[33m"
    39  	colorError = "\033[31m"
    40  	colorFatal = "\033[41m"
    41  	colorQuiet = colorReset
    42  
    43  	colorTraceBold = "\033[47m"
    44  	colorDebugBold = "\033[100m"
    45  	colorInfoBold  = "\033[106m"
    46  	colorWarnBold  = "\u001B[30m\033[103m"
    47  	colorErrorBold = "\033[101m"
    48  	colorFatalBold = "\033[101m"
    49  	colorQuietBold = ""
    50  )
    51  
    52  func (l Level) String() string {
    53  	switch l {
    54  	case TRACE:
    55  		return lblTrace
    56  	case DEBUG:
    57  		return lblDebug
    58  	case INFO:
    59  		return lblInfo
    60  	case WARN:
    61  		return lblWarn
    62  	case ERROR:
    63  		return lblError
    64  	case FATAL:
    65  		return lblFatal
    66  	default:
    67  		return lblQuiet
    68  	}
    69  }
    70  
    71  func (l Level) BoldColor() string {
    72  	switch l {
    73  	case TRACE:
    74  		return colorTraceBold
    75  	case DEBUG:
    76  		return colorDebugBold
    77  	case INFO:
    78  		return colorInfoBold
    79  	case WARN:
    80  		return colorWarnBold
    81  	case ERROR:
    82  		return colorErrorBold
    83  	case FATAL:
    84  		return colorFatalBold
    85  	default:
    86  		return colorQuietBold
    87  	}
    88  }
    89  
    90  func (l Level) Color() string {
    91  	switch l {
    92  	case TRACE:
    93  		return colorTrace
    94  	case DEBUG:
    95  		return colorDebug
    96  	case INFO:
    97  		return colorInfo
    98  	case WARN:
    99  		return colorWarn
   100  	case ERROR:
   101  		return colorError
   102  	case FATAL:
   103  		return colorFatal
   104  	default:
   105  		return colorQuiet
   106  	}
   107  }
   108  
   109  func FromString(l string) Level {
   110  	switch strings.ToUpper(l) {
   111  	case lblTrace:
   112  		return TRACE
   113  	case lblDebug:
   114  		return DEBUG
   115  	case lblInfo:
   116  		return INFO
   117  	case lblWarn:
   118  		return WARN
   119  	case lblError:
   120  		return ERROR
   121  	case lblFatal:
   122  		return FATAL
   123  	default:
   124  		return QUIET
   125  	}
   126  }