作者 tangxuhui
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
... ...
apiVersion: v1
kind: Service
metadata:
name: allied-creation-gateway
namespace: mmm-suplus-test
labels:
k8s-app: allied-creation-gateway
spec:
ports:
- name: "http"
port: 80
targetPort: 8082
- name: "https"
port: 443
targetPort: 443
selector:
k8s-app: allied-creation-gateway
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: allied-creation-gateway
namespace: mmm-suplus-test
labels:
k8s-app: allied-creation-gateway
spec:
replicas: 1
template:
metadata:
labels:
k8s-app: allied-creation-gateway
spec:
affinity:
nodeAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- preference: {}
weight: 100
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- cn-hangzhou.i-bp1djh1xn7taumbue1ze
- cn-hangzhou.i-bp1djh1xn7taumbue1zd
- cn-hangzhou.i-bp1euf5u1ph9kbhtndhb
- cn-hangzhou.i-bp1hyp5oips9cdwxxgxy
containers:
- name: allied-creation-gateway
image: 192.168.0.243:5000/mmm/allied-creation-gateway:dev
imagePullPolicy: Always
ports:
- containerPort: 8082
- containerPort: 443
volumeMounts:
- mountPath: /opt/logs
name: accesslogs
env:
- name: POSTGRESQL_DB_NAME
valueFrom:
configMapKeyRef:
name: suplus-config
key: postgresqlalliedcreation.dbname
- name: POSTGRESQL_USER
valueFrom:
configMapKeyRef:
name: suplus-config
key: postgresql.user
- name: POSTGRESQL_PASSWORD
valueFrom:
configMapKeyRef:
name: suplus-config
key: postgresql.password
- name: POSTGRESQL_HOST
valueFrom:
configMapKeyRef:
name: suplus-config
key: postgresql.host
- name: POSTGRESQL_PORT
valueFrom:
configMapKeyRef:
name: suplus-config
key: postgresql.port
- name: REDIS_HOST
valueFrom:
configMapKeyRef:
name: suplus-config
key: redis.ip
- name: REDIS_PORT
valueFrom:
configMapKeyRef:
name: suplus-config
key: redis.port
- name: REDIS_AUTH
value: ""
- name: LOG_LEVEL
value: "debug"
- name: LOG_FRAMEWORK
value: "beego"
- name: LOG_TYPE
value: "file"
- name: ERROR_BASE_CODE
value: "1"
- name: ERROR_BASE_CODE_MULTIPLE
value: "1000"
- name: ENABLE_KAFKA_LOG
value: "false"
- name: HTTP_PORT
value: "8082"
- name: ALLIED_CREATION_USER_HOST
value: "https://allied-creation-user-test.fjmaimaimai.com"
- name: ALLIED_CREATION_COOPERATION_HOST
value: "https://allied-creation-cooperation-test.fjmaimaimai.com"
- name: ALLIED_CREATION_BASIC_HOST
value: "https://allied-creation-basic-test.fjmaimaimai.com"
- name: SMS_SERVE_HOST
value: "https://sms.fjmaimaimai.com:9897"
# - name: REDIS_HOST
# valueFrom:
# configMapKeyRef:
# name: suplus-config
# key: redis.ip
# - name: REDIS_PORT
# valueFrom:
# configMapKeyRef:
# name: suplus-config
# key: redis.port
volumes:
- name: accesslogs
emptyDir: {}
... ...
#!/bin/bash
export PATH=/root/local/bin:$PATH
kubectl -n mmm-suplus-test get pods | grep -q allied-creation-gateway
if [ "$?" == "1" ];then
kubectl create -f /tmp/test/allied-creation-gateway/allied-creation-gateway.yaml --record
kubectl -n mmm-suplus-test get svc | grep -q allied-creation-gateway
if [ "$?" == "0" ];then
echo "allied-creation-gateway service install success!"
else
echo "allied-creation-gateway service install fail!"
fi
kubectl -n mmm-suplus-test get pods | grep -q allied-creation-gateway
if [ "$?" == "0" ];then
echo "allied-creation-gateway deployment install success!"
else
echo "allied-creation-gateway deployment install fail!"
fi
else
kubectl delete -f /tmp/test/allied-creation-gateway/allied-creation-gateway.yaml
kubectl -n mmm-suplus-test get svc | grep -q allied-creation-gateway
while [ "$?" == "0" ]
do
kubectl -n mmm-suplus-test get svc | grep -q allied-creation-gateway
done
kubectl -n mmm-suplus-test get pods | grep -q allied-creation-gateway
while [ "$?" == "0" ]
do
kubectl -n mmm-suplus-test get pods | grep -q allied-creation-gateway
done
kubectl create -f /tmp/test/allied-creation-gateway/allied-creation-gateway.yaml --record
kubectl -n mmm-suplus-test get svc | grep -q allied-creation-gateway
if [ "$?" == "0" ];then
echo "allied-creation-gateway service update success!"
else
echo "allied-creation-gateway service update fail!"
fi
kubectl -n mmm-suplus-test get pods | grep -q allied-creation-gateway
if [ "$?" == "0" ];then
echo "allied-creation-gateway deployment update success!"
else
echo "allied-creation-gateway deployment update fail!"
fi
fi
\ No newline at end of file
... ...
... ... @@ -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=
... ...
... ... @@ -189,6 +189,7 @@ func (usersService *UsersService) CompanyUserList(companyUserListQuery *query.Co
Phone: "",
UserType: domain.UserTypeEmployee,
InOrgIds: companyUserListQuery.Operator.OrgIds,
PullRealTime: true,
})
if err != nil {
... ...
... ... @@ -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")
}
... ...