logger

package
v2.0.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2026 License: MIT Imports: 8 Imported by: 3

Documentation

Overview

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)

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close()

Close 关闭所有日志文件

func InitError

func InitError(level string)

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

func InitInfo

func InitInfo(level string)

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

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,默认情况下输出到终端

Types

type ConsoleWriter

type ConsoleWriter struct {
	// contains filtered or unexported fields
}

ConsoleWriter 自定义控制台 Writer,为日志添加配色

func (*ConsoleWriter) Write

func (c *ConsoleWriter) Write(p []byte) (n int, err error)

Write 方法:为控制台输出添加配色(根据日志级别关键字判断)

type FileWriter

type FileWriter struct {
	// contains filtered or unexported fields
}

FileWriter 自定义文件 Writer,无配色(直接输出原始内容)

func (*FileWriter) Write

func (f *FileWriter) Write(p []byte) (n int, err error)

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具体输出的位置

type TiLog

type TiLog struct {
	*log.Logger
}

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