logger

package
v0.3.9 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package logger 负责日志收敛,给日志添加前缀和独立文件输出,以便在本框架被集成之后的日志可读

Index

Constants

View Source
const (
	TraceLevel    = 6 // 可详细跟踪
	DebugLevel    = 5 // 可调式
	InfoLevel     = 4 // 日常使用关键信息
	WarningLevel  = 3 // 警告级别信息
	ErrorLevel    = 2 // 错误级别信息
	CriticalLevel = 1 // 严重错误
)

日志级别定义

Variables

View Source
var (
	// LogLevel 日志级别
	// level 总共分5个级别:debug < info< warning< error< critical
	LogLevel = InfoLevel
	// ConsoleLevel 控制台打印级别
	ConsoleLevel = WarningLevel
	// ShowError2Console 把错误同步打印到控制台
	ShowError2Console = false
	// Logger 独立日志文件
	Logger io.Writer = os.Stdout
	// EnableLogTrack 开启并发日志染色
	EnableLogTrack = false
)

Functions

func Caller

func Caller(skip int) func() string

Caller 默认的 CallerFn, 用于 debug 日志获取调用者的行号

func CloseDebug

func CloseDebug()

CloseDebug 关闭 debug 模式

func CloseTrace

func CloseTrace()

CloseTrace 关闭日志跟踪

func Console

func Console(level int, s string)

Console 打印日志到控制台

func Consolef

func Consolef(level int, format string, a ...interface{})

Consolef 打印日志到控制台

func Consolefc

func Consolefc(level int, format string, callerFn CallerFn, a ...interface{})

Consolefc 打印日志到控制台

func Debug

func Debug(v ...interface{})

Debug 打印 debug 日志

func DebugEnable

func DebugEnable() bool

DebugEnable 是否开启 debug

func Debugf

func Debugf(format string, a ...interface{})

Debugf 打印 debug 日志

func Error

func Error(v ...interface{})

Error 打印 error 日志

func Errorf

func Errorf(format string, a ...interface{})

Errorf 打印 error 日志

func Important

func Important(v ...interface{})

Important 打印重要的日志

func Importantf

func Importantf(format string, a ...interface{})

Importantf 打印重要的日志

func Info

func Info(v ...interface{})

Info 打印 info 日志

func Infof

func Infof(format string, a ...interface{})

Infof 打印 info 日志

func IsDebugOpen

func IsDebugOpen() bool

IsDebugOpen 是否开启 debug 模式

func OpenDebug

func OpenDebug()

OpenDebug 开启 debug 模式

func OpenTrace

func OpenTrace()

OpenTrace 打开日志跟踪

func SetLog2Console

func SetLog2Console(b bool)

SetLog2Console 设置是否打印到控制台

func SetLogTrack

func SetLogTrack(enable bool, getter func() string)

SetLogTrack 设置日志染色

func Trace

func Trace(v ...interface{})

Trace 打印 trace 日志

func TraceEnable

func TraceEnable() bool

TraceEnable 是否开启 trace

func Tracef

func Tracef(format string, a ...interface{})

Tracef 打印 trace 日志

func Warning

func Warning(v ...interface{})

Warning 打印 warning 日志

func Warningf

func Warningf(format string, a ...interface{})

Warningf 打印 warning 日志

Types

type CallerFn

type CallerFn func() string

CallerFn 获取 Caller 行号的回调函数类型

type Color

type Color uint8

Color represents a text color.

const (
	None Color = iota + 29
	Black
	Red
	Green
	Yellow
	Blue
	Magenta
	Cyan
	White
)

Foreground colors.

func (Color) Add

func (c Color) Add(s string) string

Add adds the coloring to the given string.

func (Color) AddAll

func (c Color) AddAll(s string) string

AddAll adds the coloring to the given string of all line.

Jump to

Keyboard shortcuts

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