作者 陈志颖

fix conflict

2021/09/07 01:40:08.650 [D] [hook.go:130] CREATE TABLE IF NOT EXISTS "login_access" ("login_access_id" bigserial, "account" text, "platform" text, "company_id" bigint, "organization_id" bigint, "access_token" text, "refresh_token" text, "access_expired" bigint, "refresh_expired" bigint, "created_time" timestamptz, "updated_time" timestamptz, PRIMARY KEY ("login_access_id")) null
2021/09/07 01:40:09.439 [I] [hooks.go:101] generate router from comments
2021/09/07 01:40:09.440 [I] [???:0] http server Running on http://:8083
2021/09/07 01:40:12.667 [I] [filter.go:81] http请求 [
{
"framework": "beego",
"method": "GET",
"url": "/log"
}
]
2021/09/07 01:40:12.667 [D] [filter.go:81] http请求 [
{
"framework": "beego",
"method": "GET",
"url": "/log"
}
]
2021/09/07 01:40:12.669 [D] [filter.go:81] http响应 [
{
"framework": "beego",
"method": "GET",
"outputData": null,
"url": "/log"
}
]
2021/09/07 01:40:12.669 [D] [router.go:664] | ::1| 200 | 2.412278ms| match| GET  /log r:/log
2021/09/07 01:42:14.324 [D] [hook.go:130] CREATE TABLE IF NOT EXISTS "login_access" ("login_access_id" bigserial, "account" text, "platform" text, "company_id" bigint, "organization_id" bigint, "access_token" text, "refresh_token" text, "access_expired" bigint, "refresh_expired" bigint, "created_time" timestamptz, "updated_time" timestamptz, PRIMARY KEY ("login_access_id")) null
2021/09/07 01:42:15.705 [I] [hooks.go:101] generate router from comments
2021/09/07 01:42:15.706 [I] [???:0] http server Running on http://:8083
... ...
... ... @@ -91,14 +91,16 @@ spec:
value: ""
- name: LOG_LEVEL
value: "debug"
- name: LOG_FRAMEWORK
value: "beego"
- name: LOG_TYPE
value: file
value: "file"
- name: ERROR_BASE_CODE
value: "1"
- name: ERROR_BASE_CODE_MULTIPLE
value: "1000"
- name: ENABLE_KAFKA_LOG
value: "true"
value: "false"
- name: HTTP_PORT
value: "8082"
- name: ALLIED_CREATION_USER_HOST
... ...
... ... @@ -48,6 +48,7 @@ github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1
github.com/eapache/queue v1.1.0 h1:YOEu7KNc61ntiQlcEeUIoDTJ2o8mQznoNvUhiigpIqc=
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
github.com/edsrzf/mmap-go v0.0.0-20170320065105-0bce6a688712/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M=
github.com/elastic/go-elasticsearch/v6 v6.8.5 h1:U2HtkBseC1FNBmDr0TR2tKltL6FxoY+niDAlj5M8TK8=
github.com/elastic/go-elasticsearch/v6 v6.8.5/go.mod h1:UwaDJsD3rWLM5rKNFzv9hgox93HoX8utj1kxD9aFUcI=
github.com/elazarl/go-bindata-assetfs v1.0.0 h1:G/bYguwHIzWq9ZoyUQqrjTmJbbYn3j3CKKpKinvZLFk=
github.com/elazarl/go-bindata-assetfs v1.0.0/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4=
... ...
... ... @@ -8,8 +8,11 @@ import (
const SERVICE_NAME = "allied-creation-gateway"
var LOG_LEVEL = "debug"
var LOG_TYPE = "console"
var LOG_TYPE = "console"// file, console, es
var LOG_FRAMEWORK = "beego" // beego logrus
var LOG_FILE = "app.log"
var LOG_PREFIX = "[allied-creation-gateway]"
var HTTP_PORT int = 8083
//天联共创基础模块
... ...
... ... @@ -19,6 +19,10 @@ func init() {
// POSTGRESQL_PORT = os.Getenv("TOPIC_LOG_STASH")
//}
if os.Getenv("ENABLE_KAFKA_LOG") != "" {
ENABLE_KAFKA_LOG = true
if os.Getenv("ENABLE_KAFKA_LOG") == "true" {
ENABLE_KAFKA_LOG = true
} else if os.Getenv("ENABLE_KAFKA_LOG") == "false" {
ENABLE_KAFKA_LOG = false
}
}
}
... ...
... ... @@ -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,
}
}
... ...
package log
import (
"github.com/linmadan/egglib-go/log/logrus"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/constant"
"github.com/linmadan/egglib-go/log"
... ... @@ -9,13 +10,15 @@ import (
var Logger log.Logger
func init() {
// Logger = logrus.NewLogrusLogger()
// Logger.SetServiceName(constant.SERVICE_NAME)
// Logger.SetLevel(constant.LOG_LEVEL)
// //
Logger = NewBeegoLog(LoggerConfig{
Filename: constant.LOG_FILE,
Level: 7,
MaxSize: 1024 * 1024 * 2,
})
if constant.LOG_FRAMEWORK == "beego" {
Logger = NewBeegoLog(LoggerConfig{
Filename: constant.LOG_FILE,
Level: 7,
MaxSize: 1024 * 1024 * 2,
})
} else if constant.LOG_FRAMEWORK == "logrus" {
Logger = logrus.NewLogrusLogger()
Logger.SetServiceName(constant.SERVICE_NAME)
Logger.SetLevel(constant.LOG_LEVEL)
}
}
... ...
package controllers
import "io/ioutil"
type LoggerController struct {
BaseController
}
func (controller LoggerController) Index() {
bytes, _ := ioutil.ReadFile("./app.log")
controller.Ctx.WriteString(string(bytes))
}
... ...
package routers
import (
"github.com/beego/beego/v2/server/web"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/controllers"
)
func init() {
web.Router("/log", &controllers.LoggerController{}, "Get:Index")
}
... ...