diff --git a/README.md b/README.md index bac496a..e1c08bd 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,21 @@ # grlogs -本库为争游内部日志公共库 +本库为争游内部日志公共库, 该库基于 beegoLogger 基础上完善, 目前支持的引擎有 file、console、net、smtp、es ## 代码示例 1. 引入 -```go +``` import "golib.gaore.com/GaoreGo/grlogs" ``` 2. 简单用法 -```go +``` grlogs.Get("test", 128).Info("hello word") grlogs.Get("test").Warning("hello word") ``` `Get` 方法中 `lable` 参数为标签,为识别分类所用,在Grlogs里一个分类使用一个管道进行日志 3. 进阶用法 -```go +``` logger := grlogs.GetEs("wifi") logger.SetAdapter(LevelAll, AdapterElasticSearch) logger.SetAdapter(LevelInfo, AdapterFile) @@ -32,4 +32,46 @@ export GRLOG_APP_NAME=mkt.gaore.com; import _ "golib.gaore.com/GaoreGo/grlogs/logs/es" ``` -5. 文件日志会写入到 `./runtime/logs/` 文件夹 请务必在项目构建阶段创建该目录 \ No newline at end of file +5. 文件日志会写入到 `./runtime/logs/` 文件夹 **请务必在项目构建阶段创建该目录** + + +6. 完整示例 +```go +package grlogs + +import ( + "fmt" + _ "golib.gaore.com/GaoreGo/grlogs/logs/es" + "testing" + "time" +) + +func TestGetLogger(t *testing.T) { + // 新建 channel 大小为128 标识为nds 日志通道 , Get 的方法 默认带 console 和 file 输出 + l := Get("nds", 128).SetAdapter(LevelAll, AdapterElasticSearch) + l.Debug("我正在调试") + l.Critical("出错了") + + // 复用 nds 的日志通道 + Get("nds").Warning("hadoee %s", time.Now().Format(time.RFC1123)) + Get("nds").Warning("hadoee %s", time.Now().Format(time.RFC1123)) + + // 新建 channel 大小为默认 标识为wifi 日志通道 , GetEs 的方法 默认带 console 和 file 和 elatisearch 输出 + GetEs("wifi") + for i := 0; i < 10; i++ { + Get("wifi").Warning("Warning") + Get("wifi").Warn("Warn") + Get("wifi").Debug("Debug") + Get("wifi").Error("Error") + Get("wifi").Notice("Notice") + Get("wifi").Info("Info") + Get("wifi").Alert("Alert") + } + + Get("wifi").Critical("neoweiwoewe") +} + +func TestGetEs(t *testing.T) { + fmt.Println("hello world") +} +``` \ No newline at end of file diff --git a/log_test.go b/log_test.go index cffd49f..3de85b4 100644 --- a/log_test.go +++ b/log_test.go @@ -1,23 +1,37 @@ package grlogs import ( + "fmt" _ "golib.gaore.com/GaoreGo/grlogs/logs/es" "testing" "time" ) func TestGetLogger(t *testing.T) { + // 新建 channel 大小为128 标识为nds 日志通道 , Get 的方法 默认带 console 和 file 输出 l := Get("nds", 128).SetAdapter(LevelAll, AdapterElasticSearch) l.Debug("我正在调试") l.Critical("出错了") + + // 复用 nds 的日志通道 + Get("nds").Warning("hadoee %s", time.Now().Format(time.RFC1123)) Get("nds").Warning("hadoee %s", time.Now().Format(time.RFC1123)) + // 新建 channel 大小为默认 标识为wifi 日志通道 , GetEs 的方法 默认带 console 和 file 和 elatisearch 输出 GetEs("wifi") for i := 0; i < 10; i++ { - Get("wifi").Error("neoweiwoewe") + Get("wifi").Warning("Warning") + Get("wifi").Warn("Warn") + Get("wifi").Debug("Debug") + Get("wifi").Error("Error") + Get("wifi").Notice("Notice") + Get("wifi").Info("Info") + Get("wifi").Alert("Alert") } + + Get("wifi").Critical("neoweiwoewe") } func TestGetEs(t *testing.T) { - + fmt.Println("hello world") }