作者 tangxuhui
  1 +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
  2 +2021/09/07 01:40:09.439 [I] [hooks.go:101] generate router from comments
  3 +2021/09/07 01:40:09.440 [I] [???:0] http server Running on http://:8083
  4 +2021/09/07 01:40:12.667 [I] [filter.go:81] http请求 [
  5 + {
  6 + "framework": "beego",
  7 + "method": "GET",
  8 + "url": "/log"
  9 + }
  10 +]
  11 +2021/09/07 01:40:12.667 [D] [filter.go:81] http请求 [
  12 + {
  13 + "framework": "beego",
  14 + "method": "GET",
  15 + "url": "/log"
  16 + }
  17 +]
  18 +2021/09/07 01:40:12.669 [D] [filter.go:81] http响应 [
  19 + {
  20 + "framework": "beego",
  21 + "method": "GET",
  22 + "outputData": null,
  23 + "url": "/log"
  24 + }
  25 +]
  26 +2021/09/07 01:40:12.669 [D] [router.go:664] | ::1| 200 | 2.412278ms| match| GET  /log r:/log
  27 +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
  28 +2021/09/07 01:42:15.705 [I] [hooks.go:101] generate router from comments
  29 +2021/09/07 01:42:15.706 [I] [???:0] http server Running on http://:8083
@@ -91,14 +91,16 @@ spec: @@ -91,14 +91,16 @@ spec:
91 value: "" 91 value: ""
92 - name: LOG_LEVEL 92 - name: LOG_LEVEL
93 value: "debug" 93 value: "debug"
  94 + - name: LOG_FRAMEWORK
  95 + value: "beego"
94 - name: LOG_TYPE 96 - name: LOG_TYPE
95 - value: file 97 + value: "file"
96 - name: ERROR_BASE_CODE 98 - name: ERROR_BASE_CODE
97 value: "1" 99 value: "1"
98 - name: ERROR_BASE_CODE_MULTIPLE 100 - name: ERROR_BASE_CODE_MULTIPLE
99 value: "1000" 101 value: "1000"
100 - name: ENABLE_KAFKA_LOG 102 - name: ENABLE_KAFKA_LOG
101 - value: "true" 103 + value: "false"
102 - name: HTTP_PORT 104 - name: HTTP_PORT
103 value: "8082" 105 value: "8082"
104 - name: ALLIED_CREATION_USER_HOST 106 - name: ALLIED_CREATION_USER_HOST
  1 +apiVersion: v1
  2 +kind: Service
  3 +metadata:
  4 + name: allied-creation-gateway
  5 + namespace: mmm-suplus-test
  6 + labels:
  7 + k8s-app: allied-creation-gateway
  8 +spec:
  9 + ports:
  10 + - name: "http"
  11 + port: 80
  12 + targetPort: 8082
  13 + - name: "https"
  14 + port: 443
  15 + targetPort: 443
  16 + selector:
  17 + k8s-app: allied-creation-gateway
  18 +---
  19 +apiVersion: extensions/v1beta1
  20 +kind: Deployment
  21 +metadata:
  22 + name: allied-creation-gateway
  23 + namespace: mmm-suplus-test
  24 + labels:
  25 + k8s-app: allied-creation-gateway
  26 +spec:
  27 + replicas: 1
  28 + template:
  29 + metadata:
  30 + labels:
  31 + k8s-app: allied-creation-gateway
  32 + spec:
  33 + affinity:
  34 + nodeAffinity:
  35 + preferredDuringSchedulingIgnoredDuringExecution:
  36 + - preference: {}
  37 + weight: 100
  38 + requiredDuringSchedulingIgnoredDuringExecution:
  39 + nodeSelectorTerms:
  40 + - matchExpressions:
  41 + - key: kubernetes.io/hostname
  42 + operator: In
  43 + values:
  44 + - cn-hangzhou.i-bp1djh1xn7taumbue1ze
  45 + - cn-hangzhou.i-bp1djh1xn7taumbue1zd
  46 + - cn-hangzhou.i-bp1euf5u1ph9kbhtndhb
  47 + - cn-hangzhou.i-bp1hyp5oips9cdwxxgxy
  48 + containers:
  49 + - name: allied-creation-gateway
  50 + image: 192.168.0.243:5000/mmm/allied-creation-gateway:dev
  51 + imagePullPolicy: Always
  52 + ports:
  53 + - containerPort: 8082
  54 + - containerPort: 443
  55 + volumeMounts:
  56 + - mountPath: /opt/logs
  57 + name: accesslogs
  58 + env:
  59 + - name: POSTGRESQL_DB_NAME
  60 + valueFrom:
  61 + configMapKeyRef:
  62 + name: suplus-config
  63 + key: postgresqlalliedcreation.dbname
  64 + - name: POSTGRESQL_USER
  65 + valueFrom:
  66 + configMapKeyRef:
  67 + name: suplus-config
  68 + key: postgresql.user
  69 + - name: POSTGRESQL_PASSWORD
  70 + valueFrom:
  71 + configMapKeyRef:
  72 + name: suplus-config
  73 + key: postgresql.password
  74 + - name: POSTGRESQL_HOST
  75 + valueFrom:
  76 + configMapKeyRef:
  77 + name: suplus-config
  78 + key: postgresql.host
  79 + - name: POSTGRESQL_PORT
  80 + valueFrom:
  81 + configMapKeyRef:
  82 + name: suplus-config
  83 + key: postgresql.port
  84 + - name: REDIS_HOST
  85 + valueFrom:
  86 + configMapKeyRef:
  87 + name: suplus-config
  88 + key: redis.ip
  89 + - name: REDIS_PORT
  90 + valueFrom:
  91 + configMapKeyRef:
  92 + name: suplus-config
  93 + key: redis.port
  94 + - name: REDIS_AUTH
  95 + value: ""
  96 + - name: LOG_LEVEL
  97 + value: "debug"
  98 + - name: LOG_FRAMEWORK
  99 + value: "beego"
  100 + - name: LOG_TYPE
  101 + value: "file"
  102 + - name: ERROR_BASE_CODE
  103 + value: "1"
  104 + - name: ERROR_BASE_CODE_MULTIPLE
  105 + value: "1000"
  106 + - name: ENABLE_KAFKA_LOG
  107 + value: "false"
  108 + - name: HTTP_PORT
  109 + value: "8082"
  110 + - name: ALLIED_CREATION_USER_HOST
  111 + value: "https://allied-creation-user-test.fjmaimaimai.com"
  112 + - name: ALLIED_CREATION_COOPERATION_HOST
  113 + value: "https://allied-creation-cooperation-test.fjmaimaimai.com"
  114 + - name: ALLIED_CREATION_BASIC_HOST
  115 + value: "https://allied-creation-basic-test.fjmaimaimai.com"
  116 + - name: SMS_SERVE_HOST
  117 + value: "https://sms.fjmaimaimai.com:9897"
  118 + # - name: REDIS_HOST
  119 + # valueFrom:
  120 + # configMapKeyRef:
  121 + # name: suplus-config
  122 + # key: redis.ip
  123 + # - name: REDIS_PORT
  124 + # valueFrom:
  125 + # configMapKeyRef:
  126 + # name: suplus-config
  127 + # key: redis.port
  128 + volumes:
  129 + - name: accesslogs
  130 + emptyDir: {}
  1 +#!/bin/bash
  2 +export PATH=/root/local/bin:$PATH
  3 +kubectl -n mmm-suplus-test get pods | grep -q allied-creation-gateway
  4 +if [ "$?" == "1" ];then
  5 + kubectl create -f /tmp/test/allied-creation-gateway/allied-creation-gateway.yaml --record
  6 + kubectl -n mmm-suplus-test get svc | grep -q allied-creation-gateway
  7 + if [ "$?" == "0" ];then
  8 + echo "allied-creation-gateway service install success!"
  9 + else
  10 + echo "allied-creation-gateway service install fail!"
  11 + fi
  12 + kubectl -n mmm-suplus-test get pods | grep -q allied-creation-gateway
  13 + if [ "$?" == "0" ];then
  14 + echo "allied-creation-gateway deployment install success!"
  15 + else
  16 + echo "allied-creation-gateway deployment install fail!"
  17 + fi
  18 +else
  19 + kubectl delete -f /tmp/test/allied-creation-gateway/allied-creation-gateway.yaml
  20 + kubectl -n mmm-suplus-test get svc | grep -q allied-creation-gateway
  21 + while [ "$?" == "0" ]
  22 + do
  23 + kubectl -n mmm-suplus-test get svc | grep -q allied-creation-gateway
  24 + done
  25 + kubectl -n mmm-suplus-test get pods | grep -q allied-creation-gateway
  26 + while [ "$?" == "0" ]
  27 + do
  28 + kubectl -n mmm-suplus-test get pods | grep -q allied-creation-gateway
  29 + done
  30 + kubectl create -f /tmp/test/allied-creation-gateway/allied-creation-gateway.yaml --record
  31 + kubectl -n mmm-suplus-test get svc | grep -q allied-creation-gateway
  32 + if [ "$?" == "0" ];then
  33 + echo "allied-creation-gateway service update success!"
  34 + else
  35 + echo "allied-creation-gateway service update fail!"
  36 + fi
  37 + kubectl -n mmm-suplus-test get pods | grep -q allied-creation-gateway
  38 + if [ "$?" == "0" ];then
  39 + echo "allied-creation-gateway deployment update success!"
  40 + else
  41 + echo "allied-creation-gateway deployment update fail!"
  42 + fi
  43 +fi
@@ -48,6 +48,7 @@ github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1 @@ -48,6 +48,7 @@ github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1
48 github.com/eapache/queue v1.1.0 h1:YOEu7KNc61ntiQlcEeUIoDTJ2o8mQznoNvUhiigpIqc= 48 github.com/eapache/queue v1.1.0 h1:YOEu7KNc61ntiQlcEeUIoDTJ2o8mQznoNvUhiigpIqc=
49 github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= 49 github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
50 github.com/edsrzf/mmap-go v0.0.0-20170320065105-0bce6a688712/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M= 50 github.com/edsrzf/mmap-go v0.0.0-20170320065105-0bce6a688712/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M=
  51 +github.com/elastic/go-elasticsearch/v6 v6.8.5 h1:U2HtkBseC1FNBmDr0TR2tKltL6FxoY+niDAlj5M8TK8=
51 github.com/elastic/go-elasticsearch/v6 v6.8.5/go.mod h1:UwaDJsD3rWLM5rKNFzv9hgox93HoX8utj1kxD9aFUcI= 52 github.com/elastic/go-elasticsearch/v6 v6.8.5/go.mod h1:UwaDJsD3rWLM5rKNFzv9hgox93HoX8utj1kxD9aFUcI=
52 github.com/elazarl/go-bindata-assetfs v1.0.0 h1:G/bYguwHIzWq9ZoyUQqrjTmJbbYn3j3CKKpKinvZLFk= 53 github.com/elazarl/go-bindata-assetfs v1.0.0 h1:G/bYguwHIzWq9ZoyUQqrjTmJbbYn3j3CKKpKinvZLFk=
53 github.com/elazarl/go-bindata-assetfs v1.0.0/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4= 54 github.com/elazarl/go-bindata-assetfs v1.0.0/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4=
@@ -189,6 +189,7 @@ func (usersService *UsersService) CompanyUserList(companyUserListQuery *query.Co @@ -189,6 +189,7 @@ func (usersService *UsersService) CompanyUserList(companyUserListQuery *query.Co
189 Phone: "", 189 Phone: "",
190 UserType: domain.UserTypeEmployee, 190 UserType: domain.UserTypeEmployee,
191 InOrgIds: companyUserListQuery.Operator.OrgIds, 191 InOrgIds: companyUserListQuery.Operator.OrgIds,
  192 + PullRealTime: true,
192 }) 193 })
193 194
194 if err != nil { 195 if err != nil {
@@ -8,8 +8,11 @@ import ( @@ -8,8 +8,11 @@ import (
8 const SERVICE_NAME = "allied-creation-gateway" 8 const SERVICE_NAME = "allied-creation-gateway"
9 9
10 var LOG_LEVEL = "debug" 10 var LOG_LEVEL = "debug"
11 -var LOG_TYPE = "console" 11 +var LOG_TYPE = "console"// file, console, es
  12 +var LOG_FRAMEWORK = "beego" // beego logrus
12 var LOG_FILE = "app.log" 13 var LOG_FILE = "app.log"
  14 +var LOG_PREFIX = "[allied-creation-gateway]"
  15 +
13 var HTTP_PORT int = 8083 16 var HTTP_PORT int = 8083
14 17
15 //天联共创基础模块 18 //天联共创基础模块
@@ -19,6 +19,10 @@ func init() { @@ -19,6 +19,10 @@ func init() {
19 // POSTGRESQL_PORT = os.Getenv("TOPIC_LOG_STASH") 19 // POSTGRESQL_PORT = os.Getenv("TOPIC_LOG_STASH")
20 //} 20 //}
21 if os.Getenv("ENABLE_KAFKA_LOG") != "" { 21 if os.Getenv("ENABLE_KAFKA_LOG") != "" {
22 - ENABLE_KAFKA_LOG = true 22 + if os.Getenv("ENABLE_KAFKA_LOG") == "true" {
  23 + ENABLE_KAFKA_LOG = true
  24 + } else if os.Getenv("ENABLE_KAFKA_LOG") == "false" {
  25 + ENABLE_KAFKA_LOG = false
  26 + }
23 } 27 }
24 } 28 }
@@ -4,12 +4,11 @@ import ( @@ -4,12 +4,11 @@ import (
4 "bytes" 4 "bytes"
5 "encoding/json" 5 "encoding/json"
6 "fmt" 6 "fmt"
7 - "io"  
8 - "strconv"  
9 -  
10 "github.com/beego/beego/v2/core/logs" 7 "github.com/beego/beego/v2/core/logs"
11 - "github.com/linmadan/egglib-go/log" 8 + _ "github.com/beego/beego/v2/core/logs/es"
12 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/constant" 9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/constant"
  10 + "io"
  11 + "strconv"
13 ) 12 )
14 13
15 type LoggerConfig struct { 14 type LoggerConfig struct {
@@ -26,35 +25,7 @@ type BeegoLog struct { @@ -26,35 +25,7 @@ type BeegoLog struct {
26 beeLogger *logs.BeeLogger 25 beeLogger *logs.BeeLogger
27 } 26 }
28 27
29 -var _ log.Logger = &BeegoLog{}  
30 -  
31 -func NewBeegoLog(conf LoggerConfig) *BeegoLog {  
32 - logger := logs.GetBeeLogger()  
33 - logger.SetLevel(conf.Level)  
34 - if constant.LOG_TYPE == "file" { // 日志存储到文件  
35 - confByte, _ := json.Marshal(conf)  
36 - err := logger.SetLogger(logs.AdapterFile, string(confByte))  
37 - if err != nil {  
38 - fmt.Println(err.Error())  
39 - return nil  
40 - }  
41 - } else { // 日志输出到控制台  
42 - err := logger.SetLogger(logs.AdapterConsole, `{"level":7,"color":true}`)  
43 - if err != nil {  
44 - fmt.Println(err.Error())  
45 - return nil  
46 - }  
47 - }  
48 - logger.SetPrefix(constant.SERVICE_NAME)  
49 - logger.EnableFuncCallDepth(true)  
50 - logger.SetLogFuncCallDepth(5)  
51 - return &BeegoLog{  
52 - beeLogger: logger,  
53 - }  
54 -}  
55 -  
56 func (logger *BeegoLog) AddHook(write io.Writer) { 28 func (logger *BeegoLog) AddHook(write io.Writer) {
57 -  
58 } 29 }
59 30
60 func (logger *BeegoLog) SetServiceName(serviceName string) { 31 func (logger *BeegoLog) SetServiceName(serviceName string) {
@@ -118,3 +89,35 @@ func (logger *BeegoLog) Fatal(msg string, appends ...map[string]interface{}) { @@ -118,3 +89,35 @@ func (logger *BeegoLog) Fatal(msg string, appends ...map[string]interface{}) {
118 func (logger *BeegoLog) Panic(msg string, appends ...map[string]interface{}) { 89 func (logger *BeegoLog) Panic(msg string, appends ...map[string]interface{}) {
119 logs.Error(msg, appends) 90 logs.Error(msg, appends)
120 } 91 }
  92 +
  93 +func NewBeegoLog(conf LoggerConfig) *BeegoLog {
  94 + logger := logs.GetBeeLogger()
  95 + logger.SetLevel(conf.Level)
  96 + if constant.LOG_TYPE == "file" { // 日志存储到文件
  97 + confByte, _ := json.Marshal(conf)
  98 + err := logger.SetLogger(logs.AdapterFile, string(confByte))
  99 + if err != nil {
  100 + fmt.Println(err.Error())
  101 + return nil
  102 + }
  103 + } else if constant.LOG_TYPE == "es" { // 日志存储到ES
  104 + err := logger.SetLogger(logs.AdapterEs, `{"dsn":"http://192.168.100.222:9200/","level":7}`)
  105 + if err != nil {
  106 + fmt.Println(err.Error())
  107 + return nil
  108 + }
  109 + } else { // 日志输出到控制台
  110 + err := logger.SetLogger(logs.AdapterConsole, `{"level":7,"color":true}`)
  111 + if err != nil {
  112 + fmt.Println(err.Error())
  113 + return nil
  114 + }
  115 + }
  116 + logger.SetPrefix(constant.LOG_PREFIX)
  117 + logger.EnableFuncCallDepth(true)
  118 + logger.SetLogFuncCallDepth(5)
  119 + logger.SetPrefix(constant.LOG_PREFIX)
  120 + return &BeegoLog{
  121 + beeLogger: logger,
  122 + }
  123 +}
1 package log 1 package log
2 2
3 import ( 3 import (
  4 + "github.com/linmadan/egglib-go/log/logrus"
4 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/constant" 5 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/constant"
5 6
6 "github.com/linmadan/egglib-go/log" 7 "github.com/linmadan/egglib-go/log"
@@ -9,13 +10,15 @@ import ( @@ -9,13 +10,15 @@ import (
9 var Logger log.Logger 10 var Logger log.Logger
10 11
11 func init() { 12 func init() {
12 - // Logger = logrus.NewLogrusLogger()  
13 - // Logger.SetServiceName(constant.SERVICE_NAME)  
14 - // Logger.SetLevel(constant.LOG_LEVEL)  
15 - // //  
16 - Logger = NewBeegoLog(LoggerConfig{  
17 - Filename: constant.LOG_FILE,  
18 - Level: 7,  
19 - MaxSize: 1024 * 1024 * 2,  
20 - }) 13 + if constant.LOG_FRAMEWORK == "beego" {
  14 + Logger = NewBeegoLog(LoggerConfig{
  15 + Filename: constant.LOG_FILE,
  16 + Level: 7,
  17 + MaxSize: 1024 * 1024 * 2,
  18 + })
  19 + } else if constant.LOG_FRAMEWORK == "logrus" {
  20 + Logger = logrus.NewLogrusLogger()
  21 + Logger.SetServiceName(constant.SERVICE_NAME)
  22 + Logger.SetLevel(constant.LOG_LEVEL)
  23 + }
21 } 24 }
  1 +package controllers
  2 +
  3 +import "io/ioutil"
  4 +
  5 +type LoggerController struct {
  6 + BaseController
  7 +}
  8 +
  9 +func (controller LoggerController) Index() {
  10 + bytes, _ := ioutil.ReadFile("./app.log")
  11 + controller.Ctx.WriteString(string(bytes))
  12 +}
  1 +package routers
  2 +
  3 +import (
  4 + "github.com/beego/beego/v2/server/web"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/controllers"
  6 +)
  7 +
  8 +func init() {
  9 + web.Router("/log", &controllers.LoggerController{}, "Get:Index")
  10 +}