48 lines
1.0 KiB
Go
48 lines
1.0 KiB
Go
|
package grlogs
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"github.com/astaxie/beego/logs"
|
||
|
"os"
|
||
|
"path"
|
||
|
)
|
||
|
|
||
|
var adatperMapper = map[string]func(l *Logger, level int) error{
|
||
|
|
||
|
AdapterFile: func(l *Logger, level int) error {
|
||
|
if wd, err := os.Getwd(); err == nil {
|
||
|
c := FileLogConfig{
|
||
|
Filename: path.Join(wd, fmt.Sprintf("runtime/logs/%s.log", l.Lable)),
|
||
|
Level: level,
|
||
|
Maxlines: 0,
|
||
|
Daily: true,
|
||
|
Maxdays: 7,
|
||
|
Color: true,
|
||
|
Rotate: true,
|
||
|
}
|
||
|
return l.SetLogger(logs.AdapterFile, c.String())
|
||
|
} else {
|
||
|
return err
|
||
|
}
|
||
|
},
|
||
|
|
||
|
AdapterConsole: func(l *Logger, level int) error {
|
||
|
c := ConsoleLogConfig{Level: level}
|
||
|
return l.SetLogger(logs.AdapterConsole, c.String())
|
||
|
},
|
||
|
|
||
|
AdapterElasticSearch: func(l *Logger, level int) error {
|
||
|
|
||
|
dsn := "http://es-cn-0pp1mm3hq000dnbh4.public.elasticsearch.aliyuncs.com:9200/"
|
||
|
if envkey == "prod" || envkey == "" {
|
||
|
dsn = "http://es-cn-0pp1mm3hq000dnbh4.public.elasticsearch.aliyuncs.com:9200/"
|
||
|
}
|
||
|
|
||
|
c := EsConfig{
|
||
|
Dsn: dsn,
|
||
|
Level: level,
|
||
|
}
|
||
|
return l.SetLogger(logs.AdapterEs, c.String())
|
||
|
},
|
||
|
}
|