logger

package
v0.1.15 Latest Latest
Warning

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

Go to latest
Published: May 25, 2024 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DebugLv = zapcore.DebugLevel
	InfoLv  = zapcore.InfoLevel
	WarnLv  = zapcore.WarnLevel
	ErrorLv = zapcore.ErrorLevel
)

Variables

This section is empty.

Functions

This section is empty.

Types

type FileOutputOpt

type FileOutputOpt func(*OutFileOptions)

FileOutputOpt 文件输出选项

func WithCompress

func WithCompress(compress bool) FileOutputOpt

func WithFilename

func WithFilename(filename string) FileOutputOpt

func WithLocalTime

func WithLocalTime(localTime bool) FileOutputOpt

func WithMaxAge

func WithMaxAge(maxAge int) FileOutputOpt

func WithMaxBackups

func WithMaxBackups(maxBackups int) FileOutputOpt

func WithMaxSize

func WithMaxSize(maxSize int) FileOutputOpt

type Logger

type Logger struct {
	// 日志打印用
	Logger zap.SugaredLogger

	*Options
	// contains filtered or unexported fields
}

Logger 是对 zap.SugaredLogger 的封装,简化其对外使用的接口, 并且针对于 Logger 所有配置都是支持运行时动态修改,且并发安全。 Logger 也支持了针对于 zapcore.Core 的扩展,调用 Logger.AddCore 即可,

构建该对象请使用 New 进行创建,在该操作中会对部分必要属性进行初始化, 直接使用结构体创建会导致结构体不可用(甚至panic)。

如非深度定制化扩展,非必要不建议使用 Logger.AddCore 进行扩展,该操作会 导致客户端应用程序对zap包编译依赖,不保证切换内部日志实现。

func GetInstance

func GetInstance() *Logger

func New

func New(opts ...Option) *Logger

func (*Logger) AddCore

func (l *Logger) AddCore(core ...zapcore.Core)

AddCore 添加Core

func (*Logger) Debug

func (l *Logger) Debug(msg string, vs ...any)

Debug 格式化打印调试级别日志 不同于zap内部可变参数逻辑,该可变参数是用于,字符串格式化的

func (*Logger) Error

func (l *Logger) Error(vs ...any)

Error 打印错误级别日志 该方法具有两种传参形式:

  1. error类型:会直接格式化打印%+v日志
  2. 信息(格式化)
  3. error+格式化信息:error会作为 With 格式存在,且依旧以%+v格式输出

func (*Logger) Flush

func (l *Logger) Flush()

Flush 将缓冲区日志刷新至目标

func (*Logger) Info

func (l *Logger) Info(msg string, vs ...any)

Info 格式化打印信息级别日志 不同于zap内部可变参数逻辑,该可变参数是用于,字符串格式化的

func (*Logger) Lv

func (l *Logger) Lv() int8

Lv 获取当前日志打印级别

func (*Logger) NewFileOutput

func (l *Logger) NewFileOutput(opts ...FileOutputOpt)

NewFileOutput 新增日志输出文件配置

func (*Logger) NewOutput

func (l *Logger) NewOutput(writer io.Writer)

NewOutput 新增日志输出位置

func (*Logger) SetLv

func (l *Logger) SetLv(lv int8)

SetLv 设置当前日志打印级别

func (*Logger) Warn

func (l *Logger) Warn(msg string, vs ...any)

Warn 格式化打印警告级别日志 不同于zap内部可变参数逻辑,该可变参数是用于,字符串格式化的

type Option

type Option func(*Options)

func WithSkipCaller

func WithSkipCaller(skip int) Option

type Options

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

func (Options) SkipCaller

func (options Options) SkipCaller() int

type OutFileOptions

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

func (OutFileOptions) Compress

func (options OutFileOptions) Compress() bool

func (OutFileOptions) Filename

func (options OutFileOptions) Filename() string

func (OutFileOptions) LocalTime

func (options OutFileOptions) LocalTime() bool

func (OutFileOptions) MaxAge

func (options OutFileOptions) MaxAge() int

func (OutFileOptions) MaxBackups

func (options OutFileOptions) MaxBackups() int

func (OutFileOptions) MaxSize

func (options OutFileOptions) MaxSize() int

Jump to

Keyboard shortcuts

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