2020-04-01 11:28:11 +08:00
|
|
|
|
# grlogs
|
2020-04-28 17:17:21 +08:00
|
|
|
|
本库为争游内部日志公共库
|
2020-04-01 11:28:11 +08:00
|
|
|
|
|
2020-04-28 17:17:21 +08:00
|
|
|
|
## 代码示例
|
|
|
|
|
|
|
|
|
|
1. 引入
|
|
|
|
|
```go
|
|
|
|
|
import "golib.gaore.com/GaoreGo/grlogs"
|
|
|
|
|
```
|
|
|
|
|
2. 简单用法
|
|
|
|
|
```go
|
|
|
|
|
grlogs.Get("test", 128).Info("hello word")
|
|
|
|
|
grlogs.Get("test").Warning("hello word")
|
|
|
|
|
```
|
2020-04-28 17:38:45 +08:00
|
|
|
|
`Get` 方法中 `lable` 参数为标签,为识别分类所用,在Grlogs里一个分类使用一个管道进行日志
|
|
|
|
|
|
2020-04-28 17:17:21 +08:00
|
|
|
|
3. 进阶用法
|
|
|
|
|
```go
|
|
|
|
|
logger := grlogs.GetEs("wifi")
|
|
|
|
|
logger.SetAdapter(LevelAll, AdapterElasticSearch)
|
|
|
|
|
logger.SetAdapter(LevelInfo, AdapterFile)
|
|
|
|
|
logger.Critical("出错了")
|
|
|
|
|
logger.Info("出错了")
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
4. 如果需要写入es, 必须设置环境变量 `GRLOG_APP_NAME`, 不能有反斜杠, 如
|
|
|
|
|
```shell script
|
|
|
|
|
export GRLOG_APP_NAME=mkt.gaore.com;
|
|
|
|
|
```
|
2020-04-28 19:56:24 +08:00
|
|
|
|
还需要额外引入es库,完成初始化动作
|
|
|
|
|
```go
|
|
|
|
|
import _ "golib.gaore.com/GaoreGo/grlogs/logs/es"
|
|
|
|
|
```
|
2020-04-28 17:17:21 +08:00
|
|
|
|
|
|
|
|
|
5. 文件日志会写入到 `./runtime/logs/` 文件夹 请务必在项目构建阶段创建该目录
|