logker
是一个Golang小型简单易用的日志库.👨💻
📚English Docs | 🤩pkg.go.dev | 👨💻 Release版本
- 支持文件自动备份。
- 保存到到指定位置。
- 支持彩色日志信息打印。
- 自定义日志文件存储大小。
- 支持设置日志文件的时区。
Error
级别的日志单独输出到指定文件。- 支持自动根据设置的文件大小切割日志文件。
- 日志级别有4种
debug
info
error
warning
。 未来会支持: 网络传输存储 websoket🙏.
本项目会不断更新着. 如果你喜欢😍请把你的star给我吧 Thanks♪(・ω・)ノ!
- 这是你吗?😜
🔝 最底版本要求 Go version 1.11. 🔝 你的包管理必须使用的是go module!!!
go get github.com/Higker/logker
或者
go get -u github.com/Higker/logker
运行时也可以添加使用参数 -u
来获取更新.
$ go get github.com/Higker/logker
go: github.com/Higker/logker upgrade => v1.1.5
go get: github.com/Higker/logker@v1.1.5: parsing go.mod:
module declares its path as: github.com/higker/logker
but was required as: github.com/Higker/logker
module tets
go 1.14
require github.com/higker/logker v1.1.5
package main
import (
klog "github.com/higker/logker"
"time"
)
func main() {
// 在初始化的时候必须自己先创建好存储日志的文件夹!!
dir := "/Users/ding/Documents/test_log"
// New file logger
// File Max size : 这里是单个的日志文件大小 你可以自定义也可以使用内置的常量
// klog.GB1 = 1GB
// klog.MB10 = 10MB
// klog.MB100 = 100MB
format := "{level} - 时间 {time} - 位置 {position} - 消息 {message}" //This version was modified from v 1.1.5
flog := klog.NewFlog(klog.DEBUG, true, klog.Shanghai, dir, "log", 10*1024, 0777,format)
// 模拟日志输出
for {
flog.Debug("DEBUG : %d + %d = %d",1,2,1+2)
flog.Error("ERROR")
flog.Warning("WARNING %p",flog)
flog.Info("INFO %s","Hello LogKer.")
time.Sleep(2 * time.Second)
}
}
👆参数列表:
// Build File logger
// Args note
// logLevel: lev, \\ 日志等级
// wheError: wheErr, \\ 是否开启error级别的日志信息单独输出到一个error_开头文件
// directory: dir, \\ 日志存储的路径&文件夹
// fileName: fileName, \\ 日志的名字 不需要写后缀名
// timeZone: zone, \\ 你需要设置的时区 可以使用内置常量 你可以在下面查看文档链接
// power: power, \\ 你的文件系统权限
// fileMaxSize: size, \\ 单个日志文件大小
// format:
//现在upgrade到v1.1.5版本即可自定义消息输出格式~
//自定义标签名字必须是{level} {time} {position} {message}
//自定义标签的位置就是程序运行时输出对应的日志消息的位置!!!!
//例如下面我自定义的
// 1. //format := "{level} - {time} - {position} - {message}"
format := "{level} - 时间 {time} - 位置 {position} - 消息 {message}" //This version was modified from v 1.1.5
package main
import (
"github.com/higker/logker"
"strings"
)
//type Formatting string
// logKer library Test
func main() {
// Now upgrade to version v 1.1.5 to customize the message output format ~
// TheCustomTagNameMustBe {level} {time} {position} {message}
// The location of the custom label is the location
// where the program outputs the corresponding log message at run time!!!!
// forExampleHereIsMyCustom
// 1. //format := "{level} - {time} - {position} - {message}"
format := "{level} - 时间 {time} - 位置 {position} - 消息 {message}" //This version was modified from v 1.1.5
var log logker.Logger
log = logker.NewClog(logker.DEBUG, logker.Shanghai, format)
log.Debug("DEBUG %s","自定义日志消息匹配符测试")
log.Info("%v", log)
log.Warning("%v", logker.Shanghai)
log.Error("ERROR")
}
[ DEBUG ] - 时间 2020-04-20 11:57:23.8927 - 位置 main.go|main.main:23 - 消息 DEBUG 自定义日志消息匹配符测试
[ INFO ] - 时间 2020-04-20 11:57:23.8928 - 位置 main.go|main.main:24 - 消息 &{0 Asia/Shanghai 0xc00008e220 {level} - 时间 {t位置 {position} - 消息 {message}}
[WARNING] - 时间 2020-04-20 11:57:23.8928 - 位置 main.go|main.main:25 - 消息 Asia/Shanghai
[ ERROR ] - 时间 2020-04-20 11:57:23.8929 - 位置 main.go|main.main:26 - 消息 ERROR
截图没有更新~ 当前截图为 v1.0.9 version,你可以自己安装库使用查看效果,当然可能是新版本的牛逼一点2333333
- fatih (https://github.com/fatih/color)
- Icon Mafia (Logo & Banner 设计)
- When are you? 😜
欢迎提交issues👏 不一定能及时处理因为开源项目,我还有其他工作需要做。
欢迎🇨🇳中国区小伙伴加入代码贡献.不对应该会中文交流就可以23333💐
Pkg Docs:
click to pkg.go.dev
This project open source is MIT License . See the LICENSE file content.