Skip to content

Commit a743838

Browse files
feat: use zap.AtomicLevel for dynamic logging levels (#26182) (#26826)
Co-authored-by: davidby-influx <72418212+davidby-influx@users.noreply.github.com>
1 parent d0c94e9 commit a743838

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

cmd/influx_inspect/verify/seriesfile/command.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ func (cmd *Command) Run(args ...string) error {
5555
}
5656

5757
config := logger.NewConfig()
58-
config.Level = zapcore.WarnLevel
58+
config.Level.SetLevel(zapcore.WarnLevel)
5959
if cmd.verbose {
60-
config.Level = zapcore.InfoLevel
60+
config.Level.SetLevel(zapcore.InfoLevel)
6161
}
6262
logger, err := config.New(cmd.Stderr)
6363
if err != nil {

cmd/influx_tools/compact/command.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (cmd *Command) Run(args []string) (err error) {
5959

6060
var log = zap.NewNop()
6161
if cmd.verbose {
62-
cfg := logger.Config{Format: "logfmt", Level: zapcore.DebugLevel}
62+
cfg := logger.Config{Format: "logfmt", Level: zap.NewAtomicLevelAt(zapcore.DebugLevel)}
6363
log, err = cfg.New(os.Stdout)
6464
if err != nil {
6565
return err

cmd/influxd/run/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ min-version = "tls1.0"
228228
t.Fatalf("unexpected cache max memory size: %v", c.Data.CacheMaxMemorySize)
229229
}
230230

231-
if c.Logging.Level != zapcore.WarnLevel {
231+
if c.Logging.Level.Level() != zapcore.WarnLevel {
232232
t.Fatalf("unexpected logging level: %v", c.Logging.Level)
233233
}
234234

logger/config.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
package logger
22

33
import (
4-
"go.uber.org/zap/zapcore"
4+
"go.uber.org/zap"
55
)
66

77
// Config represents the configuration for creating a zap.Logger.
88
type Config struct {
9-
Format string `toml:"format"`
10-
Level zapcore.Level `toml:"level"`
11-
SuppressLogo bool `toml:"suppress-logo"`
9+
Format string `toml:"format"`
10+
Level zap.AtomicLevel `toml:"level"`
11+
SuppressLogo bool `toml:"suppress-logo"`
1212
}
1313

1414
// NewConfig returns a new instance of Config with defaults.
1515
func NewConfig() Config {
1616
return Config{
1717
Format: "auto",
18-
Level: zapcore.InfoLevel,
18+
Level: zap.NewAtomicLevel(),
1919
}
2020
}

toml/toml_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ func TestGroup_UnmarshalTOML(t *testing.T) {
141141
}
142142

143143
func TestConfig_Encode(t *testing.T) {
144-
var c run.Config
144+
var c *run.Config = run.NewConfig()
145145
c.Coordinator.WriteTimeout = itoml.Duration(time.Minute)
146146
buf := new(bytes.Buffer)
147-
if err := toml.NewEncoder(buf).Encode(&c); err != nil {
147+
if err := toml.NewEncoder(buf).Encode(c); err != nil {
148148
t.Fatal("Failed to encode: ", err)
149149
}
150150
got, search := buf.String(), `write-timeout = "1m0s"`

0 commit comments

Comments
 (0)