作者 yangfu

日志配置修改

@@ -95,6 +95,8 @@ spec: @@ -95,6 +95,8 @@ spec:
95 value: "1" 95 value: "1"
96 - name: ERROR_BASE_CODE_MULTIPLE 96 - name: ERROR_BASE_CODE_MULTIPLE
97 value: "1000" 97 value: "1000"
  98 + - name: ENABLE_KAFKA_LOG
  99 + value: "true"
98 - name: HTTP_PORT 100 - name: HTTP_PORT
99 value: "8082" 101 value: "8082"
100 - name: ALLIED_CREATION_USER_HOST 102 - name: ALLIED_CREATION_USER_HOST
@@ -2,7 +2,11 @@ package main @@ -2,7 +2,11 @@ package main
2 2
3 import ( 3 import (
4 "github.com/beego/beego/v2/server/web" 4 "github.com/beego/beego/v2/server/web"
  5 + "github.com/linmadan/egglib-go/log/logrus"
  6 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/constant"
5 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/cache" 7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/cache"
  8 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
  9 + _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
6 _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego" 10 _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego"
7 ) 11 )
8 12
@@ -11,5 +15,9 @@ func init() { @@ -11,5 +15,9 @@ func init() {
11 } 15 }
12 16
13 func main() { 17 func main() {
  18 + if constant.ENABLE_KAFKA_LOG {
  19 + w, _ := logrus.NewKafkaWriter(constant.KAFKA_HOST, constant.TOPIC_LOG_STASH, false)
  20 + log.Logger.AddHook(w)
  21 + }
14 web.Run() 22 web.Run()
15 } 23 }
@@ -5,7 +5,7 @@ import ( @@ -5,7 +5,7 @@ import (
5 "strconv" 5 "strconv"
6 ) 6 )
7 7
8 -const SERVICE_NAME = "project" 8 +const SERVICE_NAME = "gateway"
9 9
10 var LOG_LEVEL = "debug" 10 var LOG_LEVEL = "debug"
11 11
  1 +package constant
  2 +
  3 +import "os"
  4 +
  5 +var (
  6 + // kafka 地址
  7 + KAFKA_HOST = "192.168.0.250:9092,192.168.0.251:9092,192.168.0.252:9092"
  8 + // kafka topic log stash
  9 + TOPIC_LOG_STASH = "go_stash_dev"
  10 + // 是否启用日志收集 (本地不启用)
  11 + ENABLE_KAFKA_LOG = false
  12 +)
  13 +
  14 +func init() {
  15 + //if os.Getenv("KAFKA_HOST") != "" {
  16 + // POSTGRESQL_HOST = os.Getenv("KAFKA_HOST")
  17 + //}
  18 + //if os.Getenv("TOPIC_LOG_STASH") != "" {
  19 + // POSTGRESQL_PORT = os.Getenv("TOPIC_LOG_STASH")
  20 + //}
  21 + if os.Getenv("ENABLE_KAFKA_LOG") != "" {
  22 + ENABLE_KAFKA_LOG = true
  23 + }
  24 +}