github.com/gogf/gf/v2@v2.7.4/os/glog/glog_logger_color.go (about)

     1  // Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the MIT License.
     4  // If a copy of the MIT was not distributed with this file,
     5  // You can obtain one at https://github.com/gogf/gf.
     6  
     7  package glog
     8  
     9  import "github.com/fatih/color"
    10  
    11  const (
    12  	COLOR_BLACK = 30 + iota
    13  	COLOR_RED
    14  	COLOR_GREEN
    15  	COLOR_YELLOW
    16  	COLOR_BLUE
    17  	COLOR_MAGENTA
    18  	COLOR_CYAN
    19  	COLOR_WHITE
    20  )
    21  
    22  // Foreground Hi-Intensity text colors
    23  const (
    24  	COLOR_HI_BLACK = 90 + iota
    25  	COLOR_HI_RED
    26  	COLOR_HI_GREEN
    27  	COLOR_HI_YELLOW
    28  	COLOR_HI_BLUE
    29  	COLOR_HI_MAGENTA
    30  	COLOR_HI_CYAN
    31  	COLOR_HI_WHITE
    32  )
    33  
    34  // defaultLevelColor defines the default level and its mapping prefix string.
    35  var defaultLevelColor = map[int]int{
    36  	LEVEL_DEBU: COLOR_YELLOW,
    37  	LEVEL_INFO: COLOR_GREEN,
    38  	LEVEL_NOTI: COLOR_CYAN,
    39  	LEVEL_WARN: COLOR_MAGENTA,
    40  	LEVEL_ERRO: COLOR_RED,
    41  	LEVEL_CRIT: COLOR_HI_RED,
    42  	LEVEL_PANI: COLOR_HI_RED,
    43  	LEVEL_FATA: COLOR_HI_RED,
    44  }
    45  
    46  // getColoredStr returns a string that is colored by given color.
    47  func (l *Logger) getColoredStr(c int, s string) string {
    48  	return color.New(color.Attribute(c)).Sprint(s)
    49  }
    50  
    51  func (l *Logger) getColorByLevel(level int) int {
    52  	return defaultLevelColor[level]
    53  }