package
0.0.0-20231103123238-49bf83314d38
Repository: https://github.com/daz-3ux/dblog.git
Documentation: pkg.go.dev
# README
-
使用定制化日志包, 方便扩展以及统一日志格式
- 创建 zap.Logger 的自定义 Logger 对象
- 编写创建函数,创建 zapLogger 对象
- 创建 *zap.Logger 对象
- 实现日志接口
-
日志包为
github.com/daz-3ux/dBlog/internal/pkg/log
- 日志包使用 zap 库,在 zap 库基础上进行了一层封装
- 拥有 2 类
zapLogger
对象- 全局对象
- 使用类似
log.Infow()
的方式进行调用 - Init(opts *Options) 初始化全局对象
- 使用类似
- 局部对象
- 可以传入不同参数,创建一个自定义的
*zapLogger
对象 - NewLogger(opts *Options) *zapLogger 创建一个自定义的
*zapLogger
- 可以传入不同参数,创建一个自定义的
- 全局对象
- 通过 Options 结构体对日志系统进行配置
- 可以通过 NewOptions() 创建一个默认的 *Options 对象
- 自定义配置文件存放于 yaml 之中,通过
viper
读取日志配置
-
zap
- zap 是一个高性能的日志库,在性能上远超标准库 log 包
- zap 有两种日志记录模式:
- SugaredLogger
- 支持
结构化
以及printf
风格的日志记录
- 支持
- Logger
- 只支持
强类型
的结构化日志记录 - 性能甚至高于
SugaredLogger
- 只支持
- SugaredLogger
# Functions
C extracts relevant key-value pairs from the incoming context and adds them to the structured logs of the zap.Logger.
Debugw print debug level log.
Errorw print error level log.
Fatalw print fatal level log.
Infow print info level log.
Init initializes the global logger with the given options.
NewLogger creates a new logger with the given options.
NewOptions creates an Options object with default parameters.
Panicw print panic level log.
Sync flushes all buffered logs into the disk main function should call this function before exit.
Warnw print warn level log.
# Interfaces
Logger define dBlog's logger interface.