hlog
golang 统一日志输出
工具拉取
go get -u gitee.com/tym_hmm/hlog
效果
=== RUN TestSysLog 2021/12/17 14:34:48.332076 hlog_test.go:25: [DEBUG] DEBUG 2021/12/17 14:34:48.389150 hlog_test.go:26: [INFO] INFO 2021/12/17 14:34:48.389150 hlog_test.go:27: [WARNING] WARNING 2021/12/17 14:34:48.389656 hlog_test.go:28: [ERROR] ERROR 2021/12/17 14:34:48.389728 hlog_test.go:31: [DEBUG] DEBUG 2021/12/17 14:34:48.389728 hlog_test.go:32: [INFO] INFO 2021/12/17 14:34:48.389728 hlog_test.go:33: [WARNING] WARNING 2021/12/17 14:34:48.389728 hlog_test.go:34: [ERROR] ERROR 2021/12/17 14:34:48.390280 hlog_test.go:38: [INFO] INFO 2021/12/17 14:34:48.390280 hlog_test.go:39: [WARNING] WARNING 2021/12/17 14:34:48.390280 hlog_test.go:40: [ERROR] ERROR 2021/12/17 14:34:48.390280 hlog_test.go:45: [WARNING] WARNING 2021/12/17 14:34:48.390280 hlog_test.go:46: [ERROR] ERROR 2021/12/17 14:34:48.390858 hlog_test.go:52: [ERROR] ERROR
用法
1.终端日志输出
等级说明(向下等级越高)
等名称 |
---|
DEBUG |
INFO |
WARNING |
ERROR |
FATAL |
PANIC |
### 初始化 ##带参数 #Level(INFO) 显示打印等级底于此等级的日志将不打印 log := NewStdLog(Level(INFO),Name("DEBUG")) ##不带参数 log := NewStdLog() //使用 log.Println("........DEFAULT........") log.Debug("DEBUG") log.Info("INFO") log.Warning("WARNING") log.Error("ERROR")
2.输出日志到文件
io.Writer
log := NewHLog(w io.Writer) log.Debug("DEBUG") log.Info("INFO") log.Warning("WARNING") log.Error("ERROR")