From 2486eeba2662430b117d16719baca1ad4180e3bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=85=89=E6=98=A5?= Date: Mon, 15 May 2023 17:24:35 +0800 Subject: [PATCH] - update --- library.go | 2 +- utils/golog/api_zap.go | 42 ++++++++++++++++-------------------------- 2 files changed, 17 insertions(+), 27 deletions(-) diff --git a/library.go b/library.go index 2acaf916..c67529fb 100644 --- a/library.go +++ b/library.go @@ -1,5 +1,5 @@ package go_library func Version() string { - return "1.0.141" + return "1.0.142" } diff --git a/utils/golog/api_zap.go b/utils/golog/api_zap.go index a356e35a..687238dc 100644 --- a/utils/golog/api_zap.go +++ b/utils/golog/api_zap.go @@ -35,23 +35,17 @@ type ApiZapLog struct { logger *zap.Logger zapCore zapcore.Core systemConfig struct { - systemHostname string // 主机名 - systemOs string // 系统类型 - systemVersion string // 系统版本 - systemKernel string // 系统内核 - systemKernelVersion string // 系统内核版本 - systemBootTime uint64 // 系统开机时间 - cpuCores int // CPU核数 - cpuModelName string // CPU型号名称 - cpuMhz float64 // CPU兆赫 - systemInsideIp string // 内网ip - systemOutsideIp string // 外网ip - goVersion string // go版本 - sdkVersion string // sdk版本 + systemHostname string // 主机名 + systemOs string // 系统类型 + systemKernel string // 系统内核 + systemInsideIp string // 内网ip + systemOutsideIp string // 外网ip + goVersion string // go版本 + sdkVersion string // sdk版本 } } -func NewApiZapLog(config *ApiZapLogConfig) *ApiZapLog { +func NewApiZapLog(ctx context.Context, config *ApiZapLogConfig) *ApiZapLog { zl := &ApiZapLog{config: config} @@ -104,6 +98,8 @@ func NewApiZapLog(config *ApiZapLogConfig) *ApiZapLog { zl.logger = zl.withShowLine(zap.New(zl.zapCore)) + zl.setConfig(ctx) + return zl } @@ -125,7 +121,7 @@ func (zl *ApiZapLog) Middleware(ctx context.Context, request gorequest.Response) }, zapcore.Field{ Key: "request_time", Type: zapcore.StringType, - String: request.RequestTime.String(), + String: gotime.SetCurrent(request.RequestTime).Format(), }, zapcore.Field{ Key: "request_uri", Type: zapcore.StringType, @@ -173,7 +169,7 @@ func (zl *ApiZapLog) Middleware(ctx context.Context, request gorequest.Response) }, zapcore.Field{ Key: "response_time", Type: zapcore.StringType, - String: request.ResponseTime.GoString(), + String: gotime.SetCurrent(request.ResponseTime).Format(), }, zapcore.Field{ Key: "system_host_name", Type: zapcore.StringType, @@ -212,7 +208,7 @@ func (zl *ApiZapLog) MiddlewareXml(ctx context.Context, request gorequest.Respon }, zapcore.Field{ Key: "request_time", Type: zapcore.StringType, - String: request.RequestTime.String(), + String: gotime.SetCurrent(request.RequestTime).Format(), }, zapcore.Field{ Key: "request_uri", Type: zapcore.StringType, @@ -260,7 +256,7 @@ func (zl *ApiZapLog) MiddlewareXml(ctx context.Context, request gorequest.Respon }, zapcore.Field{ Key: "response_time", Type: zapcore.StringType, - String: request.ResponseTime.GoString(), + String: gotime.SetCurrent(request.ResponseTime).Format(), }, zapcore.Field{ Key: "system_host_name", Type: zapcore.StringType, @@ -299,7 +295,7 @@ func (zl *ApiZapLog) MiddlewareCustom(ctx context.Context, api string, request g }, zapcore.Field{ Key: "request_time", Type: zapcore.StringType, - String: request.RequestTime.String(), + String: gotime.SetCurrent(request.RequestTime).Format(), }, zapcore.Field{ Key: "request_uri", Type: zapcore.StringType, @@ -347,7 +343,7 @@ func (zl *ApiZapLog) MiddlewareCustom(ctx context.Context, api string, request g }, zapcore.Field{ Key: "response_time", Type: zapcore.StringType, - String: request.ResponseTime.GoString(), + String: gotime.SetCurrent(request.ResponseTime).Format(), }, zapcore.Field{ Key: "system_host_name", Type: zapcore.StringType, @@ -382,13 +378,7 @@ func (zl *ApiZapLog) setConfig(ctx context.Context) { zl.systemConfig.systemHostname = info.SystemHostname zl.systemConfig.systemOs = info.SystemOs - zl.systemConfig.systemVersion = info.SystemVersion zl.systemConfig.systemKernel = info.SystemKernel - zl.systemConfig.systemKernelVersion = info.SystemKernelVersion - zl.systemConfig.systemBootTime = info.SystemBootTime - zl.systemConfig.cpuCores = info.CpuCores - zl.systemConfig.cpuModelName = info.CpuModelName - zl.systemConfig.cpuMhz = info.CpuMhz zl.systemConfig.systemInsideIp = goip.GetInsideIp(ctx)