From d65801f258ca8ee576428c07688e02daa19e268e Mon Sep 17 00:00:00 2001 From: kevin Date: Thu, 2 Mar 2023 10:13:31 +0800 Subject: [PATCH] chore: add comments --- core/conf/config.go | 4 ++-- core/logx/config.go | 39 ++++++++++++++++++++++++++++----------- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/core/conf/config.go b/core/conf/config.go index 4b686e7e..ccc9e8ee 100644 --- a/core/conf/config.go +++ b/core/conf/config.go @@ -59,7 +59,7 @@ func LoadConfig(file string, v any, opts ...Option) error { // LoadFromJsonBytes loads config into v from content json bytes. func LoadFromJsonBytes(content []byte, v any) error { - finfo, err := buildFieldsInfo(reflect.TypeOf(v)) + info, err := buildFieldsInfo(reflect.TypeOf(v)) if err != nil { return err } @@ -69,7 +69,7 @@ func LoadFromJsonBytes(content []byte, v any) error { return err } - lowerCaseKeyMap := toLowerCaseKeyMap(m, finfo) + lowerCaseKeyMap := toLowerCaseKeyMap(m, info) return mapping.UnmarshalJsonMap(lowerCaseKeyMap, v, mapping.WithCanonicalKeyFunc(toLowerCase)) } diff --git a/core/logx/config.go b/core/logx/config.go index 8f0398fd..1bd2317d 100644 --- a/core/logx/config.go +++ b/core/logx/config.go @@ -2,17 +2,34 @@ package logx // A LogConf is a logging config. type LogConf struct { - ServiceName string `json:",optional"` - Mode string `json:",default=console,options=[console,file,volume]"` - Encoding string `json:",default=json,options=[json,plain]"` - TimeFormat string `json:",optional"` - Path string `json:",default=logs"` - Level string `json:",default=info,options=[debug,info,error,severe]"` - MaxContentLength uint32 `json:",optional"` - Compress bool `json:",optional"` - Stat bool `json:",default=true"` - KeepDays int `json:",optional"` - StackCooldownMillis int `json:",default=100"` + // ServiceName represents the service name. + ServiceName string `json:",optional"` + // Mode represents the logging mode, default is `console`. + // console: log to console. + // file: log to file. + // volume: used in k8s, prepend the hostname to the log file name. + Mode string `json:",default=console,options=[console,file,volume]"` + // Encoding represents the encoding type, default is `json`. + // json: json encoding. + // plain: plain text encoding, typically used in development. + Encoding string `json:",default=json,options=[json,plain]"` + // TimeFormat represents the time format, default is `2006-01-02T15:04:05.000Z07:00`. + TimeFormat string `json:",optional"` + // Path represents the log file path, default is `logs`. + Path string `json:",default=logs"` + // Level represents the log level, default is `info`. + Level string `json:",default=info,options=[debug,info,error,severe]"` + // MaxContentLength represents the max content bytes, default is no limit. + MaxContentLength uint32 `json:",optional"` + // Compress represents whether to compress the log file, default is `false`. + Compress bool `json:",optional"` + // Stdout represents whether to log statistics, default is `true`. + Stat bool `json:",default=true"` + // KeepDays represents how many days the log files will be kept. Default to keep all files. + // Only take effect when Mode is `file` or `volume`, both work when Rotation is `daily` or `size`. + KeepDays int `json:",optional"` + // StackCooldownMillis represents the cooldown time for stack logging, default is 100ms. + StackCooldownMillis int `json:",default=100"` // MaxBackups represents how many backup log files will be kept. 0 means all files will be kept forever. // Only take effect when RotationRuleType is `size`. // Even thougth `MaxBackups` sets 0, log files will still be removed