Merge branch 'dev' of http://gitlab.fjmaimaimai.com/allied-creation/allied-creat…
…ion-cooperation into dev
正在显示
13 个修改的文件
包含
57 行增加
和
167 行删除
| @@ -54,6 +54,8 @@ spec: | @@ -54,6 +54,8 @@ spec: | ||
| 54 | env: | 54 | env: |
| 55 | - name: LOG_LEVEL | 55 | - name: LOG_LEVEL |
| 56 | value: "debug" | 56 | value: "debug" |
| 57 | + - name: LOG_FRAMEWORK | ||
| 58 | + value: "beego" | ||
| 57 | - name: LOG_TYPE | 59 | - name: LOG_TYPE |
| 58 | value: "file" | 60 | value: "file" |
| 59 | - name: ERROR_BASE_CODE | 61 | - name: ERROR_BASE_CODE |
| @@ -61,7 +63,7 @@ spec: | @@ -61,7 +63,7 @@ spec: | ||
| 61 | - name: ERROR_BASE_CODE_MULTIPLE | 63 | - name: ERROR_BASE_CODE_MULTIPLE |
| 62 | value: "1000" | 64 | value: "1000" |
| 63 | - name: ENABLE_KAFKA_LOG | 65 | - name: ENABLE_KAFKA_LOG |
| 64 | - value: "true" | 66 | + value: "false" |
| 65 | - name: USER_MODULE_HOST | 67 | - name: USER_MODULE_HOST |
| 66 | value: "http://allied-creation-user-dev.fjmaimaimai.com" | 68 | value: "http://allied-creation-user-dev.fjmaimaimai.com" |
| 67 | - name: REDIS_HOST | 69 | - name: REDIS_HOST |
| 1 | package main | 1 | package main |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | + "fmt" | ||
| 4 | "github.com/beego/beego/v2/server/web" | 5 | "github.com/beego/beego/v2/server/web" |
| 6 | + "github.com/linmadan/egglib-go/log/logrus" | ||
| 7 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/constant" | ||
| 5 | _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/constant" | 8 | _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/constant" |
| 6 | _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg" | 9 | _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg" |
| 10 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log" | ||
| 7 | _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log" | 11 | _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log" |
| 8 | _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/port/beego" | 12 | _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/port/beego" |
| 9 | ) | 13 | ) |
| 10 | 14 | ||
| 11 | func main() { | 15 | func main() { |
| 12 | // web主服务 | 16 | // web主服务 |
| 13 | - //if constant.ENABLE_KAFKA_LOG { | ||
| 14 | - // w, _ := logrus.NewKafkaWriter(constant.KAFKA_HOSTS, constant.TOPIC_LOG_STASH, false) | ||
| 15 | - // log.Logger.AddHook(w) | ||
| 16 | - //} | 17 | + if constant.ENABLE_KAFKA_LOG { |
| 18 | + w, err := logrus.NewKafkaWriter(constant.KAFKA_HOSTS, constant.TOPIC_LOG_STASH, false) | ||
| 19 | + if err != nil { | ||
| 20 | + log.Logger.Error(err.Error()) | ||
| 21 | + } | ||
| 22 | + log.Logger.AddHook(w) | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + fmt.Printf("Server running at:%d\n", web.BConfig.Listen.HTTPPort) | ||
| 26 | + | ||
| 17 | web.Run() | 27 | web.Run() |
| 18 | } | 28 | } |
| @@ -18,6 +18,10 @@ type CooperationContractByUndertakerDto struct { | @@ -18,6 +18,10 @@ type CooperationContractByUndertakerDto struct { | ||
| 18 | CooperationContractNumber string `json:"cooperationContractNumber"` | 18 | CooperationContractNumber string `json:"cooperationContractNumber"` |
| 19 | // 项目合约名称 | 19 | // 项目合约名称 |
| 20 | CooperationContractName string `json:"cooperationContractName"` | 20 | CooperationContractName string `json:"cooperationContractName"` |
| 21 | + // 项目合约状态 | ||
| 22 | + CooperationContractStatus int32 `json:"cooperationContractStatus"` | ||
| 23 | + // 共创描述 | ||
| 24 | + CooperationContractDescription string `json:"cooperationContractDescription"` | ||
| 21 | // 合同附件 | 25 | // 合同附件 |
| 22 | Attachment []*domain.Attachment `json:"attachment"` | 26 | Attachment []*domain.Attachment `json:"attachment"` |
| 23 | // 发起人姓名 | 27 | // 发起人姓名 |
| @@ -37,6 +41,8 @@ func (dto *CooperationContractByUndertakerDto) LoadDto(contractByUndertaker *mod | @@ -37,6 +41,8 @@ func (dto *CooperationContractByUndertakerDto) LoadDto(contractByUndertaker *mod | ||
| 37 | dto.UndertakerPhone = contractByUndertaker.UndertakerPhone | 41 | dto.UndertakerPhone = contractByUndertaker.UndertakerPhone |
| 38 | dto.CooperationContractNumber = contractByUndertaker.CooperationContractNumber | 42 | dto.CooperationContractNumber = contractByUndertaker.CooperationContractNumber |
| 39 | dto.CooperationContractName = contractByUndertaker.CooperationContractName | 43 | dto.CooperationContractName = contractByUndertaker.CooperationContractName |
| 44 | + dto.CooperationContractStatus = contractByUndertaker.ContractStatus | ||
| 45 | + dto.CooperationContractDescription = contractByUndertaker.CooperationContractDescription | ||
| 40 | dto.Attachment = contractByUndertaker.ContractAttachment | 46 | dto.Attachment = contractByUndertaker.ContractAttachment |
| 41 | dto.SponsorName = contractByUndertaker.CooperationContractSponsor.UserName | 47 | dto.SponsorName = contractByUndertaker.CooperationContractSponsor.UserName |
| 42 | if contractByUndertaker.Department != nil { | 48 | if contractByUndertaker.Department != nil { |
| @@ -836,7 +836,7 @@ func (cooperationContractService *CooperationContractService) SearchCooperationC | @@ -836,7 +836,7 @@ func (cooperationContractService *CooperationContractService) SearchCooperationC | ||
| 836 | if count, cooperationContractByUndertakers, err := cooperationContractDao.SearchCooperationContractByUndertaker(tool_funs.SimpleStructToMap(searchCooperationContractByUndertakerQuery)); err != nil { | 836 | if count, cooperationContractByUndertakers, err := cooperationContractDao.SearchCooperationContractByUndertaker(tool_funs.SimpleStructToMap(searchCooperationContractByUndertakerQuery)); err != nil { |
| 837 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 837 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 838 | } else { | 838 | } else { |
| 839 | - cooperationContractByUndertakerDtos := []*dto.CooperationContractByUndertakerDto{} | 839 | + cooperationContractByUndertakerDtos := make([]*dto.CooperationContractByUndertakerDto, 0) |
| 840 | for _, cooperationContractByUndertaker := range cooperationContractByUndertakers { | 840 | for _, cooperationContractByUndertaker := range cooperationContractByUndertakers { |
| 841 | cooperationContractByUndertakerDto := &dto.CooperationContractByUndertakerDto{} | 841 | cooperationContractByUndertakerDto := &dto.CooperationContractByUndertakerDto{} |
| 842 | if err := cooperationContractByUndertakerDto.LoadDto(cooperationContractByUndertaker); err != nil { | 842 | if err := cooperationContractByUndertakerDto.LoadDto(cooperationContractByUndertaker); err != nil { |
| @@ -130,8 +130,9 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD | @@ -130,8 +130,9 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD | ||
| 130 | } | 130 | } |
| 131 | 131 | ||
| 132 | // 查找合约 | 132 | // 查找合约 |
| 133 | - var cooperationContractsMap map[string]*domain.CooperationContract | 133 | + cooperationContractsMap := make(map[string]*domain.CooperationContract) |
| 134 | if count, cooperationContracts, err := cooperationContractRepository.Find(map[string]interface{}{ | 134 | if count, cooperationContracts, err := cooperationContractRepository.Find(map[string]interface{}{ |
| 135 | + "offsetLimit": false, | ||
| 135 | "companyId": createDividendsOrderCommand.CompanyId, | 136 | "companyId": createDividendsOrderCommand.CompanyId, |
| 136 | "orgId": createDividendsOrderCommand.OrgId, | 137 | "orgId": createDividendsOrderCommand.OrgId, |
| 137 | }); err != nil { | 138 | }); err != nil { |
| @@ -317,7 +318,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD | @@ -317,7 +318,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD | ||
| 317 | } | 318 | } |
| 318 | 319 | ||
| 319 | // 查找合约 | 320 | // 查找合约 |
| 320 | - var cooperationContractsMap map[string]*domain.CooperationContract | 321 | + cooperationContractsMap := make(map[string]*domain.CooperationContract) |
| 321 | countContracts, cooperationContracts, err := cooperationContractRepository.Find(map[string]interface{}{ | 322 | countContracts, cooperationContracts, err := cooperationContractRepository.Find(map[string]interface{}{ |
| 322 | "offsetLimit": false, | 323 | "offsetLimit": false, |
| 323 | "companyId": importDividendsOrderCommand.CompanyId, | 324 | "companyId": importDividendsOrderCommand.CompanyId, |
| @@ -143,8 +143,9 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) CreateDivide | @@ -143,8 +143,9 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) CreateDivide | ||
| 143 | } | 143 | } |
| 144 | 144 | ||
| 145 | // 查找合约 | 145 | // 查找合约 |
| 146 | - var cooperationContractsMap map[string]*domain.CooperationContract | 146 | + cooperationContractsMap := make(map[string]*domain.CooperationContract) |
| 147 | if count, cooperationContracts, err := cooperationContractRepository.Find(map[string]interface{}{ | 147 | if count, cooperationContracts, err := cooperationContractRepository.Find(map[string]interface{}{ |
| 148 | + "offsetLimit": false, | ||
| 148 | "companyId": createDividendsReturnedOrderCommand.CompanyId, | 149 | "companyId": createDividendsReturnedOrderCommand.CompanyId, |
| 149 | "orgId": createDividendsReturnedOrderCommand.OrgId, | 150 | "orgId": createDividendsReturnedOrderCommand.OrgId, |
| 150 | }); err != nil { | 151 | }); err != nil { |
| @@ -366,7 +367,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide | @@ -366,7 +367,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide | ||
| 366 | } | 367 | } |
| 367 | 368 | ||
| 368 | // 查找合约 | 369 | // 查找合约 |
| 369 | - var cooperationContractsMap map[string]*domain.CooperationContract | 370 | + cooperationContractsMap := make(map[string]*domain.CooperationContract) |
| 370 | countContracts, cooperationContracts, err := cooperationContractRepository.Find(map[string]interface{}{ | 371 | countContracts, cooperationContracts, err := cooperationContractRepository.Find(map[string]interface{}{ |
| 371 | "offsetLimit": false, | 372 | "offsetLimit": false, |
| 372 | "companyId": importDividendsReturnedOrderCommand.CompanyId, | 373 | "companyId": importDividendsReturnedOrderCommand.CompanyId, |
| @@ -6,6 +6,7 @@ const SERVICE_NAME = "allied-creation-cooperation" | @@ -6,6 +6,7 @@ const SERVICE_NAME = "allied-creation-cooperation" | ||
| 6 | 6 | ||
| 7 | // LOG_TYPE 日志相关设置 | 7 | // LOG_TYPE 日志相关设置 |
| 8 | var LOG_TYPE = "terminal" // file, terminal, es | 8 | var LOG_TYPE = "terminal" // file, terminal, es |
| 9 | +var LOG_FRAMEWORK = "beego" // beego logrus | ||
| 9 | var LOG_LEVEL = "debug" | 10 | var LOG_LEVEL = "debug" |
| 10 | var LOG_FILE = "app.log" | 11 | var LOG_FILE = "app.log" |
| 11 | var LOG_PREFIX = "[allied-creation-cooperation]" | 12 | var LOG_PREFIX = "[allied-creation-cooperation]" |
| @@ -23,6 +24,9 @@ func init() { | @@ -23,6 +24,9 @@ func init() { | ||
| 23 | if os.Getenv("LOG_LEVEL") != "" { | 24 | if os.Getenv("LOG_LEVEL") != "" { |
| 24 | LOG_LEVEL = os.Getenv("LOG_LEVEL") | 25 | LOG_LEVEL = os.Getenv("LOG_LEVEL") |
| 25 | } | 26 | } |
| 27 | + if os.Getenv("LOG_FRAMEWORK") != "" { | ||
| 28 | + LOG_FRAMEWORK = os.Getenv("LOG_FRAMEWORK") | ||
| 29 | + } | ||
| 26 | if os.Getenv("LOG_FILE") != "" { | 30 | if os.Getenv("LOG_FILE") != "" { |
| 27 | LOG_FILE = os.Getenv("LOG_FILE") | 31 | LOG_FILE = os.Getenv("LOG_FILE") |
| 28 | } | 32 | } |
| @@ -2,23 +2,27 @@ package constant | @@ -2,23 +2,27 @@ package constant | ||
| 2 | 2 | ||
| 3 | import "os" | 3 | import "os" |
| 4 | 4 | ||
| 5 | -// kafka 地址 | 5 | +// KAFKA_HOSTS kafka 地址 |
| 6 | var KAFKA_HOSTS = "192.168.0.250:9092,192.168.0.251:9092,192.168.0.252:9092" | 6 | var KAFKA_HOSTS = "192.168.0.250:9092,192.168.0.251:9092,192.168.0.252:9092" |
| 7 | 7 | ||
| 8 | -// kafka topic log stash | 8 | +// TOPIC_LOG_STASH kafka topic log stash |
| 9 | var TOPIC_LOG_STASH = "go_stash_dev" | 9 | var TOPIC_LOG_STASH = "go_stash_dev" |
| 10 | 10 | ||
| 11 | -// 是否启用日志收集 (本地不启用) | 11 | +// ENABLE_KAFKA_LOG 是否启用日志收集 (本地不启用) |
| 12 | var ENABLE_KAFKA_LOG = false | 12 | var ENABLE_KAFKA_LOG = false |
| 13 | 13 | ||
| 14 | func init() { | 14 | func init() { |
| 15 | - //if os.Getenv("KAFKA_HOSTS") != "" { | ||
| 16 | - // KAFKA_HOSTS = os.Getenv("KAFKA_HOSTS") | ||
| 17 | - //} | ||
| 18 | - //if os.Getenv("TOPIC_LOG_STASH") != "" { | ||
| 19 | - // POSTGRESQL_PORT = os.Getenv("TOPIC_LOG_STASH") | ||
| 20 | - //} | 15 | + if os.Getenv("KAFKA_HOSTS") != "" { |
| 16 | + KAFKA_HOSTS = os.Getenv("KAFKA_HOSTS") | ||
| 17 | + } | ||
| 18 | + if os.Getenv("TOPIC_LOG_STASH") != "" { | ||
| 19 | + POSTGRESQL_PORT = os.Getenv("TOPIC_LOG_STASH") | ||
| 20 | + } | ||
| 21 | if os.Getenv("ENABLE_KAFKA_LOG") != "" { | 21 | if os.Getenv("ENABLE_KAFKA_LOG") != "" { |
| 22 | + if os.Getenv("ENABLE_KAFKA_LOG") == "true" { | ||
| 22 | 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 | } |
| @@ -25,7 +25,7 @@ type CooperationContractByUndertaker struct { | @@ -25,7 +25,7 @@ type CooperationContractByUndertaker struct { | ||
| 25 | Department *domain.Department `comment:"共创合约发起部门"` | 25 | Department *domain.Department `comment:"共创合约发起部门"` |
| 26 | // 组织机构 | 26 | // 组织机构 |
| 27 | Org *domain.Org `comment:"组织机构"` | 27 | Org *domain.Org `comment:"组织机构"` |
| 28 | - // 共创合约状态 | 28 | + // 共创合约状态 1正常,2关闭 |
| 29 | ContractStatus int32 `comment:"共创合约状态"` | 29 | ContractStatus int32 `comment:"共创合约状态"` |
| 30 | // 共创模式名称 | 30 | // 共创模式名称 |
| 31 | CooperationModeName string `comment:"共创合约名称"` | 31 | CooperationModeName string `comment:"共创合约名称"` |
| @@ -248,9 +248,11 @@ func (repository *CooperationApplicationRepository) Find(queryOptions map[string | @@ -248,9 +248,11 @@ func (repository *CooperationApplicationRepository) Find(queryOptions map[string | ||
| 248 | if userBaseId, ok := queryOptions["userBaseId"]; ok && userBaseId.(int64) != 0 { | 248 | if userBaseId, ok := queryOptions["userBaseId"]; ok && userBaseId.(int64) != 0 { |
| 249 | query.Where(`(cooperation_application.cooperation_application_applicant->>'userBaseId' ='?')`, userBaseId) | 249 | query.Where(`(cooperation_application.cooperation_application_applicant->>'userBaseId' ='?')`, userBaseId) |
| 250 | } | 250 | } |
| 251 | - if isCanceled, ok := queryOptions["isCanceled"]; ok && isCanceled.(int32) != 3 { | 251 | + if isCanceled, ok := queryOptions["isCanceled"]; ok && isCanceled.(int32) != 0 { |
| 252 | + if isCanceled.(int32) != 3 { | ||
| 252 | query.Where("is_canceled = ?", isCanceled) | 253 | query.Where("is_canceled = ?", isCanceled) |
| 253 | } | 254 | } |
| 255 | + } | ||
| 254 | if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 { | 256 | if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 { |
| 255 | query.Where("company->>'companyId' = '?'", companyId) | 257 | query.Where("company->>'companyId' = '?'", companyId) |
| 256 | } | 258 | } |
| @@ -26,7 +26,6 @@ type BeegoLog struct { | @@ -26,7 +26,6 @@ type BeegoLog struct { | ||
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | func (logger *BeegoLog) AddHook(write io.Writer) { | 28 | func (logger *BeegoLog) AddHook(write io.Writer) { |
| 29 | - panic("implement me") | ||
| 30 | } | 29 | } |
| 31 | 30 | ||
| 32 | func (logger *BeegoLog) SetServiceName(serviceName string) { | 31 | func (logger *BeegoLog) SetServiceName(serviceName string) { |
| @@ -2,25 +2,22 @@ package log | @@ -2,25 +2,22 @@ package log | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "github.com/linmadan/egglib-go/log" | 4 | "github.com/linmadan/egglib-go/log" |
| 5 | + "github.com/linmadan/egglib-go/log/logrus" | ||
| 5 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/constant" | 6 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/constant" |
| 6 | ) | 7 | ) |
| 7 | 8 | ||
| 8 | var Logger log.Logger | 9 | var Logger log.Logger |
| 9 | 10 | ||
| 10 | func init() { | 11 | func init() { |
| 11 | - //Logger = logrus.NewLogrusLogger() | ||
| 12 | - //Logger.SetServiceName(constant.SERVICE_NAME) | ||
| 13 | - //Logger.SetLevel(constant.LOG_LEVEL) | ||
| 14 | - | ||
| 15 | - if constant.LOG_TYPE == "es" { | ||
| 16 | - Logger = NewServerLog() | ||
| 17 | - Logger.SetServiceName(constant.SERVICE_NAME) | ||
| 18 | - Logger.SetLevel(constant.LOG_LEVEL) | ||
| 19 | - } else { | 12 | + if constant.LOG_FRAMEWORK == "beego" { |
| 20 | Logger = NewBeegoLog(LoggerConfig{ | 13 | Logger = NewBeegoLog(LoggerConfig{ |
| 21 | Filename: constant.LOG_FILE, | 14 | Filename: constant.LOG_FILE, |
| 22 | Level: 7, | 15 | Level: 7, |
| 23 | MaxSize: 1024 * 1024 * 2, | 16 | MaxSize: 1024 * 1024 * 2, |
| 24 | }) | 17 | }) |
| 18 | + } else if constant.LOG_FRAMEWORK == "logrus" { | ||
| 19 | + Logger = logrus.NewLogrusLogger() | ||
| 20 | + Logger.SetServiceName(constant.SERVICE_NAME) | ||
| 21 | + Logger.SetLevel(constant.LOG_LEVEL) | ||
| 25 | } | 22 | } |
| 26 | } | 23 | } |
pkg/log/logrus.go
已删除
100644 → 0
| 1 | -package log | ||
| 2 | - | ||
| 3 | -import ( | ||
| 4 | - "fmt" | ||
| 5 | - "github.com/olivere/elastic/v7" | ||
| 6 | - "github.com/sirupsen/logrus" | ||
| 7 | - "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/constant" | ||
| 8 | - "gopkg.in/sohlich/elogrus.v7" | ||
| 9 | - "io" | ||
| 10 | - "os" | ||
| 11 | -) | ||
| 12 | - | ||
| 13 | -type ServerLog struct { | ||
| 14 | - serviceName string | ||
| 15 | - logrus *logrus.Logger | ||
| 16 | -} | ||
| 17 | - | ||
| 18 | -func (logger *ServerLog) AddHook(write io.Writer) { | ||
| 19 | - panic("implement me") | ||
| 20 | -} | ||
| 21 | - | ||
| 22 | -func (logger *ServerLog) SetServiceName(serviceName string) { | ||
| 23 | - logger.serviceName = serviceName | ||
| 24 | -} | ||
| 25 | - | ||
| 26 | -func (logger *ServerLog) SetLevel(level string) { | ||
| 27 | - switch level { | ||
| 28 | - case "trace": | ||
| 29 | - logger.logrus.Level = logrus.TraceLevel | ||
| 30 | - case "debug": | ||
| 31 | - logger.logrus.Level = logrus.DebugLevel | ||
| 32 | - case "info": | ||
| 33 | - logger.logrus.Level = logrus.InfoLevel | ||
| 34 | - case "warn": | ||
| 35 | - logger.logrus.Level = logrus.WarnLevel | ||
| 36 | - case "error": | ||
| 37 | - logger.logrus.Level = logrus.ErrorLevel | ||
| 38 | - case "fatal": | ||
| 39 | - logger.logrus.Level = logrus.FatalLevel | ||
| 40 | - case "panic": | ||
| 41 | - logger.logrus.Level = logrus.PanicLevel | ||
| 42 | - default: | ||
| 43 | - logger.logrus.Level = logrus.DebugLevel | ||
| 44 | - } | ||
| 45 | -} | ||
| 46 | - | ||
| 47 | -func (logger *ServerLog) Trace(msg string, appends ...map[string]interface{}) { | ||
| 48 | - contextLogger := logger.logrus.WithFields(logrus.Fields{"serviceName": logger.serviceName}) | ||
| 49 | - for _, append := range appends { | ||
| 50 | - contextLogger = contextLogger.WithFields(append) | ||
| 51 | - } | ||
| 52 | - contextLogger.Trace(msg) | ||
| 53 | -} | ||
| 54 | - | ||
| 55 | -func (logger *ServerLog) Debug(msg string, appends ...map[string]interface{}) { | ||
| 56 | - contextLogger := logger.logrus.WithFields(logrus.Fields{"serviceName": logger.serviceName}) | ||
| 57 | - for _, append := range appends { | ||
| 58 | - contextLogger = contextLogger.WithFields(append) | ||
| 59 | - } | ||
| 60 | - contextLogger.Debug(msg) | ||
| 61 | -} | ||
| 62 | - | ||
| 63 | -func (logger *ServerLog) Info(msg string, appends ...map[string]interface{}) { | ||
| 64 | - contextLogger := logger.logrus.WithFields(logrus.Fields{"serviceName": logger.serviceName}) | ||
| 65 | - for _, append := range appends { | ||
| 66 | - contextLogger = contextLogger.WithFields(append) | ||
| 67 | - } | ||
| 68 | - contextLogger.Info(msg) | ||
| 69 | -} | ||
| 70 | - | ||
| 71 | -func (logger *ServerLog) Warn(msg string, appends ...map[string]interface{}) { | ||
| 72 | - contextLogger := logger.logrus.WithFields(logrus.Fields{"serviceName": logger.serviceName}) | ||
| 73 | - for _, append := range appends { | ||
| 74 | - contextLogger = contextLogger.WithFields(append) | ||
| 75 | - } | ||
| 76 | - contextLogger.Warn(msg) | ||
| 77 | -} | ||
| 78 | - | ||
| 79 | -func (logger *ServerLog) Error(msg string, appends ...map[string]interface{}) { | ||
| 80 | - contextLogger := logger.logrus.WithFields(logrus.Fields{"serviceName": logger.serviceName}) | ||
| 81 | - for _, append := range appends { | ||
| 82 | - contextLogger = contextLogger.WithFields(append) | ||
| 83 | - } | ||
| 84 | - contextLogger.Error(msg) | ||
| 85 | -} | ||
| 86 | - | ||
| 87 | -func (logger *ServerLog) Fatal(msg string, appends ...map[string]interface{}) { | ||
| 88 | - contextLogger := logger.logrus.WithFields(logrus.Fields{"serviceName": logger.serviceName}) | ||
| 89 | - for _, append := range appends { | ||
| 90 | - contextLogger = contextLogger.WithFields(append) | ||
| 91 | - } | ||
| 92 | - contextLogger.Fatal(msg) | ||
| 93 | -} | ||
| 94 | - | ||
| 95 | -func (logger *ServerLog) Panic(msg string, appends ...map[string]interface{}) { | ||
| 96 | - contextLogger := logger.logrus.WithFields(logrus.Fields{"serviceName": logger.serviceName}) | ||
| 97 | - for _, append := range appends { | ||
| 98 | - contextLogger = contextLogger.WithFields(append) | ||
| 99 | - } | ||
| 100 | - contextLogger.Panic(msg) | ||
| 101 | -} | ||
| 102 | - | ||
| 103 | -func NewServerLog() *ServerLog { | ||
| 104 | - logger := logrus.New() | ||
| 105 | - logger.Formatter = &logrus.JSONFormatter{ | ||
| 106 | - TimestampFormat: "2006-01-02 15:04:05", | ||
| 107 | - PrettyPrint: true, | ||
| 108 | - } | ||
| 109 | - if constant.LOG_TYPE == "file" { | ||
| 110 | - file, err := os.OpenFile("logrus.log", os.O_CREATE|os.O_WRONLY, 0666) | ||
| 111 | - if err == nil { | ||
| 112 | - _ = file.Truncate(1024 * 1024 * 2) | ||
| 113 | - logger.Out = file | ||
| 114 | - } else { | ||
| 115 | - logger.Info("Failed to log to file, using default stderr") | ||
| 116 | - } | ||
| 117 | - } else if constant.LOG_TYPE == "es" { | ||
| 118 | - url := fmt.Sprintf("http://%s:%s", "es.chenzhiying.asia", "80") | ||
| 119 | - client, err := elastic.NewClient(elastic.SetURL(url), elastic.SetSniff(false)) | ||
| 120 | - if err != nil { | ||
| 121 | - //log.Panic(err) | ||
| 122 | - panic(err) | ||
| 123 | - } | ||
| 124 | - hook, err := elogrus.NewAsyncElasticHook(client, "es.chenzhiying.asia", logrus.DebugLevel, "boss-appointment") | ||
| 125 | - if err != nil { | ||
| 126 | - //log.Panic(err) | ||
| 127 | - panic(err) | ||
| 128 | - } | ||
| 129 | - logger.Hooks.Add(hook) | ||
| 130 | - } else { | ||
| 131 | - logger.Out = os.Stdout | ||
| 132 | - } | ||
| 133 | - return &ServerLog{ | ||
| 134 | - logrus: logger, | ||
| 135 | - } | ||
| 136 | -} |
-
请 注册 或 登录 后发表评论