
ketty 是一个 Golang 开发的简单的日志美化输出 Logger 。
https://github.com/anqiansong/ketty
$ go install github.com/anqiansong/ketty@latest func main(){ console.Info(` { "name":"Hello Ketty", "description":"a color logger", "author":"anqiansong", "category":"console", "github":"https://github.com/anqiansong/ketty", "useage":[ "info", "debug" ] }`) console.Debug("Hello Ketty") console.Warn("Hello Ketty") console.Error(errors.New("error test")) } 

直接使用的 Console 实例支持一些默认配置项:
frame.WithLineStyle 作为边框func main(){ console.Info("Hello ketty, This is info log") console.Debug("Hello ketty, This debug log") console.Warn("Hello ketty, This warn log") console.Error(errors.New("Hello ketty,This is an error")) } // 替换默认的边框 plusStyle := text.WithPlusStyle() c := console.NewConsole(console.WithTextOption(plusStyle)) c.DisableBorder() // 禁用边框 c.DisableColor() // 禁用颜色美化 // 输出 info 日志 c.Info("Hello Ketty, It's now %q", time.Now()) [INFO] 2021-11-26 23:24:51.826 ┌──────────── [INFO] 2021-11-26 23:24:51.826 │ Hello Ketty [INFO] 2021-11-26 23:24:51.826 └──────────── [INFO] 2021-11-26 23:25:16.794 ............. [INFO] 2021-11-26 23:25:16.794 . Hello Ketty [INFO] 2021-11-26 23:25:16.794 ............. [INFO] 2021-11-26 23:25:30.461 ************* [INFO] 2021-11-26 23:25:30.461 * Hello Ketty [INFO] 2021-11-26 23:25:30.461 ************* [INFO] 2021-11-26 23:25:45.736 +------------ [INFO] 2021-11-26 23:25:45.736 | Hello Ketty [INFO] 2021-11-26 23:25:45.736 +------------ [INFO] 2021-11-26 23:26:02.382 ★★★★★★★★★★★★★ [INFO] 2021-11-26 23:26:02.382 ★ Hello Ketty [INFO] 2021-11-26 23:26:02.382 ★★★★★★★★★★★★★ [INFO] 2021-11-26 23:26:18.008 [INFO] 2021-11-26 23:26:18.008 Hello Ketty [INFO] 2021-11-26 23:26:18.008 [INFO] 2021-11-26 22:33:01.695 Hello Ketty, It's now "2021-11-26 22:33:01.695338 +0800 CST m=+0.000156150" // 边框横向、众项、拐角均为一种符号 plusStyle := text.WithCommonBorder("x") [INFO] 2021-11-26 23:26:44.162 xxxxxxxxxxxxx [INFO] 2021-11-26 23:26:44.162 x Hello Ketty [INFO] 2021-11-26 23:26:44.162 xxxxxxxxxxxxx // arg1: 左上角符号 // arg2: 左下角符号 // arg3: 横向边框符号 // arg4: 垂直边框符号 plusStyle := text.WithBorder("=","=","-","|") c := console.NewConsole(console.WithTextOption(plusStyle)) [INFO] 2021-11-26 23:26:59.321 =------------ [INFO] 2021-11-26 23:26:59.321 | Hello Ketty [INFO] 2021-11-26 23:26:59.321 =------------ TODO
Windows 不支持美化输出。
1 tiedan 2021 年 11 月 27 日 实用性略差 |
2 EvaCcino 2021 年 11 月 27 日 日志系统杀手…… |
3 jasonkayzk 2021 年 11 月 27 日 这种打到 elk 有些行不就是 ★★★★★★★★★★★★★ |
4 joesonw 2021 年 11 月 27 日 via iPhone 建议可以兼容不同的其他 logger 。这种格式毕竟也还是开发阶段用的多,线上不太适合采集分析。 |
5 codeMore 2021 年 11 月 27 日 日志量是不是扩大了一倍? |
6 KesonAn OP 到线上可以禁用美化输出,这个的初衷主要是本地集成调式或者一些工具开发使用 |