v1.2.1 增加es管道写入日志
This commit is contained in:
parent
48f1a7b6ca
commit
f35dc15fb2
17
log.go
17
log.go
@ -48,7 +48,7 @@ func New(label string, channelLens ...int64) (l *Logger, loaded bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Get(label string, channelLens ...int64) (l *Logger) {
|
func Get(label string, channelLens ...int64) (l *Logger) {
|
||||||
var filelevel Level = LevelWarning
|
var filelevel Level = LevelInfo
|
||||||
var loaded bool
|
var loaded bool
|
||||||
if os.Getenv(envkey) == "dev" {
|
if os.Getenv(envkey) == "dev" {
|
||||||
filelevel = LevelAll
|
filelevel = LevelAll
|
||||||
@ -57,6 +57,19 @@ func Get(label string, channelLens ...int64) (l *Logger) {
|
|||||||
if l, loaded = New(label, channelLens...); !loaded {
|
if l, loaded = New(label, channelLens...); !loaded {
|
||||||
l.SetAdapter(filelevel, AdapterFile).SetAdapter(LevelAll, AdapterConsole)
|
l.SetAdapter(filelevel, AdapterFile).SetAdapter(LevelAll, AdapterConsole)
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
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
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -12,7 +12,7 @@ func TestGetLogger(t *testing.T) {
|
|||||||
l.Critical("出错了")
|
l.Critical("出错了")
|
||||||
Get("nds").Warning("hadoee %s", time.Now().Format(time.RFC1123))
|
Get("nds").Warning("hadoee %s", time.Now().Format(time.RFC1123))
|
||||||
|
|
||||||
Get("wifi").SetAdapter(LevelAll, AdapterElasticSearch)
|
GetEs("wifi")
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
Get("wifi").Error("neoweiwoewe")
|
Get("wifi").Error("neoweiwoewe")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user