v1.2.1 增加es管道写入日志

This commit is contained in:
liangzy 2020-04-28 15:49:04 +08:00
parent 48f1a7b6ca
commit f35dc15fb2
2 changed files with 16 additions and 3 deletions

17
log.go
View File

@ -48,7 +48,7 @@ func New(label string, channelLens ...int64) (l *Logger, loaded bool) {
}
func Get(label string, channelLens ...int64) (l *Logger) {
var filelevel Level = LevelWarning
var filelevel Level = LevelInfo
var loaded bool
if os.Getenv(envkey) == "dev" {
filelevel = LevelAll
@ -57,6 +57,19 @@ func Get(label string, channelLens ...int64) (l *Logger) {
if l, loaded = New(label, channelLens...); !loaded {
l.SetAdapter(filelevel, AdapterFile).SetAdapter(LevelAll, AdapterConsole)
}
return
}
func GetEs(label string, channelLens ...int64) (l *Logger) {
var filelevel Level = LevelInfo
var loaded bool
if os.Getenv(envkey) == "dev" {
filelevel = LevelAll
}
if l, loaded = New(label, channelLens...); !loaded {
l.SetAdapter(filelevel, AdapterFile).SetAdapter(LevelAll, AdapterConsole).SetAdapter(filelevel, AdapterElasticSearch)
}
return
}

View File

@ -12,7 +12,7 @@ func TestGetLogger(t *testing.T) {
l.Critical("出错了")
Get("nds").Warning("hadoee %s", time.Now().Format(time.RFC1123))
Get("wifi").SetAdapter(LevelAll, AdapterElasticSearch)
GetEs("wifi")
for i := 0; i < 10; i++ {
Get("wifi").Error("neoweiwoewe")
}