zlog

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2025 License: MIT Imports: 8 Imported by: 0

README

* 日志库

** 简单的异步日志库

- 支持文件切割
- 支持最大日志文件限制
- 每日日志文件
- 支持自定义日志格式化与后端输出

** 架构

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddBackend

func AddBackend(be Backend)

AddBackend 添加多个输出后端

func Debugf

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

Debugf logs a message at level Debug on the standard logger.

func Debugln

func Debugln(args ...interface{})

Debugln logs a message at level Debug on the standard logger.

func Errorf

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

Errorf logs a message at level Error on the standard logger.

func Errorln

func Errorln(args ...interface{})

Errorln logs a message at level Error on the standard logger.

func Fatalf

func Fatalf(format string, args ...interface{})

Fatalf logs a message at level Fatal on the standard logger.

func Fatalln

func Fatalln(args ...interface{})

Fatalln logs a message at level Fatal on the standard logger.

func Infof

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

Infof logs a message at level Info on the standard logger.

func Infoln

func Infoln(args ...interface{})

Infoln logs a message at level Info on the standard logger.

func SetBackend

func SetBackend(be Backend)

SetBackend 设置输出后端为单一

func SetFormattor

func SetFormattor(ft Formatter)

SetFormattor 设置格式化器

func SetLevel

func SetLevel(lvl string) error

SetLevel 设置日志等级

func Stop

func Stop()

Stop 停止

func Sync

func Sync()

Sync 刷新缓存

func Tracef

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

Tracef logs a message at level Info on the standard logger.

func Warnf

func Warnf(format string, args ...interface{})

Warnf logs a message at level Warn on the standard logger.

func Warnln

func Warnln(args ...interface{})

Warnln logs a message at level Warn on the standard logger.

Types

type Backend

type Backend interface {
	Write(buf []byte) (int, error)
	Sync() error
	Close() error
}

Backend 日志输出端接口

type Fields

type Fields map[string]any

Fields type

type Formatter

type Formatter interface {
	SetLevel(lvl string) error
	Format(level Level, msg string) []byte
	WithFields(fields Fields)
}

Formatter 格式化前端

type InciseFileBackend

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

InciseFileBackend 文件切割后端

func NewInciseFile

func NewInciseFile(filePath, fileLink, prefix string, maxSize int64) (*InciseFileBackend, error)

NewInciseFile create file backend

func (*InciseFileBackend) Close

func (b *InciseFileBackend) Close() error

Close 文件后端关闭

func (*InciseFileBackend) Sync

func (b *InciseFileBackend) Sync() error

Sync 刷新缓存区

func (*InciseFileBackend) Write

func (b *InciseFileBackend) Write(buf []byte) (int, error)

Write 文件后端写方法

type Level

type Level uint8

Level 日志等级

const (
	TraceLevel Level = iota
	DebugLevel
	InforLevel
	WarnLevel
	ErrorLevel
	FatalLevel
	NULLLevel //非法等级
)

func ParseLevel

func ParseLevel(lvl string) (Level, error)

ParseLevel takes a string level and returns the Logrus log level constant.

func (Level) String

func (level Level) String() string

Convert the Level to a string

type TextFormatter

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

TextFormatter 文本格式化前端

func NewTextFmt

func NewTextFmt(lvl string) *TextFormatter

NewTextFmt 创建格式化

func (*TextFormatter) Format

func (f *TextFormatter) Format(level Level, msg string) []byte

Format 日志格式 2006-01-02 15:04:05 [error] test.go 245 : this is a error

func (*TextFormatter) SetLevel

func (f *TextFormatter) SetLevel(lvl string) error

SetLevel 设置日志级别

func (*TextFormatter) WithFields

func (f *TextFormatter) WithFields(fields Fields)

WithFields 添加一个map

type ZLog

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

ZLog is a log

func GetInstance

func GetInstance() *ZLog

GetInstance 获取实例

func NewZLog

func NewZLog(level Level) *ZLog

NewZLog 创建日志

func WithFields

func WithFields(fields Fields) *ZLog

WithFields 添加附加数据

func (*ZLog) AddBackend

func (z *ZLog) AddBackend(be Backend)

AddBackend 添加多个输出后端

func (*ZLog) Debugf

func (z *ZLog) Debugf(format string, args ...interface{})

Debugf logs a message at level Debug on the standard logger.

func (*ZLog) Debugln

func (z *ZLog) Debugln(args ...interface{})

Debugln logs a message at level Debug on the standard logger.

func (*ZLog) Errorf

func (z *ZLog) Errorf(format string, args ...interface{})

Errorf logs a message at level Error on the standard logger.

func (*ZLog) Errorln

func (z *ZLog) Errorln(args ...interface{})

Errorln logs a message at level Error on the standard logger.

func (*ZLog) Fatalf

func (z *ZLog) Fatalf(format string, args ...interface{})

Fatalf logs a message at level Fatal on the standard logger.

func (*ZLog) Fatalln

func (z *ZLog) Fatalln(args ...interface{})

Fatalln logs a message at level Fatal on the standard logger.

func (*ZLog) Infof

func (z *ZLog) Infof(format string, args ...interface{})

Infof logs a message at level Info on the standard logger.

func (*ZLog) Infoln

func (z *ZLog) Infoln(args ...interface{})

Infoln logs a message at level Info on the standard logger.

func (*ZLog) SetBackend

func (z *ZLog) SetBackend(be Backend)

SetBackend 设置输出后端

func (*ZLog) SetFormattor

func (z *ZLog) SetFormattor(ft Formatter)

SetFormattor 设置格式化前端

func (*ZLog) SetLevel

func (z *ZLog) SetLevel(level string) error

SetLevel 设置日志级别

func (*ZLog) Stop

func (z *ZLog) Stop()

Stop 停止

func (*ZLog) Sync

func (z *ZLog) Sync()

Sync 刷新缓冲

func (*ZLog) Tracef

func (z *ZLog) Tracef(format string, args ...interface{})

Tracef logs a message at level Info on the standard logger.

func (*ZLog) Warnf

func (z *ZLog) Warnf(format string, args ...interface{})

Warnf logs a message at level Warn on the standard logger.

func (*ZLog) Warnln

func (z *ZLog) Warnln(args ...interface{})

Warnln logs a message at level Warn on the standard logger.

func (*ZLog) WithFields

func (z *ZLog) WithFields(fields Fields) *ZLog

WithFields 添加数据

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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