Documentation ¶
Overview ¶
Package logger 提供Tigo框架自带的log纪录功能
Package logger logger 包是Tigo框架的日志组件包,内部里面封装了日志相关操作,包括从配置文件初始化日志,通过config对象初始化日志,以及配置日志等级等。 目前该包不支持分布式日志,如果要使用分布式日志,推荐使用其他的第三方日志模块。 --------------------------------------------------------------------------------------------------------------------- 初始化日志配置,如下示例所示:
Basic Example:
logLevel := logger.LogLevel{ Info: "stdout", Warning: "/path/to/logfile", Error: "/path/to/logfile", Trace: "/path/to/logfile", TimeRoll: "D*3", } logger.InitLoggerWithObject(logLevel)
--------------------------------------------------------------------------------------------------------------------- 日志打印用例:
Basic Example:
logger.Info.Print("Hello Logger") logger.Info.Println("Hello Logger") logger.Info.Printf("Hello %d", 250)
Index ¶
- Constants
- func InitError(level string)
- func InitInfo(level string)
- func InitLoggerWithConfigFile(filePath string)
- func InitLoggerWithObject(logLevel LogLevel)
- func InitTrace(level string)
- func InitWarning(level string)
- func SetLogPath(defineLogPath string)
- func StatusColor(status int) (coloredStatus string)
- type LogLevel
- type TiLog
Constants ¶
const ( TraceLevel int = iota + 1 InfoLevel WarningLevel ErrorLevel )
TraceLevel 等变量表示log实例的级别
Variables ¶
This section is empty.
Functions ¶
func InitLoggerWithConfigFile ¶
func InitLoggerWithConfigFile(filePath string)
InitLoggerWithConfigFile 根据配置文件路径初始化log模块; 配置文件需要配置如下部分:
- trace "discard": 不输出;"stdout": 终端输出不打印到文件;"/path/demo.log": 输出到指定文件
- info "discard": 不输出;"stdout": 终端输出不打印到文件;"/path/demo.log": 输出到指定文件
- warning "discard": 不输出;"stdout": 终端输出不打印到文件;"/path/demo.log": 输出到指定文件
- error "discard": 不输出;"stdout": 终端输出不打印到文件;"/path/demo.log": 输出到指定文件
func InitLoggerWithObject ¶
func InitLoggerWithObject(logLevel LogLevel)
InitLoggerWithObject 根据LogLevel结构体的实例初始化log模块; 配置文件需要配置如下部分:
- Trace "discard": 不输出;"stdout": 终端输出不打印到文件;"/path/demo.log": 输出到指定文件
- Info "discard": 不输出;"stdout": 终端输出不打印到文件;"/path/demo.log": 输出到指定文件
- Warning "discard": 不输出;"stdout": 终端输出不打印到文件;"/path/demo.log": 输出到指定文件
- Error "discard": 不输出;"stdout": 终端输出不打印到文件;"/path/demo.log": 输出到指定文件
func SetLogPath ¶
func SetLogPath(defineLogPath string)
SetLogPath 设置log输出路径,警告:若使用了InitLoggerWithConfigFile和InitLoggerWithObject请不要使用此方法,会覆盖原有的log输出结构。
Types ¶
type LogLevel ¶
type LogLevel struct { Trace string `json:"trace" yaml:"trace"` Info string `json:"info" yaml:"info"` Warning string `json:"warning" yaml:"warning"` Error string `json:"error" yaml:"error"` TimeRoll string `json:"time_roll" yaml:"timeRoll"` }
LogLevel 是log分级结构体
- Trace 跟踪
- Info 信息
- Warning 预警
- Error 错误
discard: 丢弃,stdout: 终端输出,文件路径表示log具体输出的位置