...
|
...
|
@@ -4,12 +4,11 @@ import ( |
|
|
"bytes"
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
"io"
|
|
|
"strconv"
|
|
|
|
|
|
"github.com/beego/beego/v2/core/logs"
|
|
|
"github.com/linmadan/egglib-go/log"
|
|
|
_ "github.com/beego/beego/v2/core/logs/es"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/constant"
|
|
|
"io"
|
|
|
"strconv"
|
|
|
)
|
|
|
|
|
|
type LoggerConfig struct {
|
...
|
...
|
@@ -26,35 +25,7 @@ type BeegoLog struct { |
|
|
beeLogger *logs.BeeLogger
|
|
|
}
|
|
|
|
|
|
var _ log.Logger = &BeegoLog{}
|
|
|
|
|
|
func NewBeegoLog(conf LoggerConfig) *BeegoLog {
|
|
|
logger := logs.GetBeeLogger()
|
|
|
logger.SetLevel(conf.Level)
|
|
|
if constant.LOG_TYPE == "file" { // 日志存储到文件
|
|
|
confByte, _ := json.Marshal(conf)
|
|
|
err := logger.SetLogger(logs.AdapterFile, string(confByte))
|
|
|
if err != nil {
|
|
|
fmt.Println(err.Error())
|
|
|
return nil
|
|
|
}
|
|
|
} else { // 日志输出到控制台
|
|
|
err := logger.SetLogger(logs.AdapterConsole, `{"level":7,"color":true}`)
|
|
|
if err != nil {
|
|
|
fmt.Println(err.Error())
|
|
|
return nil
|
|
|
}
|
|
|
}
|
|
|
logger.SetPrefix(constant.SERVICE_NAME)
|
|
|
logger.EnableFuncCallDepth(true)
|
|
|
logger.SetLogFuncCallDepth(5)
|
|
|
return &BeegoLog{
|
|
|
beeLogger: logger,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func (logger *BeegoLog) AddHook(write io.Writer) {
|
|
|
|
|
|
}
|
|
|
|
|
|
func (logger *BeegoLog) SetServiceName(serviceName string) {
|
...
|
...
|
@@ -118,3 +89,35 @@ func (logger *BeegoLog) Fatal(msg string, appends ...map[string]interface{}) { |
|
|
func (logger *BeegoLog) Panic(msg string, appends ...map[string]interface{}) {
|
|
|
logs.Error(msg, appends)
|
|
|
}
|
|
|
|
|
|
func NewBeegoLog(conf LoggerConfig) *BeegoLog {
|
|
|
logger := logs.GetBeeLogger()
|
|
|
logger.SetLevel(conf.Level)
|
|
|
if constant.LOG_TYPE == "file" { // 日志存储到文件
|
|
|
confByte, _ := json.Marshal(conf)
|
|
|
err := logger.SetLogger(logs.AdapterFile, string(confByte))
|
|
|
if err != nil {
|
|
|
fmt.Println(err.Error())
|
|
|
return nil
|
|
|
}
|
|
|
} else if constant.LOG_TYPE == "es" { // 日志存储到ES
|
|
|
err := logger.SetLogger(logs.AdapterEs, `{"dsn":"http://192.168.100.222:9200/","level":7}`)
|
|
|
if err != nil {
|
|
|
fmt.Println(err.Error())
|
|
|
return nil
|
|
|
}
|
|
|
} else { // 日志输出到控制台
|
|
|
err := logger.SetLogger(logs.AdapterConsole, `{"level":7,"color":true}`)
|
|
|
if err != nil {
|
|
|
fmt.Println(err.Error())
|
|
|
return nil
|
|
|
}
|
|
|
}
|
|
|
logger.SetPrefix(constant.LOG_PREFIX)
|
|
|
logger.EnableFuncCallDepth(true)
|
|
|
logger.SetLogFuncCallDepth(5)
|
|
|
logger.SetPrefix(constant.LOG_PREFIX)
|
|
|
return &BeegoLog{
|
|
|
beeLogger: logger,
|
|
|
}
|
|
|
} |
...
|
...
|
|