2020-04-27 21:26:13 +08:00
|
|
|
package grlogs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/astaxie/beego/logs"
|
|
|
|
"os"
|
|
|
|
"path"
|
|
|
|
)
|
|
|
|
|
2020-04-28 10:37:47 +08:00
|
|
|
var adatperMapper = map[Adapter]func(l *Logger, level Level) error{
|
2020-04-27 21:26:13 +08:00
|
|
|
|
2020-04-28 10:37:47 +08:00
|
|
|
AdapterFile: func(l *Logger, level Level) error {
|
2020-04-27 21:26:13 +08:00
|
|
|
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,
|
|
|
|
}
|
2020-04-28 10:37:47 +08:00
|
|
|
|
2020-04-27 21:26:13 +08:00
|
|
|
return l.SetLogger(logs.AdapterFile, c.String())
|
|
|
|
} else {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-04-28 10:37:47 +08:00
|
|
|
AdapterConsole: func(l *Logger, level Level) error {
|
2020-04-27 21:26:13 +08:00
|
|
|
c := ConsoleLogConfig{Level: level}
|
|
|
|
return l.SetLogger(logs.AdapterConsole, c.String())
|
|
|
|
},
|
|
|
|
|
2020-04-28 10:37:47 +08:00
|
|
|
AdapterElasticSearch: func(l *Logger, level Level) error {
|
2020-04-27 21:26:13 +08:00
|
|
|
|
|
|
|
dsn := "http://es-cn-0pp1mm3hq000dnbh4.public.elasticsearch.aliyuncs.com:9200/"
|
|
|
|
if envkey == "prod" || envkey == "" {
|
2020-04-28 14:32:56 +08:00
|
|
|
dsn = "http://es-cn-0pp1mm3hq000dnbh4.elasticsearch.aliyuncs.com:9200/"
|
2020-04-27 21:26:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
c := EsConfig{
|
2020-04-28 14:32:56 +08:00
|
|
|
Username: "elastic",
|
|
|
|
Password: "Hellogaore@",
|
|
|
|
Dsn: dsn,
|
|
|
|
Level: level,
|
|
|
|
Index: os.Getenv("GRLOG_APP_NAME"),
|
2020-04-27 21:26:13 +08:00
|
|
|
}
|
2020-04-28 14:32:56 +08:00
|
|
|
|
2020-04-27 21:26:13 +08:00
|
|
|
return l.SetLogger(logs.AdapterEs, c.String())
|
|
|
|
},
|
|
|
|
}
|