From 873bddc6650e8fba4ffbf17da83e232ab0571e1e Mon Sep 17 00:00:00 2001 From: "Jonathan A. Sternberg" Date: Wed, 29 Apr 2026 12:03:54 -0500 Subject: [PATCH] feat: add log level option to buildkitd config This adds a way to set the log level of buildkitd outside of using `--debug` or `--trace` which allows increasing the log level rather than only lowering it. The `--debug` and `--trace` options will still exist both in the configuration file and on the command line. These are more general convenience options. Setting the log level option will override the log level and will take precedence over the more general options. Signed-off-by: Jonathan A. Sternberg --- cmd/buildkitd/config/config.go | 1 + cmd/buildkitd/main.go | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/cmd/buildkitd/config/config.go b/cmd/buildkitd/config/config.go index 65447eda0cc4..4709c555bb2c 100644 --- a/cmd/buildkitd/config/config.go +++ b/cmd/buildkitd/config/config.go @@ -63,6 +63,7 @@ type SystemConfig struct { type LogConfig struct { Format string `toml:"format"` + Level string `toml:"level"` } type GRPCConfig struct { diff --git a/cmd/buildkitd/main.go b/cmd/buildkitd/main.go index 808feaa00aaa..bc6ab4c79ddd 100644 --- a/cmd/buildkitd/main.go +++ b/cmd/buildkitd/main.go @@ -186,6 +186,12 @@ func main() { Usage: "log formatter: json or text", Value: "text", }, + cli.StringFlag{ + Name: "log-level", + Usage: "set the log level", + Value: "info", + EnvVar: "BUILDKITD_LOG_LEVEL", + }, cli.StringFlag{ Name: "group", Usage: groupUsageStr, @@ -273,6 +279,14 @@ func main() { logrus.SetLevel(logrus.TraceLevel) } + if cfg.Log.Level != "" { + level, err := logrus.ParseLevel(cfg.Log.Level) + if err != nil { + return errors.Wrap(err, "unsupported log level") + } + logrus.SetLevel(level) + } + if sc := cfg.System; sc != nil { if v := sc.PlatformsCacheMaxAge; v != nil { archutil.CacheMaxAge = v.Duration @@ -598,6 +612,9 @@ func applyMainFlags(c *cli.Context, cfg *config.Config) error { if c.IsSet("log-format") { cfg.Log.Format = c.String("log-format") } + if c.IsSet("log-level") { + cfg.Log.Level = c.String("log-level") + } if c.IsSet("addr") || len(cfg.GRPC.Address) == 0 { cfg.GRPC.Address = c.StringSlice("addr") }