更新read me
This commit is contained in:
		
							parent
							
								
									1e57935100
								
							
						
					
					
						commit
						d6024cf64c
					
				
							
								
								
									
										52
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										52
									
								
								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/` 文件夹 请务必在项目构建阶段创建该目录 | ||||
| 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") | ||||
| } | ||||
| ``` | ||||
							
								
								
									
										18
									
								
								log_test.go
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								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") | ||||
| } | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user