正在显示
4 个修改的文件
包含
35 行增加
和
1 行删除
@@ -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 | } |
pkg/constant/kafka.go
0 → 100644
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 | +} |
-
请 注册 或 登录 后发表评论