Comparing v0.56.0...v0.57.0 · prometheus/common (original) (raw)

Commits on Aug 28, 2024

  1. feat: new promslog and promslog/flag packages to wrap log/slog
    Prereq for prometheus/prometheus#14355
    This adds a new promslog package to create an opinionated slog logger
    for use within the prometheus ecosystem. By default, logs are written at
    info level and formatted to add a kv pair for the source caller. If
    backwards compatibility for the literal output format of the logging is
    required, logs can be styled in a format that is similar to how the
    promlog package formatted it's go-kit/log output [1]. The promslog
    package also makes use of an slog.LevelVar to dynamically adjust the
    level of an existing logger. Similar to the old promlog package, we
    provide means to log in logfmt and json output formats.
    Creating a logger is similar to the old promlog package -- optionally
    populate a Config struct, and then call New() with the config.
    In order to dynamically adjust the logger's level, retain the Config
    struct as it's own variable to access the AllowedLevel.Set() method,
    which internally updates the AllowedLevel's slog.LevelVar to the
    desired log level. Ex:
config := &promslog.Config{} // Retain as variable if you need to dynamically adjust log level  
logger := promslog.New(config)  
config.Level.Set("debug")  
logger.Debug("your message here", "hello", "world")  

To use go-kit style log output:

config := &promslog.Config{Style: promslog.GoKitStyle} // Retain as variable if you need to dynamically adjust log level  
logger := promslog.New(config)  
config.Level.Set("debug")  
logger.Debug("your message here", "hello", "world")  
  1. When using the go-kit log style, the following changes are made to the
    default slog output:
  1. Configuration menu
    Browse the repository at this point in the history