You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by li...@apache.org on 2026/09/07 04:43:07 UTC

(skywalking-banyandb) 01/01: Unify the logging configuration across every BanyanDB binary

This is an automated email from the ASF dual-hosted git repository.

mrproliu pushed a commit to branch unify-logging-level
in repository https://gitbox.apache.org/repos/asf/skywalking-banyandb.git

commit 62692f29f6bfc2bf3375291711b771732e28ee2c
Author: mrproliu <74...@qq.com>
AuthorDate: Mon Sep 7 12:39:32 2026 +0800

    Unify the logging configuration across every BanyanDB binary
---
 CHANGES.md                              |  4 ++++
 banyand/backup/backup.go                |  3 +--
 banyand/backup/lifecycle/lifecycle.go   |  3 +--
 banyand/backup/restore.go               |  3 +--
 docs/operation/configuration.md         |  4 ++--
 docs/operation/observability/logging.md | 11 ++++++++++-
 fodc/agent/internal/cmd/root.go         | 10 ++++++++--
 fodc/proxy/cmd/proxy/main.go            | 13 ++++++++-----
 pkg/cmdsetup/root.go                    |  5 +----
 pkg/logger/setting.go                   |  9 +++++++++
 10 files changed, 45 insertions(+), 20 deletions(-)

diff --git a/CHANGES.md b/CHANGES.md
index a8489bffa..4034ee805 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -4,6 +4,10 @@ Release Notes.
 
 ## 0.12.0
 
+### Features
+
+- Add logging related flags to the FODC proxy and agent. Every BanyanDB binary now shares the same logging flags and the matching `BYDB_LOGGING_*` environment variables.
+
 ### Document
 
 - Add the [native inverted-index replacement design package](docs/design/archive/0.12.0/native-inverted-index/README.md), including the implementation specification, ICE walkthrough, research plan, and visual report.
diff --git a/banyand/backup/backup.go b/banyand/backup/backup.go
index 68ac063ea..b8b76b029 100644
--- a/banyand/backup/backup.go
+++ b/banyand/backup/backup.go
@@ -139,8 +139,7 @@ func NewBackupCommand() *cobra.Command {
 		},
 	}
 
-	cmd.Flags().StringVar(&logging.Env, "logging-env", "prod", "the logging environment")
-	cmd.Flags().StringVar(&logging.Level, "logging-level", "info", "the root level of logging")
+	logger.RegisterFlags(cmd.Flags(), &logging)
 	cmd.Flags().StringVar(&backupOpts.gRPCAddr, "grpc-addr", "127.0.0.1:17912", "gRPC address of the data node")
 	cmd.Flags().BoolVar(&backupOpts.enableTLS, "enable-tls", false, "Enable TLS for gRPC connection")
 	cmd.Flags().BoolVar(&backupOpts.insecure, "insecure", false, "Skip server certificate verification")
diff --git a/banyand/backup/lifecycle/lifecycle.go b/banyand/backup/lifecycle/lifecycle.go
index c6f74dc37..a8eda7436 100644
--- a/banyand/backup/lifecycle/lifecycle.go
+++ b/banyand/backup/lifecycle/lifecycle.go
@@ -108,8 +108,7 @@ func NewCommandWithRegistry() (*cobra.Command, observability.MetricsRegistry) {
 		},
 	}
 	cmd.Flags().AddFlagSet(group.RegisterFlags().FlagSet)
-	cmd.Flags().StringVar(&logging.Env, "logging-env", "prod", "the logging")
-	cmd.Flags().StringVar(&logging.Level, "logging-level", "info", "the root level of logging")
+	logger.RegisterFlags(cmd.Flags(), &logging)
 	crashOutputCfg.RegisterFlags(cmd.Flags())
 	return cmd, metricSvc
 }
diff --git a/banyand/backup/restore.go b/banyand/backup/restore.go
index dd5db44b8..4c5871208 100644
--- a/banyand/backup/restore.go
+++ b/banyand/backup/restore.go
@@ -56,8 +56,7 @@ func NewRestoreCommand() *cobra.Command {
 			return logger.Init(logging)
 		},
 	}
-	rootCmd.Flags().StringVar(&logging.Env, "logging-env", "prod", "the logging environment")
-	rootCmd.Flags().StringVar(&logging.Level, "logging-level", "info", "the root level of logging")
+	logger.RegisterFlags(rootCmd.Flags(), &logging)
 	rootCmd.AddCommand(newRunCommand())
 	rootCmd.AddCommand(NewTimeDirCommand())
 	return rootCmd
diff --git a/docs/operation/configuration.md b/docs/operation/configuration.md
index e9534dd29..d3c984ccb 100644
--- a/docs/operation/configuration.md
+++ b/docs/operation/configuration.md
@@ -271,8 +271,8 @@ These flags configure the connections a liaison holds to the data nodes it queri
 
 - `--logging-env string`: The logging environment (default: "prod").
 - `--logging-level string`: The root level of logging (default: "info").
-- `--logging-levels strings`: The level logging of logging.
-- `--logging-modules strings`: The specific module for logging.
+- `--logging-levels strings`: The logging level of each module, one per module.
+- `--logging-modules strings`: The modules whose logging level overrides the root one.
 - `--node-host string`: The node host of the server, only used when `node-host-provider` is "flag".
 - `--node-host-provider nodeIDProvider`: The node host provider, can be hostname, IP, or flag (default: Hostname).
 
diff --git a/docs/operation/observability/logging.md b/docs/operation/observability/logging.md
index 0c5e225fb..c1c798c04 100644
--- a/docs/operation/observability/logging.md
+++ b/docs/operation/observability/logging.md
@@ -1,6 +1,15 @@
 # Logging
 
-BanyanDB uses the [zerolog](https://github.com/rs/zerolog) library for logging. The log level can be set using the `log-level` flag. The supported log levels are `debug`, `info`, `warn`, `error`, and `fatal`. The default log level is `info`.
+BanyanDB uses the [zerolog](https://github.com/rs/zerolog) library for logging. The log level can be set using the `logging-level` flag. The supported log levels are `debug`, `info`, `warn`, `error`, and `fatal`. The default log level is `info`.
+
+Every BanyanDB binary accepts the same four logging flags: the server (`standalone`, `data`, `liaison`), `backup`, `restore`, `lifecycle`, the FODC proxy and the FODC agent. Each flag is also bound to an environment variable named after it, prefixed with `BYDB_` and upper-cased with dashes replaced by underscores, which is the usual way to configure them in a container:
+
+| Flag | Environment variable |
+|---|---|
+| `--logging-level` | `BYDB_LOGGING_LEVEL` |
+| `--logging-env` | `BYDB_LOGGING_ENV` |
+| `--logging-modules` | `BYDB_LOGGING_MODULES` |
+| `--logging-levels` | `BYDB_LOGGING_LEVELS` |
 
 `logging-env` is used to set the logging environment. The default value is `prod`. The logging environment can be set to `dev` for development or `prod` for production. The logging environment affects the log format and output. In the `dev` environment, logs are output in a human-readable format, while in the `prod` environment, logs are output in JSON format.
 
diff --git a/fodc/agent/internal/cmd/root.go b/fodc/agent/internal/cmd/root.go
index 57f05cdbb..4184b5586 100644
--- a/fodc/agent/internal/cmd/root.go
+++ b/fodc/agent/internal/cmd/root.go
@@ -44,6 +44,7 @@ import (
 	"github.com/apache/skywalking-banyandb/fodc/agent/internal/server"
 	"github.com/apache/skywalking-banyandb/fodc/agent/internal/watchdog"
 	"github.com/apache/skywalking-banyandb/pkg/cgroups"
+	"github.com/apache/skywalking-banyandb/pkg/config"
 	"github.com/apache/skywalking-banyandb/pkg/logger"
 	"github.com/apache/skywalking-banyandb/pkg/meter"
 	"github.com/apache/skywalking-banyandb/pkg/meter/prom"
@@ -100,6 +101,7 @@ var (
 	pressureDir                        string
 	pressureMaxArtifacts               int
 	pressureMaxDiskBytes               int64
+	logging                            logger.Logging
 	rootCmd                            = &cobra.Command{
 		Use:     "fodc",
 		Short:   "First Occurrence Data Collection (FODC) agent",
@@ -171,6 +173,7 @@ func init() {
 		"Maximum number of capture events to retain; the lowest-RSS events are evicted first")
 	rootCmd.Flags().Int64Var(&pressureMaxDiskBytes, "pressure-profiler-max-disk-bytes", defaultPressureMaxDiskBytes,
 		"Maximum total on-disk bytes for retained capture events (0 disables the disk bound)")
+	logger.RegisterFlags(rootCmd.Flags(), &logging)
 }
 
 func calculateCapacity(log *logger.Logger) int64 {
@@ -260,11 +263,14 @@ func initializeKTM(ctx context.Context, log *logger.Logger, fr *flightrecorder.F
 }
 
 // runFODC is the main function for the FODC agent.
-func runFODC(_ *cobra.Command, _ []string) error {
+func runFODC(cmd *cobra.Command, _ []string) error {
 	if installErr := crashOutputCfg.InstallGlobalCrashOutput(); installErr != nil {
 		return fmt.Errorf("failed to install crash output: %w", installErr)
 	}
-	if initErr := logger.Init(logger.Logging{Env: "prod", Level: "info"}); initErr != nil {
+	if loadErr := config.Load("logging", cmd.Flags()); loadErr != nil {
+		return fmt.Errorf("failed to load logging config: %w", loadErr)
+	}
+	if initErr := logger.Init(logging); initErr != nil {
 		return fmt.Errorf("failed to initialize logger: %w", initErr)
 	}
 	log := logger.GetLogger("fodc")
diff --git a/fodc/proxy/cmd/proxy/main.go b/fodc/proxy/cmd/proxy/main.go
index e5122714e..067f3af84 100644
--- a/fodc/proxy/cmd/proxy/main.go
+++ b/fodc/proxy/cmd/proxy/main.go
@@ -35,6 +35,7 @@ import (
 	"github.com/apache/skywalking-banyandb/fodc/proxy/internal/metrics"
 	"github.com/apache/skywalking-banyandb/fodc/proxy/internal/pressure"
 	"github.com/apache/skywalking-banyandb/fodc/proxy/internal/registry"
+	"github.com/apache/skywalking-banyandb/pkg/config"
 	"github.com/apache/skywalking-banyandb/pkg/logger"
 	"github.com/apache/skywalking-banyandb/pkg/version"
 )
@@ -61,6 +62,7 @@ var (
 	httpReadTimeout   time.Duration
 	httpWriteTimeout  time.Duration
 	heartbeatInterval time.Duration
+	logging           logger.Logging
 
 	rootCmd = &cobra.Command{
 		Use:     "fodc-proxy",
@@ -91,6 +93,7 @@ func init() {
 		"HTTP write timeout")
 	rootCmd.Flags().DurationVar(&heartbeatInterval, "heartbeat-interval", defaultHeartbeatInterval,
 		"Default heartbeat interval for agents")
+	logger.RegisterFlags(rootCmd.Flags(), &logging)
 }
 
 func main() {
@@ -100,11 +103,11 @@ func main() {
 	}
 }
 
-func runProxy(_ *cobra.Command, _ []string) error {
-	if initErr := logger.Init(logger.Logging{
-		Env:   "prod",
-		Level: "info",
-	}); initErr != nil {
+func runProxy(cmd *cobra.Command, _ []string) error {
+	if loadErr := config.Load("logging", cmd.Flags()); loadErr != nil {
+		return fmt.Errorf("failed to load logging config: %w", loadErr)
+	}
+	if initErr := logger.Init(logging); initErr != nil {
 		return fmt.Errorf("failed to initialize logger: %w", initErr)
 	}
 
diff --git a/pkg/cmdsetup/root.go b/pkg/cmdsetup/root.go
index 5a989ff02..8bb965c49 100644
--- a/pkg/cmdsetup/root.go
+++ b/pkg/cmdsetup/root.go
@@ -81,10 +81,7 @@ BanyanDB, as an observability database, aims to ingest, analyze and store Metric
 		"node-host-provider", "the node host provider, can be hostname, ip or flag, default is hostname")
 	cmd.PersistentFlags().StringVar(&common.FlagNodeHost, "node-host", "", "the node host of the server only used when node-host-provider is \"flag\"")
 	cmd.PersistentFlags().StringSliceVar(&common.FlagNodeLabels, "node-labels", nil, "the node labels. e.g. key1=value1,key2=value2")
-	cmd.PersistentFlags().StringVar(&logging.Env, "logging-env", "prod", "the logging")
-	cmd.PersistentFlags().StringVar(&logging.Level, "logging-level", "info", "the root level of logging")
-	cmd.PersistentFlags().StringSliceVar(&logging.Modules, "logging-modules", nil, "the specific module")
-	cmd.PersistentFlags().StringSliceVar(&logging.Levels, "logging-levels", nil, "the level logging of logging")
+	logger.RegisterFlags(cmd.PersistentFlags(), &logging)
 	crashOutputConfig.RegisterFlags(cmd.PersistentFlags())
 	cmd.AddCommand(newStandaloneCmd(runners...))
 	cmd.AddCommand(newDataCmd(runners...))
diff --git a/pkg/logger/setting.go b/pkg/logger/setting.go
index 32d0e1534..baac6f5c1 100644
--- a/pkg/logger/setting.go
+++ b/pkg/logger/setting.go
@@ -28,6 +28,7 @@ import (
 
 	"github.com/pkg/errors"
 	"github.com/rs/zerolog"
+	"github.com/spf13/pflag"
 )
 
 const rootName = "ROOT"
@@ -93,6 +94,14 @@ func GetLogger(scope ...string) *Logger {
 	return l
 }
 
+// RegisterFlags registers the logging flags shared by every BanyanDB binary.
+func RegisterFlags(fs *pflag.FlagSet, logging *Logging) {
+	fs.StringVar(&logging.Env, "logging-env", "prod", "the logging environment")
+	fs.StringVar(&logging.Level, "logging-level", "info", "the root level of logging")
+	fs.StringSliceVar(&logging.Modules, "logging-modules", nil, "the modules whose logging level overrides the root one")
+	fs.StringSliceVar(&logging.Levels, "logging-levels", nil, "the logging level of each module, one per module")
+}
+
 // Init initializes a rs/zerolog logger from user config.
 func Init(cfg Logging) (err error) {
 	switch cfg.Env {