高热共公日志库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
liangzy 01c35869b8 接入阿里sls, 增加关闭日志通道 4 years ago
logs 接入阿里sls 4 years ago
.gitignore v1.2.0 整个beegolog 打进去, 增加syncmap日志通道 4 years ago
README.md 接入阿里sls 4 years ago
config.go 接入阿里sls 4 years ago
funtion.go 接入阿里sls 4 years ago
log.go 接入阿里sls, 增加关闭日志通道 4 years ago
log_test.go 接入阿里sls, 增加关闭日志通道 4 years ago
options.go 接入阿里sls 4 years ago

README.md

grlogs

本库为争游内部日志公共库, 该库基于 beegoLogger 基础上完善, 目前支持的引擎有 file、console、net、smtp、es、alisls

代码示例

  1. 引入
import "golib.gaore.com/GaoreGo/grlogs"
  1. 简单用法
 grlogs.Get("test", 128).Info("hello word")
 grlogs.Get("test").Warning("hello word")

Get 方法中 lable 参数为标签,为识别分类所用,在Grlogs里一个分类使用一个管道进行日志

  1. 进阶用法
logger := grlogs.GetEs("wifi")
logger.SetAdapter(LevelAll, AdapterElasticSearch)
logger.SetAdapter(LevelInfo, AdapterFile)
logger.Critical("出错了")
logger.Info("出错了")
  1. 如果需要写入es, 必须设置环境变量 GRLOG_APP_NAME, 不能有反斜杠, 如
export GRLOG_APP_NAME=mkt.gaore.com;

还需要额外引入es库,完成初始化动作

import _ "golib.gaore.com/GaoreGo/grlogs/logs/es"
  1. 文件日志会写入到 ./runtime/logs/ 文件夹 请务必在项目构建阶段创建该目录

  2. 完整示例

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")
}