作者 陈志颖

fix:共创申请查询参数修复

... ... @@ -54,6 +54,8 @@ spec:
env:
- name: LOG_LEVEL
value: "debug"
- name: LOG_FRAMEWORK
value: "beego"
- name: LOG_TYPE
value: "file"
- name: ERROR_BASE_CODE
... ... @@ -61,7 +63,7 @@ spec:
- name: ERROR_BASE_CODE_MULTIPLE
value: "1000"
- name: ENABLE_KAFKA_LOG
value: "true"
value: "false"
- name: USER_MODULE_HOST
value: "http://allied-creation-user-dev.fjmaimaimai.com"
- name: REDIS_HOST
... ...
package main
import (
"fmt"
"github.com/beego/beego/v2/server/web"
"github.com/linmadan/egglib-go/log/logrus"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/constant"
_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/constant"
_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log"
_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log"
_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/port/beego"
)
func main() {
// web主服务
//if constant.ENABLE_KAFKA_LOG {
// w, _ := logrus.NewKafkaWriter(constant.KAFKA_HOSTS, constant.TOPIC_LOG_STASH, false)
// log.Logger.AddHook(w)
//}
if constant.ENABLE_KAFKA_LOG {
w, err := logrus.NewKafkaWriter(constant.KAFKA_HOSTS, constant.TOPIC_LOG_STASH, false)
if err != nil {
log.Logger.Error(err.Error())
}
log.Logger.AddHook(w)
}
fmt.Printf("Server running at:%d\n", web.BConfig.Listen.HTTPPort)
web.Run()
}
... ...
... ... @@ -6,6 +6,7 @@ const SERVICE_NAME = "allied-creation-cooperation"
// LOG_TYPE 日志相关设置
var LOG_TYPE = "terminal" // file, terminal, es
var LOG_FRAMEWORK = "beego" // beego logrus
var LOG_LEVEL = "debug"
var LOG_FILE = "app.log"
var LOG_PREFIX = "[allied-creation-cooperation]"
... ... @@ -23,6 +24,9 @@ func init() {
if os.Getenv("LOG_LEVEL") != "" {
LOG_LEVEL = os.Getenv("LOG_LEVEL")
}
if os.Getenv("LOG_FRAMEWORK") != "" {
LOG_FRAMEWORK = os.Getenv("LOG_FRAMEWORK")
}
if os.Getenv("LOG_FILE") != "" {
LOG_FILE = os.Getenv("LOG_FILE")
}
... ...
... ... @@ -2,23 +2,27 @@ package constant
import "os"
// kafka 地址
// KAFKA_HOSTS kafka 地址
var KAFKA_HOSTS = "192.168.0.250:9092,192.168.0.251:9092,192.168.0.252:9092"
// kafka topic log stash
// TOPIC_LOG_STASH kafka topic log stash
var TOPIC_LOG_STASH = "go_stash_dev"
// 是否启用日志收集 (本地不启用)
// ENABLE_KAFKA_LOG 是否启用日志收集 (本地不启用)
var ENABLE_KAFKA_LOG = false
func init() {
//if os.Getenv("KAFKA_HOSTS") != "" {
// KAFKA_HOSTS = os.Getenv("KAFKA_HOSTS")
//}
//if os.Getenv("TOPIC_LOG_STASH") != "" {
// POSTGRESQL_PORT = os.Getenv("TOPIC_LOG_STASH")
//}
if os.Getenv("KAFKA_HOSTS") != "" {
KAFKA_HOSTS = os.Getenv("KAFKA_HOSTS")
}
if os.Getenv("TOPIC_LOG_STASH") != "" {
POSTGRESQL_PORT = os.Getenv("TOPIC_LOG_STASH")
}
if os.Getenv("ENABLE_KAFKA_LOG") != "" {
if os.Getenv("ENABLE_KAFKA_LOG") == "true" {
ENABLE_KAFKA_LOG = true
} else if os.Getenv("ENABLE_KAFKA_LOG") == "false" {
ENABLE_KAFKA_LOG = false
}
}
}
... ...
... ... @@ -248,7 +248,7 @@ func (repository *CooperationApplicationRepository) Find(queryOptions map[string
if userBaseId, ok := queryOptions["userBaseId"]; ok && userBaseId.(int64) != 0 {
query.Where(`(cooperation_application.cooperation_application_applicant->>'userBaseId' ='?')`, userBaseId)
}
if isCanceled, ok := queryOptions["isCanceled"]; ok && isCanceled.(int32) != 3 {
if isCanceled, ok := queryOptions["isCanceled"]; ok && isCanceled.(int32) != 0 {
query.Where("is_canceled = ?", isCanceled)
}
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
... ...
... ... @@ -26,7 +26,6 @@ type BeegoLog struct {
}
func (logger *BeegoLog) AddHook(write io.Writer) {
panic("implement me")
}
func (logger *BeegoLog) SetServiceName(serviceName string) {
... ...
... ... @@ -2,25 +2,22 @@ package log
import (
"github.com/linmadan/egglib-go/log"
"github.com/linmadan/egglib-go/log/logrus"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/constant"
)
var Logger log.Logger
func init() {
//Logger = logrus.NewLogrusLogger()
//Logger.SetServiceName(constant.SERVICE_NAME)
//Logger.SetLevel(constant.LOG_LEVEL)
if constant.LOG_TYPE == "es" {
Logger = NewServerLog()
Logger.SetServiceName(constant.SERVICE_NAME)
Logger.SetLevel(constant.LOG_LEVEL)
} else {
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 log
import (
"fmt"
"github.com/olivere/elastic/v7"
"github.com/sirupsen/logrus"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/constant"
"gopkg.in/sohlich/elogrus.v7"
"io"
"os"
)
type ServerLog struct {
serviceName string
logrus *logrus.Logger
}
func (logger *ServerLog) AddHook(write io.Writer) {
panic("implement me")
}
func (logger *ServerLog) SetServiceName(serviceName string) {
logger.serviceName = serviceName
}
func (logger *ServerLog) SetLevel(level string) {
switch level {
case "trace":
logger.logrus.Level = logrus.TraceLevel
case "debug":
logger.logrus.Level = logrus.DebugLevel
case "info":
logger.logrus.Level = logrus.InfoLevel
case "warn":
logger.logrus.Level = logrus.WarnLevel
case "error":
logger.logrus.Level = logrus.ErrorLevel
case "fatal":
logger.logrus.Level = logrus.FatalLevel
case "panic":
logger.logrus.Level = logrus.PanicLevel
default:
logger.logrus.Level = logrus.DebugLevel
}
}
func (logger *ServerLog) Trace(msg string, appends ...map[string]interface{}) {
contextLogger := logger.logrus.WithFields(logrus.Fields{"serviceName": logger.serviceName})
for _, append := range appends {
contextLogger = contextLogger.WithFields(append)
}
contextLogger.Trace(msg)
}
func (logger *ServerLog) Debug(msg string, appends ...map[string]interface{}) {
contextLogger := logger.logrus.WithFields(logrus.Fields{"serviceName": logger.serviceName})
for _, append := range appends {
contextLogger = contextLogger.WithFields(append)
}
contextLogger.Debug(msg)
}
func (logger *ServerLog) Info(msg string, appends ...map[string]interface{}) {
contextLogger := logger.logrus.WithFields(logrus.Fields{"serviceName": logger.serviceName})
for _, append := range appends {
contextLogger = contextLogger.WithFields(append)
}
contextLogger.Info(msg)
}
func (logger *ServerLog) Warn(msg string, appends ...map[string]interface{}) {
contextLogger := logger.logrus.WithFields(logrus.Fields{"serviceName": logger.serviceName})
for _, append := range appends {
contextLogger = contextLogger.WithFields(append)
}
contextLogger.Warn(msg)
}
func (logger *ServerLog) Error(msg string, appends ...map[string]interface{}) {
contextLogger := logger.logrus.WithFields(logrus.Fields{"serviceName": logger.serviceName})
for _, append := range appends {
contextLogger = contextLogger.WithFields(append)
}
contextLogger.Error(msg)
}
func (logger *ServerLog) Fatal(msg string, appends ...map[string]interface{}) {
contextLogger := logger.logrus.WithFields(logrus.Fields{"serviceName": logger.serviceName})
for _, append := range appends {
contextLogger = contextLogger.WithFields(append)
}
contextLogger.Fatal(msg)
}
func (logger *ServerLog) Panic(msg string, appends ...map[string]interface{}) {
contextLogger := logger.logrus.WithFields(logrus.Fields{"serviceName": logger.serviceName})
for _, append := range appends {
contextLogger = contextLogger.WithFields(append)
}
contextLogger.Panic(msg)
}
func NewServerLog() *ServerLog {
logger := logrus.New()
logger.Formatter = &logrus.JSONFormatter{
TimestampFormat: "2006-01-02 15:04:05",
PrettyPrint: true,
}
if constant.LOG_TYPE == "file" {
file, err := os.OpenFile("logrus.log", os.O_CREATE|os.O_WRONLY, 0666)
if err == nil {
_ = file.Truncate(1024 * 1024 * 2)
logger.Out = file
} else {
logger.Info("Failed to log to file, using default stderr")
}
} else if constant.LOG_TYPE == "es" {
url := fmt.Sprintf("http://%s:%s", "es.chenzhiying.asia", "80")
client, err := elastic.NewClient(elastic.SetURL(url), elastic.SetSniff(false))
if err != nil {
//log.Panic(err)
panic(err)
}
hook, err := elogrus.NewAsyncElasticHook(client, "es.chenzhiying.asia", logrus.DebugLevel, "boss-appointment")
if err != nil {
//log.Panic(err)
panic(err)
}
logger.Hooks.Add(hook)
} else {
logger.Out = os.Stdout
}
return &ServerLog{
logrus: logger,
}
}