From 4e65b41202eab5e3f3f40a67c399632f27b45a5a Mon Sep 17 00:00:00 2001 From: Gaius Date: Tue, 24 Jun 2025 15:27:28 +0800 Subject: [PATCH] feat: add logLevel and remove verbose (#4157) Signed-off-by: Gaius --- build/package/docs/dfcache/dfcache-delete.1 | 2 - build/package/docs/dfcache/dfcache-doc.1 | 2 - build/package/docs/dfcache/dfcache-export.1 | 4 +- build/package/docs/dfcache/dfcache-import.1 | 2 - build/package/docs/dfcache/dfcache-plugin.1 | 2 - build/package/docs/dfcache/dfcache-stat.1 | 2 - build/package/docs/dfcache/dfcache-version.1 | 2 - build/package/docs/dfcache/dfcache.1 | 2 - build/package/docs/dfcache/dfcache.md | 2 - build/package/docs/dfcache/dfcache_delete.md | 2 - build/package/docs/dfcache/dfcache_doc.md | 2 - build/package/docs/dfcache/dfcache_export.md | 4 +- build/package/docs/dfcache/dfcache_import.md | 2 - build/package/docs/dfcache/dfcache_plugin.md | 2 - build/package/docs/dfcache/dfcache_stat.md | 2 - build/package/docs/dfcache/dfcache_version.md | 2 - build/package/docs/dfget.1 | 2 - build/package/docs/dfget.1.md | 2 - build/package/nfpm/config/dfget.yaml | 2 - client/config/dfcache.go | 3 ++ client/config/dfget.go | 3 ++ client/config/peerhost.go | 1 + client/config/peerhost_test.go | 1 - client/config/testdata/config/daemon.yaml | 3 +- client/daemon/objectstorage/objectstorage.go | 4 +- client/daemon/upload/upload_manager.go | 4 +- cmd/dependency/base/option.go | 4 +- cmd/dependency/dependency.go | 3 -- cmd/dfcache/cmd/root.go | 3 +- cmd/dfget/cmd/daemon.go | 2 +- cmd/dfget/cmd/root.go | 4 +- cmd/manager/cmd/root.go | 2 +- cmd/scheduler/cmd/root.go | 2 +- .../template/manager.template.yaml | 10 +---- .../template/scheduler.template.yaml | 10 +---- internal/dflog/logcore.go | 6 +-- internal/dflog/logger.go | 1 + internal/dflog/loginit.go | 38 +++++++++---------- manager/config/config.go | 5 ++- manager/config/config_test.go | 1 + manager/config/testdata/manager.yaml | 1 + manager/database/mysql.go | 2 +- manager/router/router.go | 2 +- pkg/log/log.go | 4 +- scheduler/config/config.go | 5 ++- scheduler/config/config_test.go | 1 + scheduler/config/testdata/scheduler.yaml | 1 + test/testdata/charts/config-rate-limit.yaml | 6 ++- test/testdata/charts/config.yaml | 6 ++- 49 files changed, 69 insertions(+), 111 deletions(-) diff --git a/build/package/docs/dfcache/dfcache-delete.1 b/build/package/docs/dfcache/dfcache-delete.1 index d5f6f010f..3ea9d35f8 100644 --- a/build/package/docs/dfcache/dfcache-delete.1 +++ b/build/package/docs/dfcache/dfcache-delete.1 @@ -16,10 +16,8 @@ dfcache delete <\-i cid> [flags] \-\-config string the path of configuration file with yaml extension name, default is /etc/dragonfly/dfcache.yaml, it can also be set by env var: DFCACHE_CONFIG \-\-console whether logger output records to the stdout \-\-logdir string Dfcache log directory - \-\-pprof\-port int listen port for pprof(default \-1) \-t, \-\-tag string different tags for the same cid will be recognized as different files in P2P network \-\-timeout duration Timeout for this cache operation, 0 is infinite - \-\-verbose whether logger use debug level \-\-workhome string Dfcache working directory \-h, \-\-help help for delete .EE diff --git a/build/package/docs/dfcache/dfcache-doc.1 b/build/package/docs/dfcache/dfcache-doc.1 index be2418e87..6f620dd83 100644 --- a/build/package/docs/dfcache/dfcache-doc.1 +++ b/build/package/docs/dfcache/dfcache-doc.1 @@ -16,10 +16,8 @@ dfcache doc [flags] \-\-config string the path of configuration file with yaml extension name, default is /etc/dragonfly/dfcache.yaml, it can also be set by env var: DFCACHE_CONFIG \-\-console whether logger output records to the stdout \-\-logdir string Dfcache log directory - \-\-pprof\-port int listen port for pprof(default \-1) \-t, \-\-tag string different tags for the same cid will be recognized as different files in P2P network \-\-timeout duration Timeout for this cache operation, 0 is infinite - \-\-verbose whether logger use debug level \-\-workhome string Dfcache working directory \-h, \-\-help help for doc \-\-path string destination dir of generated markdown documents (default \(dq./\(dq) diff --git a/build/package/docs/dfcache/dfcache-export.1 b/build/package/docs/dfcache/dfcache-export.1 index 5ef562679..5d425c2e5 100644 --- a/build/package/docs/dfcache/dfcache-export.1 +++ b/build/package/docs/dfcache/dfcache-export.1 @@ -16,10 +16,8 @@ dfcache export <\-i cid> |<\-O output> [flags] \-\-config string the path of configuration file with yaml extension name, default is /etc/dragonfly/dfcache.yaml, it can also be set by env var: DFCACHE_CONFIG \-\-console whether logger output records to the stdout \-\-logdir string Dfcache log directory - \-\-pprof\-port int listen port for pprof(default \-1) - \-t, \-\-tag string different tags for the same cid will be recognized as different files in P2P network + \-t, \-\-tag string different tags for the same cid will be recognized as different files in P3P network \-\-timeout duration Timeout for this cache operation, 0 is infinite - \-\-verbose whether logger use debug level \-\-workhome string Dfcache working directory \-h, \-\-help help for export \-l, \-\-local only export file from local cache diff --git a/build/package/docs/dfcache/dfcache-import.1 b/build/package/docs/dfcache/dfcache-import.1 index 8e6a51013..795e555e2 100644 --- a/build/package/docs/dfcache/dfcache-import.1 +++ b/build/package/docs/dfcache/dfcache-import.1 @@ -16,10 +16,8 @@ dfcache import <\-i cid> |<\-I file> [flags] \-\-config string the path of configuration file with yaml extension name, default is /etc/dragonfly/dfcache.yaml, it can also be set by env var: DFCACHE_CONFIG \-\-console whether logger output records to the stdout \-\-logdir string Dfcache log directory - \-\-pprof\-port int listen port for pprof(default \-1) \-t, \-\-tag string different tags for the same cid will be recognized as different files in P2P network \-\-timeout duration Timeout for this cache operation, 0 is infinite - \-\-verbose whether logger use debug level \-\-workhome string Dfcache working directory \-h, \-\-help help for import \-I, \-\-input string import the given file into P2P network diff --git a/build/package/docs/dfcache/dfcache-plugin.1 b/build/package/docs/dfcache/dfcache-plugin.1 index 837777617..7cbd7f387 100644 --- a/build/package/docs/dfcache/dfcache-plugin.1 +++ b/build/package/docs/dfcache/dfcache-plugin.1 @@ -16,10 +16,8 @@ dfcache plugin [flags] \-\-config string the path of configuration file with yaml extension name, default is /etc/dragonfly/dfcache.yaml, it can also be set by env var: DFCACHE_CONFIG \-\-console whether logger output records to the stdout \-\-logdir string Dfcache log directory - \-\-pprof\-port int listen port for pprof(default \-1) \-t, \-\-tag string different tags for the same cid will be recognized as different files in P2P network \-\-timeout duration Timeout for this cache operation, 0 is infinite - \-\-verbose whether logger use debug level \-\-workhome string Dfcache working directory \-h, \-\-help help for plugin .EE diff --git a/build/package/docs/dfcache/dfcache-stat.1 b/build/package/docs/dfcache/dfcache-stat.1 index 8e0ccf9d0..57cfa7ee4 100644 --- a/build/package/docs/dfcache/dfcache-stat.1 +++ b/build/package/docs/dfcache/dfcache-stat.1 @@ -17,10 +17,8 @@ dfcache stat <\-i cid> [flags] \-\-config string the path of configuration file with yaml extension name, default is /etc/dragonfly/dfcache.yaml, it can also be set by env var: DFCACHE_CONFIG \-\-console whether logger output records to the stdout \-\-logdir string Dfcache log directory - \-\-pprof\-port int listen port for pprof(default \-1) \-t, \-\-tag string different tags for the same cid will be recognized as different files in P2P network \-\-timeout duration Timeout for this cache operation, 0 is infinite - \-\-verbose whether logger use debug level \-\-workhome string Dfcache working directory \-h, \-\-help help for stat \-l, \-\-local only check task exists locally, and don\(aqt check other peers in P2P network diff --git a/build/package/docs/dfcache/dfcache-version.1 b/build/package/docs/dfcache/dfcache-version.1 index 1187489a2..76aac1020 100644 --- a/build/package/docs/dfcache/dfcache-version.1 +++ b/build/package/docs/dfcache/dfcache-version.1 @@ -16,10 +16,8 @@ dfcache version [flags] \-\-config string the path of configuration file with yaml extension name, default is /etc/dragonfly/dfcache.yaml, it can also be set by env var: DFCACHE_CONFIG \-\-console whether logger output records to the stdout \-\-logdir string Dfcache log directory - \-\-pprof\-port int listen port for pprof(default \-1) \-t, \-\-tag string different tags for the same cid will be recognized as different files in P2P network \-\-timeout duration Timeout for this cache operation, 0 is infinite - \-\-verbose whether logger use debug level \-\-workhome string Dfcache working directory \-h, \-\-help help for version .EE diff --git a/build/package/docs/dfcache/dfcache.1 b/build/package/docs/dfcache/dfcache.1 index 4616203fd..0b89e6c49 100644 --- a/build/package/docs/dfcache/dfcache.1 +++ b/build/package/docs/dfcache/dfcache.1 @@ -23,10 +23,8 @@ network. \-\-console whether logger output records to the stdout \-h, \-\-help help for dfcache \-\-logdir string Dfcache log directory - \-\-pprof\-port int listen port for pprof(default \-1) \-t, \-\-tag string different tags for the same cid will be recognized as different files in P2P network \-\-timeout duration Timeout for this cache operation, 0 is infinite - \-\-verbose whether logger use debug level \-\-workhome string Dfcache working directory .EE .SH SEE ALSO diff --git a/build/package/docs/dfcache/dfcache.md b/build/package/docs/dfcache/dfcache.md index 6b6978e03..ada8bad5d 100644 --- a/build/package/docs/dfcache/dfcache.md +++ b/build/package/docs/dfcache/dfcache.md @@ -23,10 +23,8 @@ responsibility to go back to source and add file into P2P network. --console whether logger output records to the stdout -h, --help help for dfcache --logdir string Dfcache log directory - --pprof-port int listen port for pprof(default -1) -t, --tag string different tags for the same cid will be recognized as different files in P2P network --timeout duration Timeout for this cache operation, 0 is infinite - --verbose whether logger use debug level --workhome string Dfcache working directory ``` diff --git a/build/package/docs/dfcache/dfcache_delete.md b/build/package/docs/dfcache/dfcache_delete.md index bacd3ef85..528319047 100644 --- a/build/package/docs/dfcache/dfcache_delete.md +++ b/build/package/docs/dfcache/dfcache_delete.md @@ -19,10 +19,8 @@ dfcache delete <-i cid> [flags] --config string the path of configuration file with yaml extension name, default is /etc/dragonfly/dfcache.yaml, it can also be set by env var: DFCACHE_CONFIG --console whether logger output records to the stdout --logdir string Dfcache log directory - --pprof-port int listen port for pprof(default -1) -t, --tag string different tags for the same cid will be recognized as different files in P2P network --timeout duration Timeout for this cache operation, 0 is infinite - --verbose whether logger use debug level --workhome string Dfcache working directory -h, --help help for delete ``` diff --git a/build/package/docs/dfcache/dfcache_doc.md b/build/package/docs/dfcache/dfcache_doc.md index 50e71bfa6..7b57cc799 100644 --- a/build/package/docs/dfcache/dfcache_doc.md +++ b/build/package/docs/dfcache/dfcache_doc.md @@ -19,10 +19,8 @@ dfcache doc [flags] --config string the path of configuration file with yaml extension name, default is /etc/dragonfly/dfcache.yaml, it can also be set by env var: DFCACHE_CONFIG --console whether logger output records to the stdout --logdir string Dfcache log directory - --pprof-port int listen port for pprof(default -1) -t, --tag string different tags for the same cid will be recognized as different files in P2P network --timeout duration Timeout for this cache operation, 0 is infinite - --verbose whether logger use debug level --workhome string Dfcache working directory -h, --help help for doc --path string destination dir of generated markdown documents (default "./") diff --git a/build/package/docs/dfcache/dfcache_export.md b/build/package/docs/dfcache/dfcache_export.md index 1fbc94ce5..f203f5ae8 100644 --- a/build/package/docs/dfcache/dfcache_export.md +++ b/build/package/docs/dfcache/dfcache_export.md @@ -19,10 +19,8 @@ dfcache export <-i cid> |<-O output> [flags] --config string the path of configuration file with yaml extension name, default is /etc/dragonfly/dfcache.yaml, it can also be set by env var: DFCACHE_CONFIG --console whether logger output records to the stdout --logdir string Dfcache log directory - --pprof-port int listen port for pprof(default -1) - -t, --tag string different tags for the same cid will be recognized as different files in P2P network + -t, --tag string different tags for the same cid will be recognized as different files in P3P network --timeout duration Timeout for this cache operation, 0 is infinite - --verbose whether logger use debug level --workhome string Dfcache working directory -h, --help help for export -l, --local only export file from local cache diff --git a/build/package/docs/dfcache/dfcache_import.md b/build/package/docs/dfcache/dfcache_import.md index ab1fc47ac..d852e4729 100644 --- a/build/package/docs/dfcache/dfcache_import.md +++ b/build/package/docs/dfcache/dfcache_import.md @@ -19,10 +19,8 @@ dfcache import <-i cid> |<-I file> [flags] --config string the path of configuration file with yaml extension name, default is /etc/dragonfly/dfcache.yaml, it can also be set by env var: DFCACHE_CONFIG --console whether logger output records to the stdout --logdir string Dfcache log directory - --pprof-port int listen port for pprof(default -1) -t, --tag string different tags for the same cid will be recognized as different files in P2P network --timeout duration Timeout for this cache operation, 0 is infinite - --verbose whether logger use debug level --workhome string Dfcache working directory -h, --help help for import -I, --input string import the given file into P2P network diff --git a/build/package/docs/dfcache/dfcache_plugin.md b/build/package/docs/dfcache/dfcache_plugin.md index cf9e35f69..8a00b0d8a 100644 --- a/build/package/docs/dfcache/dfcache_plugin.md +++ b/build/package/docs/dfcache/dfcache_plugin.md @@ -19,10 +19,8 @@ dfcache plugin [flags] --config string the path of configuration file with yaml extension name, default is /etc/dragonfly/dfcache.yaml, it can also be set by env var: DFCACHE_CONFIG --console whether logger output records to the stdout --logdir string Dfcache log directory - --pprof-port int listen port for pprof(default -1) -t, --tag string different tags for the same cid will be recognized as different files in P2P network --timeout duration Timeout for this cache operation, 0 is infinite - --verbose whether logger use debug level --workhome string Dfcache working directory -h, --help help for plugin ``` diff --git a/build/package/docs/dfcache/dfcache_stat.md b/build/package/docs/dfcache/dfcache_stat.md index dda2c06ef..70f082917 100644 --- a/build/package/docs/dfcache/dfcache_stat.md +++ b/build/package/docs/dfcache/dfcache_stat.md @@ -19,10 +19,8 @@ dfcache stat <-i cid> [flags] --config string the path of configuration file with yaml extension name, default is /etc/dragonfly/dfcache.yaml, it can also be set by env var: DFCACHE_CONFIG --console whether logger output records to the stdout --logdir string Dfcache log directory - --pprof-port int listen port for pprof(default -1) -t, --tag string different tags for the same cid will be recognized as different files in P2P network --timeout duration Timeout for this cache operation, 0 is infinite - --verbose whether logger use debug level --workhome string Dfcache working directory -h, --help help for stat -l, --local only check task exists locally, and don't check other peers in P2P network diff --git a/build/package/docs/dfcache/dfcache_version.md b/build/package/docs/dfcache/dfcache_version.md index 70d2a9c3c..0016af289 100644 --- a/build/package/docs/dfcache/dfcache_version.md +++ b/build/package/docs/dfcache/dfcache_version.md @@ -19,10 +19,8 @@ dfcache version [flags] --config string the path of configuration file with yaml extension name, default is /etc/dragonfly/dfcache.yaml, it can also be set by env var: DFCACHE_CONFIG --console whether logger output records to the stdout --logdir string Dfcache log directory - --pprof-port int listen port for pprof(default -1) -t, --tag string different tags for the same cid will be recognized as different files in P2P network --timeout duration Timeout for this cache operation, 0 is infinite - --verbose whether logger use debug level --workhome string Dfcache working directory -h, --help help for version ``` diff --git a/build/package/docs/dfget.1 b/build/package/docs/dfget.1 index f2a2552b3..6ff8c61e3 100644 --- a/build/package/docs/dfget.1 +++ b/build/package/docs/dfget.1 @@ -32,7 +32,6 @@ and so on. \-\-original\-offset Range request only. Download ranged data into target file with original offset. Daemon will make a hardlink to target file. Client can download many ranged data into one file for same url. When enabled, back source in client will be disabled \-O, \-\-output string Destination path which is used to store the downloaded file, it must be a full path \-P, \-\-priority string Scheduler will schedule task according to priority - \-\-pprof\-port int listen port for pprof(default \-1) \-\-range string Download range. Like: 0\-9, stands download 10 bytes from 0 \-9, [0:9] in real url \-\-ratelimit string The downloading network bandwidth limit per second in format of G(B)/g/M(B)/m/K(B)/k/B, pure number will be parsed as Byte, 0 is infinite (default \(dq100.0MB\(dq) \-r, \-\-recursive Recursively download all resources in target url, the target source client must support list action @@ -41,7 +40,6 @@ and so on. \-\-tag string Different tags for the same url will be divided into different P2P overlay, it conflicts with \-\-digest \-\-timeout duration Timeout for the downloading task, 0 is infinite \-u, \-\-url string Download one file from the url, equivalent to the command\(aqs first position argument - \-\-verbose whether logger use debug level \-\-workhome string Dfget working directory .EE .SH BUGS diff --git a/build/package/docs/dfget.1.md b/build/package/docs/dfget.1.md index 0ffea16c2..a22ebbb39 100644 --- a/build/package/docs/dfget.1.md +++ b/build/package/docs/dfget.1.md @@ -29,7 +29,6 @@ functionality, such as network bandwidth limit, transmission encryption and so o --original-offset Range request only. Download ranged data into target file with original offset. Daemon will make a hardlink to target file. Client can download many ranged data into one file for same url. When enabled, back source in client will be disabled -O, --output string Destination path which is used to store the downloaded file, it must be a full path -P, --priority string Scheduler will schedule task according to priority - --pprof-port int listen port for pprof(default -1) --range string Download range. Like: 0-9, stands download 10 bytes from 0 -9, [0:9] in real url --ratelimit string The downloading network bandwidth limit per second in format of G(B)/g/M(B)/m/K(B)/k/B, pure number will be parsed as Byte, 0 is infinite (default "100.0MB") -r, --recursive Recursively download all resources in target url, the target source client must support list action @@ -38,7 +37,6 @@ functionality, such as network bandwidth limit, transmission encryption and so o --tag string Different tags for the same url will be divided into different P2P overlay, it conflicts with --digest --timeout duration Timeout for the downloading task, 0 is infinite -u, --url string Download one file from the url, equivalent to the command's first position argument - --verbose whether logger use debug level --workhome string Dfget working directory ``` diff --git a/build/package/nfpm/config/dfget.yaml b/build/package/nfpm/config/dfget.yaml index 23a749ab9..482edf43c 100644 --- a/build/package/nfpm/config/dfget.yaml +++ b/build/package/nfpm/config/dfget.yaml @@ -25,8 +25,6 @@ scheduler: scheduleTimeout: 10s # when enabled, pprof will be enabled, -verbose: true -log-level: debug console: false # current host info used for scheduler diff --git a/client/config/dfcache.go b/client/config/dfcache.go index bad0adb8d..ea67f330b 100644 --- a/client/config/dfcache.go +++ b/client/config/dfcache.go @@ -52,6 +52,9 @@ type CacheOption struct { // LogDir is log directory of dfcache. LogDir string `yaml:"logDir,omitempty" mapstructure:"logDir,omitempty"` + // LogLevel is log level of dfcache, supported values are "debug", "info", "warn", "error", "panic", "fatal". + LogLevel string `yaml:"logLevel,omitempty" mapstructure:"logLevel,omitempty"` + // Maximum size in megabytes of log files before rotation (default: 1024) LogMaxSize int `yaml:"logMaxSize" mapstructure:"logMaxSize"` diff --git a/client/config/dfget.go b/client/config/dfget.go index 27213e1e2..b1e5de243 100644 --- a/client/config/dfget.go +++ b/client/config/dfget.go @@ -100,6 +100,9 @@ type ClientOption struct { // LogDir is log directory of dfget. LogDir string `yaml:"logDir,omitempty" mapstructure:"logDir,omitempty"` + // LogLevel is log level of dfget, supported values are "debug", "info", "warn", "error", "panic", "fatal". + LogLevel string `yaml:"logLevel,omitempty" mapstructure:"logLevel,omitempty"` + // Maximum size in megabytes of log files before rotation (default: 1024) LogMaxSize int `yaml:"logMaxSize" mapstructure:"logMaxSize"` diff --git a/client/config/peerhost.go b/client/config/peerhost.go index 8589e523f..79471dd78 100644 --- a/client/config/peerhost.go +++ b/client/config/peerhost.go @@ -62,6 +62,7 @@ type DaemonOption struct { CacheDir string `mapstructure:"cacheDir" yaml:"cacheDir"` CacheDirMode uint32 `mapstructure:"cacheDirMode" yaml:"cacheDirMode"` LogDir string `mapstructure:"logDir" yaml:"logDir"` + LogLevel string `mapstructure:"logLevel" yaml:"logLevel"` LogMaxSize int `yaml:"logMaxSize" mapstructure:"logMaxSize"` LogMaxAge int `yaml:"logMaxAge" mapstructure:"logMaxAge"` LogMaxBackups int `yaml:"logMaxBackups" mapstructure:"logMaxBackups"` diff --git a/client/config/peerhost_test.go b/client/config/peerhost_test.go index 6380ef985..4edc4b074 100644 --- a/client/config/peerhost_test.go +++ b/client/config/peerhost_test.go @@ -234,7 +234,6 @@ func TestPeerHostOption_Load(t *testing.T) { peerHostOption := &DaemonOption{ Options: base.Options{ Console: true, - Verbose: true, PProfPort: -1, Tracing: base.TracingConfig{ Protocol: "grpc", diff --git a/client/config/testdata/config/daemon.yaml b/client/config/testdata/config/daemon.yaml index aa173cccf..2f4e9f6ca 100644 --- a/client/config/testdata/config/daemon.yaml +++ b/client/config/testdata/config/daemon.yaml @@ -1,6 +1,5 @@ console: true -verbose: true -pprof-port: -1 +pprofPort: -1 tracing: protocol: "grpc" endpoint: "localhost:4317" diff --git a/client/daemon/objectstorage/objectstorage.go b/client/daemon/objectstorage/objectstorage.go index 24614af49..d307127ba 100644 --- a/client/daemon/objectstorage/objectstorage.go +++ b/client/daemon/objectstorage/objectstorage.go @@ -147,9 +147,7 @@ func (o *objectStorage) Stop() error { // Initialize router of gin. func (o *objectStorage) initRouter(cfg *config.DaemonOption, logDir string) *gin.Engine { // Set mode. - if !cfg.Verbose { - gin.SetMode(gin.ReleaseMode) - } + gin.SetMode(gin.ReleaseMode) // Logging to a file. if !cfg.Console { diff --git a/client/daemon/upload/upload_manager.go b/client/daemon/upload/upload_manager.go index 57962e502..971fb755d 100644 --- a/client/daemon/upload/upload_manager.go +++ b/client/daemon/upload/upload_manager.go @@ -148,9 +148,7 @@ func (um *uploadManager) Stop() error { // Initialize router of gin. func (um *uploadManager) initRouter(cfg *config.DaemonOption, logDir string) *gin.Engine { // Set mode - if !cfg.Verbose { - gin.SetMode(gin.ReleaseMode) - } + gin.SetMode(gin.ReleaseMode) r := gin.New() diff --git a/cmd/dependency/base/option.go b/cmd/dependency/base/option.go index 62dd344b1..abb71703a 100644 --- a/cmd/dependency/base/option.go +++ b/cmd/dependency/base/option.go @@ -18,9 +18,7 @@ package base type Options struct { Console bool `yaml:"console" mapstructure:"console"` - Verbose bool `yaml:"verbose" mapstructure:"verbose"` - LogLevel string `yaml:"log-level" mapstructure:"log-level"` - PProfPort int `yaml:"pprof-port" mapstructure:"pprof-port"` + PProfPort int `yaml:"pprofPort" mapstructure:"pprofPort"` Tracing TracingConfig `yaml:"tracing" mapstructure:"tracing"` } diff --git a/cmd/dependency/dependency.go b/cmd/dependency/dependency.go index 9ca2ab199..f719ef6fd 100644 --- a/cmd/dependency/dependency.go +++ b/cmd/dependency/dependency.go @@ -71,9 +71,6 @@ func InitCommandAndConfig(cmd *cobra.Command, useConfigFile bool, config any) { // Add common flags flags := cmd.PersistentFlags() flags.Bool("console", false, "whether logger output records to the stdout") - flags.Bool("verbose", false, "whether logger use debug level") - flags.String("log-level", "", "use specific log level(debug, info, warn, error), take precedence over verbose flag") - flags.Int("pprof-port", -1, "listen port for pprof, 0 represents random port") flags.String("config", "", fmt.Sprintf("the path of configuration file with yaml extension name, default is %s, it can also be set by env var: %s", filepath.Join(dfpath.DefaultConfigDir, rootName+".yaml"), strings.ToUpper(rootName+"_config"))) // Bind common flags diff --git a/cmd/dfcache/cmd/root.go b/cmd/dfcache/cmd/root.go index 391994ea4..4f87a1c7e 100644 --- a/cmd/dfcache/cmd/root.go +++ b/cmd/dfcache/cmd/root.go @@ -83,6 +83,7 @@ func init() { flags.Duration("timeout", dfcacheConfig.Timeout, "Timeout for this cache operation, 0 is infinite") flags.String("workhome", dfcacheConfig.WorkHome, "Dfcache working directory") flags.String("logdir", dfcacheConfig.LogDir, "Dfcache log directory") + flags.String("logLevel", dfcacheConfig.LogLevel, "Dfcache log level, one of: debug, info, warn, error, fatal, panic") flags.String("daemon-sock", dfcacheConfig.DaemonSock, "Dfdaemon socket path to connect") // Bind common flags @@ -142,7 +143,7 @@ func runDfcacheSubcmd(ctx context.Context, cmdName string, args []string) error MaxBackups: dfcacheConfig.LogMaxBackups} // Initialize logger - if err := logger.InitDfcache(dfcacheConfig.Verbose, dfcacheConfig.LogLevel, d.LogDir(), rotateConfig); err != nil { + if err := logger.InitDfcache(dfcacheConfig.LogLevel, d.LogDir(), rotateConfig); err != nil { return fmt.Errorf("init client dfcache logger: %w", err) } logger.Infof("version:\n%s", version.Version()) diff --git a/cmd/dfget/cmd/daemon.go b/cmd/dfget/cmd/daemon.go index b0d7a7797..80e226eb7 100644 --- a/cmd/dfget/cmd/daemon.go +++ b/cmd/dfget/cmd/daemon.go @@ -80,7 +80,7 @@ it supports container engine, wget and other downloading tools through proxy fun MaxBackups: cfg.LogMaxBackups} // Initialize logger - if err := logger.InitDaemon(cfg.Verbose, cfg.LogLevel, cfg.Console, d.LogDir(), rotateConfig); err != nil { + if err := logger.InitDaemon(cfg.LogLevel, cfg.Console, d.LogDir(), rotateConfig); err != nil { return fmt.Errorf("init client daemon logger: %w", err) } logger.RedirectStdoutAndStderr(cfg.Console, path.Join(d.LogDir(), types.DaemonName)) diff --git a/cmd/dfget/cmd/root.go b/cmd/dfget/cmd/root.go index 21e556cc2..9f3f1aa36 100644 --- a/cmd/dfget/cmd/root.go +++ b/cmd/dfget/cmd/root.go @@ -94,7 +94,7 @@ var rootCmd = &cobra.Command{ MaxBackups: dfgetConfig.LogMaxBackups} // Initialize logger - if err := logger.InitDfget(dfgetConfig.Verbose, dfgetConfig.LogLevel, dfgetConfig.Console, d.LogDir(), rotateConfig); err != nil { + if err := logger.InitDfget(dfgetConfig.LogLevel, dfgetConfig.Console, d.LogDir(), rotateConfig); err != nil { return fmt.Errorf("init client dfget logger: %w", err) } @@ -178,6 +178,8 @@ func init() { flagSet.String("logdir", dfgetConfig.LogDir, "Dfget log directory") + flagSet.String("logLevel", dfgetConfig.LogLevel, "Dfget log level, one of: debug, info, warn, error, fatal, panic") + flagSet.String("datadir", dfgetConfig.DataDir, "Dfget data directory") flagSet.String("cachedir", dfgetConfig.CacheDir, "Dfget cache directory") diff --git a/cmd/manager/cmd/root.go b/cmd/manager/cmd/root.go index 041b6873d..224f97719 100644 --- a/cmd/manager/cmd/root.go +++ b/cmd/manager/cmd/root.go @@ -72,7 +72,7 @@ for managing schedulers and seed peers, offering http apis and portal, etc.`, MaxBackups: cfg.Server.LogMaxBackups} // Initialize logger. - if err := logger.InitManager(cfg.Verbose, cfg.LogLevel, cfg.Console, d.LogDir(), rotateConfig); err != nil { + if err := logger.InitManager(cfg.Server.LogLevel, cfg.Console, d.LogDir(), rotateConfig); err != nil { return fmt.Errorf("init manager logger: %w", err) } logger.RedirectStdoutAndStderr(cfg.Console, path.Join(d.LogDir(), types.ManagerName)) diff --git a/cmd/scheduler/cmd/root.go b/cmd/scheduler/cmd/root.go index fa198290a..6a5c1629d 100644 --- a/cmd/scheduler/cmd/root.go +++ b/cmd/scheduler/cmd/root.go @@ -72,7 +72,7 @@ generate and maintain a P2P network during the download process, and push suitab MaxBackups: cfg.Server.LogMaxBackups} // Initialize logger. - if err := logger.InitScheduler(cfg.Verbose, cfg.LogLevel, cfg.Console, d.LogDir(), rotateConfig); err != nil { + if err := logger.InitScheduler(cfg.Server.LogLevel, cfg.Console, d.LogDir(), rotateConfig); err != nil { return fmt.Errorf("init scheduler logger: %w", err) } logger.RedirectStdoutAndStderr(cfg.Console, path.Join(d.LogDir(), types.SchedulerName)) diff --git a/deploy/docker-compose/template/manager.template.yaml b/deploy/docker-compose/template/manager.template.yaml index 6ff0cf7a0..e54380672 100644 --- a/deploy/docker-compose/template/manager.template.yaml +++ b/deploy/docker-compose/template/manager.template.yaml @@ -162,14 +162,8 @@ network: # Console shows log on console. console: false -# Whether to enable debug level logger and enable pprof. -verbose: true - -# Use specific log level(debug, info, warn, error), take precedence over verbose flag. -# log-level: debug - -# Listen port for pprof, only valid when the verbose option is true, default is -1. -pprof-port: -1 +# Listen port for pprof, default is -1 (means disabled). +pprofPort: -1 tracing: # Jaeger endpoint url, like: http://jaeger.dragonfly.svc:4317. diff --git a/deploy/docker-compose/template/scheduler.template.yaml b/deploy/docker-compose/template/scheduler.template.yaml index 830d8b904..e6b9e3fec 100644 --- a/deploy/docker-compose/template/scheduler.template.yaml +++ b/deploy/docker-compose/template/scheduler.template.yaml @@ -178,14 +178,8 @@ network: # Console shows log on console. console: false -# Whether to enable debug level logger and enable pprof. -verbose: true - -# Use specific log level(debug, info, warn, error), take precedence over verbose flag. -# log-level: debug - -# Listen port for pprof, only valid when the verbose option is true, default is -1. -pprof-port: -1 +# Listen port for pprof, default is -1 (means disabled). +pprofPort: -1 tracing: # Jaeger endpoint url, like: http://jaeger.dragonfly.svc:4317. diff --git a/internal/dflog/logcore.go b/internal/dflog/logcore.go index 7e53ce65f..ba64834b3 100644 --- a/internal/dflog/logcore.go +++ b/internal/dflog/logcore.go @@ -53,8 +53,7 @@ var customCoreLevel atomic.Bool var grpcLevel = zap.NewAtomicLevelAt(zapcore.WarnLevel) var customGrpcLevel atomic.Bool -func CreateLogger(filePath string, compress bool, stats bool, verbose bool, logLevel string, config LogRotateConfig) (*zap.Logger, zap.AtomicLevel, error) { - +func CreateLogger(filePath string, compress bool, stats bool, logLevel string, config LogRotateConfig) (*zap.Logger, zap.AtomicLevel, error) { rotateConfig := &lumberjack.Logger{ Filename: filePath, MaxSize: config.MaxSize, @@ -68,7 +67,6 @@ func CreateLogger(filePath string, compress bool, stats bool, verbose bool, logL encoderConfig := zap.NewProductionEncoderConfig() encoderConfig.EncodeTime = zapcore.TimeEncoderOfLayout(encodeTimeFormat) var level = zap.NewAtomicLevelAt(zap.InfoLevel) - // Use logLevel first, then fallback to verbose flag. if logLevel != "" { switch strings.ToLower(logLevel) { case "debug": @@ -82,8 +80,6 @@ func CreateLogger(filePath string, compress bool, stats bool, verbose bool, logL default: fmt.Printf("Warning: invalid log level '%s', using 'info' instead\n", logLevel) } - } else if verbose { - level = zap.NewAtomicLevelAt(zapcore.DebugLevel) } if strings.HasSuffix(filePath, GrpcLogFileName) && customGrpcLevel.Load() { diff --git a/internal/dflog/logger.go b/internal/dflog/logger.go index 8df457130..a2f57ba73 100644 --- a/internal/dflog/logger.go +++ b/internal/dflog/logger.go @@ -102,6 +102,7 @@ func SetGrpcLogger(log *zap.SugaredLogger) { if vl, err := strconv.Atoi(vLevel); err == nil { v = vl } + grpclog.SetLoggerV2(&zapGrpc{GrpcLogger, v}) } diff --git a/internal/dflog/loginit.go b/internal/dflog/loginit.go index 5fee7c881..4d64e0fa4 100644 --- a/internal/dflog/loginit.go +++ b/internal/dflog/loginit.go @@ -35,9 +35,9 @@ type logInitMeta struct { setLoggerFunc func(log *zap.Logger) } -func InitManager(verbose bool, logLevel string, console bool, dir string, rotateConfig LogRotateConfig) error { +func InitManager(logLevel string, console bool, dir string, rotateConfig LogRotateConfig) error { if console { - return createConsoleLogger(verbose, logLevel) + return createConsoleLogger(logLevel) } logDir := filepath.Join(dir, types.ManagerName) @@ -64,12 +64,12 @@ func InitManager(verbose bool, logLevel string, console bool, dir string, rotate }, } - return createFileLogger(verbose, logLevel, meta, logDir, rotateConfig) + return createFileLogger(logLevel, meta, logDir, rotateConfig) } -func InitScheduler(verbose bool, logLevel string, console bool, dir string, rotateConfig LogRotateConfig) error { +func InitScheduler(logLevel string, console bool, dir string, rotateConfig LogRotateConfig) error { if console { - return createConsoleLogger(verbose, logLevel) + return createConsoleLogger(logLevel) } logDir := filepath.Join(dir, types.SchedulerName) @@ -92,12 +92,12 @@ func InitScheduler(verbose bool, logLevel string, console bool, dir string, rota }, } - return createFileLogger(verbose, logLevel, meta, logDir, rotateConfig) + return createFileLogger(logLevel, meta, logDir, rotateConfig) } -func InitDaemon(verbose bool, logLevel string, console bool, dir string, rotateConfig LogRotateConfig) error { +func InitDaemon(logLevel string, console bool, dir string, rotateConfig LogRotateConfig) error { if console { - return createConsoleLogger(verbose, logLevel) + return createConsoleLogger(logLevel) } logDir := filepath.Join(dir, types.DaemonName) @@ -120,12 +120,12 @@ func InitDaemon(verbose bool, logLevel string, console bool, dir string, rotateC }, } - return createFileLogger(verbose, logLevel, meta, logDir, rotateConfig) + return createFileLogger(logLevel, meta, logDir, rotateConfig) } -func InitDfget(verbose bool, logLevel string, console bool, dir string, rotateConfig LogRotateConfig) error { +func InitDfget(logLevel string, console bool, dir string, rotateConfig LogRotateConfig) error { if console { - return createConsoleLogger(verbose, logLevel) + return createConsoleLogger(logLevel) } logDir := filepath.Join(dir, types.DfgetName) @@ -140,10 +140,10 @@ func InitDfget(verbose bool, logLevel string, console bool, dir string, rotateCo }, } - return createFileLogger(verbose, logLevel, meta, logDir, rotateConfig) + return createFileLogger(logLevel, meta, logDir, rotateConfig) } -func InitDfcache(verbose bool, logLevel string, dir string, rotateConfig LogRotateConfig) error { +func InitDfcache(logLevel string, dir string, rotateConfig LogRotateConfig) error { logDir := filepath.Join(dir, types.DfcacheName) var meta = []logInitMeta{ { @@ -156,14 +156,13 @@ func InitDfcache(verbose bool, logLevel string, dir string, rotateConfig LogRota }, } - return createFileLogger(verbose, logLevel, meta, logDir, rotateConfig) + return createFileLogger(logLevel, meta, logDir, rotateConfig) } -func createConsoleLogger(verbose bool, logLevel string) error { +func createConsoleLogger(logLevel string) error { levels = nil config := zap.NewDevelopmentConfig() config.Level = zap.NewAtomicLevelAt(zap.InfoLevel) - // Use logLevel first, then fallback to verbose flag. if logLevel != "" { switch strings.ToLower(logLevel) { case "debug": @@ -177,8 +176,6 @@ func createConsoleLogger(verbose bool, logLevel string) error { default: fmt.Printf("Warning: invalid log level '%s', using 'info' instead\n", logLevel) } - } else if verbose { - config.Level = zap.NewAtomicLevelAt(zap.DebugLevel) } log, err := config.Build(zap.AddCaller(), zap.AddStacktrace(zap.WarnLevel), zap.AddCallerSkip(1)) @@ -199,13 +196,13 @@ func createConsoleLogger(verbose bool, logLevel string) error { return nil } -func createFileLogger(verbose bool, logLevel string, meta []logInitMeta, logDir string, rotateConfig LogRotateConfig) error { +func createFileLogger(logLevel string, meta []logInitMeta, logDir string, rotateConfig LogRotateConfig) error { levels = nil // create parent dir first _ = os.MkdirAll(logDir, fs.FileMode(0700)) for _, m := range meta { - log, level, err := CreateLogger(path.Join(logDir, m.fileName), false, false, verbose, logLevel, rotateConfig) + log, level, err := CreateLogger(path.Join(logDir, m.fileName), false, false, logLevel, rotateConfig) if err != nil { return err } @@ -217,6 +214,7 @@ func createFileLogger(verbose bool, logLevel string, meta []logInitMeta, logDir levels = append(levels, level) } + startLoggerSignalHandler() return nil } diff --git a/manager/config/config.go b/manager/config/config.go index 59ce405e4..38b8d48b8 100644 --- a/manager/config/config.go +++ b/manager/config/config.go @@ -68,6 +68,9 @@ type ServerConfig struct { // Server log directory. LogDir string `yaml:"logDir" mapstructure:"logDir"` + // LogLevel is log level of server, supported values are "debug", "info", "warn", "error", "panic", "fatal". + LogLevel string `yaml:"logLevel" mapstructure:"logLevel"` + // Maximum size in megabytes of log files before rotation (default: 1024) LogMaxSize int `yaml:"logMaxSize" mapstructure:"logMaxSize"` @@ -403,7 +406,6 @@ func New() *Config { return &Config{ Options: base.Options{ Console: false, - Verbose: false, PProfPort: -1, Tracing: base.TracingConfig{ ServiceName: types.ManagerName, @@ -420,6 +422,7 @@ func New() *Config { REST: RESTConfig{ Addr: DefaultRESTAddr, }, + LogLevel: "info", LogMaxSize: DefaultLogRotateMaxSize, LogMaxAge: DefaultLogRotateMaxAge, LogMaxBackups: DefaultLogRotateMaxBackups, diff --git a/manager/config/config_test.go b/manager/config/config_test.go index d08cefeaf..7ba6337c4 100644 --- a/manager/config/config_test.go +++ b/manager/config/config_test.go @@ -97,6 +97,7 @@ func TestConfig_Load(t *testing.T) { Name: "foo", CacheDir: "foo", LogDir: "foo", + LogLevel: "debug", LogMaxSize: 512, LogMaxAge: 5, LogMaxBackups: 3, diff --git a/manager/config/testdata/manager.yaml b/manager/config/testdata/manager.yaml index ad436f9e2..9eb1353eb 100644 --- a/manager/config/testdata/manager.yaml +++ b/manager/config/testdata/manager.yaml @@ -2,6 +2,7 @@ server: name: foo cacheDir: foo logDir: foo + logLevel: debug logMaxSize: 512 logMaxAge: 5 logMaxBackups: 3 diff --git a/manager/database/mysql.go b/manager/database/mysql.go index aa264fd52..9b5767433 100644 --- a/manager/database/mysql.go +++ b/manager/database/mysql.go @@ -54,7 +54,7 @@ func newMysql(cfg *config.Config) (*gorm.DB, error) { // Initialize gorm logger. logLevel := gormlogger.Info - if !cfg.Verbose { + if cfg.Server.LogLevel != "info" { logLevel = gormlogger.Warn } gormLogger := zapgorm2.New(logger.CoreLogger.Desugar()).LogMode(logLevel) diff --git a/manager/router/router.go b/manager/router/router.go index 5073804d0..5508aabe1 100644 --- a/manager/router/router.go +++ b/manager/router/router.go @@ -44,7 +44,7 @@ import ( func Init(cfg *config.Config, logDir string, service service.Service, database *database.Database, enforcer *casbin.Enforcer, limiter ratelimiter.JobRateLimiter, assets static.ServeFileSystem) (*gin.Engine, error) { // Set mode. - if !cfg.Verbose { + if cfg.Server.LogLevel == "info" { gin.SetMode(gin.ReleaseMode) } diff --git a/pkg/log/log.go b/pkg/log/log.go index 7559c3b2b..fa597ad3c 100644 --- a/pkg/log/log.go +++ b/pkg/log/log.go @@ -34,7 +34,7 @@ func SetGrpcLevel(level zapcore.Level) { } // SetupDaemon sets daemon log config: path, console -func SetupDaemon(logDir string, verbose bool, logLevel string, console bool, rotateConfig logger.LogRotateConfig) error { +func SetupDaemon(logDir string, logLevel string, console bool, rotateConfig logger.LogRotateConfig) error { var options []dfpath.Option if logDir != "" { options = append(options, dfpath.WithLogDir(logDir)) @@ -45,5 +45,5 @@ func SetupDaemon(logDir string, verbose bool, logLevel string, console bool, rot return err } - return logger.InitDaemon(verbose, logLevel, console, d.LogDir(), rotateConfig) + return logger.InitDaemon(logLevel, console, d.LogDir(), rotateConfig) } diff --git a/scheduler/config/config.go b/scheduler/config/config.go index 870dc3f38..c3f614c35 100644 --- a/scheduler/config/config.go +++ b/scheduler/config/config.go @@ -91,6 +91,9 @@ type ServerConfig struct { // Server log directory. LogDir string `yaml:"logDir" mapstructure:"logDir"` + // LogLevel is log level of server, supported values are "debug", "info", "warn", "error", "panic", "fatal". + LogLevel string `yaml:"logLevel" mapstructure:"logLevel"` + // Maximum size in megabytes of log files before rotation (default: 1024) LogMaxSize int `yaml:"logMaxSize" mapstructure:"logMaxSize"` @@ -318,7 +321,6 @@ func New() *Config { return &Config{ Options: base.Options{ Console: false, - Verbose: false, PProfPort: -1, Tracing: base.TracingConfig{ ServiceName: types.SchedulerName, @@ -328,6 +330,7 @@ func New() *Config { Port: DefaultServerPort, AdvertisePort: DefaultServerAdvertisePort, Host: fqdn.FQDNHostname, + LogLevel: "info", LogMaxSize: DefaultLogRotateMaxSize, LogMaxAge: DefaultLogRotateMaxAge, LogMaxBackups: DefaultLogRotateMaxBackups, diff --git a/scheduler/config/config_test.go b/scheduler/config/config_test.go index a48acfd95..fa59514f8 100644 --- a/scheduler/config/config_test.go +++ b/scheduler/config/config_test.go @@ -87,6 +87,7 @@ func TestConfig_Load(t *testing.T) { }, CacheDir: "foo", LogDir: "foo", + LogLevel: "debug", LogMaxSize: 512, LogMaxAge: 5, LogMaxBackups: 3, diff --git a/scheduler/config/testdata/scheduler.yaml b/scheduler/config/testdata/scheduler.yaml index 05f1f715d..ae51de1d1 100644 --- a/scheduler/config/testdata/scheduler.yaml +++ b/scheduler/config/testdata/scheduler.yaml @@ -12,6 +12,7 @@ server: logDir: foo pluginDir: foo dataDir: foo + logLevel: debug logMaxSize: 512 logMaxAge: 5 logMaxBackups: 3 diff --git a/test/testdata/charts/config-rate-limit.yaml b/test/testdata/charts/config-rate-limit.yaml index 8c746f276..c789ef75c 100644 --- a/test/testdata/charts/config-rate-limit.yaml +++ b/test/testdata/charts/config-rate-limit.yaml @@ -25,7 +25,8 @@ manager: enable: true config: console: false - verbose: true + server: + logLevel: debug job: rateLimit: fillInterval: 1m @@ -63,7 +64,8 @@ scheduler: enableHost: true config: console: false - verbose: true + server: + logLevel: debug scheduler: algorithm: default retryBackToSourceLimit: 7 diff --git a/test/testdata/charts/config.yaml b/test/testdata/charts/config.yaml index 5a58152b8..4bb6c6f00 100644 --- a/test/testdata/charts/config.yaml +++ b/test/testdata/charts/config.yaml @@ -25,7 +25,8 @@ manager: enable: true config: console: false - verbose: true + server: + logLevel: debug job: rateLimit: fillInterval: 1m @@ -63,7 +64,8 @@ scheduler: enableHost: true config: console: false - verbose: true + server: + logLevel: debug scheduler: algorithm: default retryBackToSourceLimit: 7