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")
|
|
|
|
|
```
|
|
|
|
|
lable 为通
|
|
|
|
|
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;
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
5. 文件日志会写入到 `./runtime/logs/` 文件夹 请务必在项目构建阶段创建该目录
|