# Ketty
ketty 是一个Golang 开发的简单的日志美化输出 Logger。
## Github
[https://github.com/anqiansong/ketty](https://github.com/anqiansong/ketty)
## 安装
```bash
$ go install github.com/anqiansong/ketty@latest
```
## 快速开始
```go
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"))
}
```
## 终端显示
![terminal](https://img-blog.csdnimg.cn/16d79669808043b5b2fd2132ea7ce7e1.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAS2Vzb27kuLY=,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center)
## Goland 显示
![](https://img-blog.csdnimg.cn/616a6114a7744ce4a492e3e2b5f49d4c.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAS2Vzb27kuLY=,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center)
![](https://img-blog.csdnimg.cn/269d0f98cb35458c8898e74ebfa15df9.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAS2Vzb27kuLY=,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center)
## 用法
### 直接使用
直接使用的 Console 实例支持一些默认配置项:
* 使用 `frame.WithLineStyle` 作为边框
* 默认美化日志
```go
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"))
}
```
### 初始化
```go
// 替换默认的边框
plusStyle := text.WithPlusStyle()
c := console.NewConsole(console.WithTextOption(plusStyle))
```
### Console 配置
```go
c.DisableBorder() // 禁用边框
c.DisableColor() // 禁用颜色美化
```
### 打印 log
```go
// 输出 info 日志
c.Info("Hello Ketty, It's now %q", time.Now())
```
## 边框样式
### 预设样式
* WithLineStyle 默认样式
```text
[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 └────────────
```
* WithDotStyle
```text
[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 .............
```
* WithStarStyle
```text
[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 *************
```
* WithPlusStyle
```text
[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 +------------
```
* WithFivePointedStarStyle
```text
[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 ★★★★★★★★★★★★★
```
* WithDoubleLine
```text
[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 ╚════════════
```
* DisableBorder
```text
[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"
```
### 自定义样式
* WithCommonBorder
```go
// 边框横向、众项、拐角均为一种符号
plusStyle := text.WithCommonBorder("x")
```
```text
[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
```
* WithBorder
```go
// arg1: 左上角符号
// arg2: 左下角符号
// arg3: 横向边框符号
// arg4: 垂直边框符号
plusStyle := text.WithBorder("=","=","-","|")
c := console.NewConsole(console.WithTextOption(plusStyle))
```
```text
[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 不支持美化输出。
有疑问加站长微信联系(非本文作者))