logger

package
v1.0.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 26, 2019 License: MIT Imports: 10 Imported by: 3

Documentation

Overview

Package logger 提供Tigo框架自带的log纪录功能

Index

Constants

View Source
const (
	TraceLevel int = iota + 1
	InfoLevel
	WarningLevel
	ErrorLevel
)

TraceLevel 等变量表示log实例的级别

Variables

This section is empty.

Functions

func InitError

func InitError(level string)

InitError 初始化Error,默认情况下输出到文件

func InitInfo

func InitInfo(level string)

InitInfo 初始化Info,默认情况下输出到终端

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 InitTrace

func InitTrace(level string)

InitTrace 初始化Trace,默认情况下不输出

func InitWarning

func InitWarning(level string)

InitWarning 初始化Warning,默认情况下输出到终端

func SetLogPath

func SetLogPath(defineLogPath string)

SetLogPath 设置log输出路径,警告:若使用了InitLoggerWithConfigFile和InitLoggerWithObject请不要使用此方法,会覆盖原有的log输出结构。

Types

type LogLevel

type LogLevel struct {
	Trace    string `json:"trace"`
	Info     string `json:"info"`
	Warning  string `json:"warning"`
	Error    string `json:"error"`
	TimeRoll string `json:"time_roll"`
}

LogLevel 是log分级结构体

  • Trace 跟踪
  • Info 信息
  • Warning 预警
  • Error 错误

discard: 丢弃,stdout: 终端输出,文件路径表示log具体输出的位置

type TiLog

type TiLog struct {
	*log.Logger
	Level int
}

TiLog 是Tigo自定义的log结构体

var (
	Trace   *TiLog
	Info    *TiLog
	Warning *TiLog
	Error   *TiLog
)

Trace 等变量不同级别的log实例

func (*TiLog) Print

func (l *TiLog) Print(v ...interface{})

Print 打印log,不换行

func (*TiLog) Printf

func (l *TiLog) Printf(format string, v ...interface{})

Printf 格式化输出log

func (*TiLog) Println

func (l *TiLog) Println(v ...interface{})

Println 打印log并且换行

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL