Skip to content

slog: expose io.Writer#694

Merged
ArthurSens merged 1 commit intoprometheus:mainfrom
jkroepke:slog/writer
Sep 14, 2024
Merged

slog: expose io.Writer#694
ArthurSens merged 1 commit intoprometheus:mainfrom
jkroepke:slog/writer

Conversation

@jkroepke
Copy link
Member

@jkroepke jkroepke commented Sep 7, 2024

While implementing the new slog logger at windows_exporter, I figure out that I'm unable to set the Writer as I could on slog.

Define the Writer is important for windows. stdout and stderr are not captured, if programs running as Windows Service.

On windows_exporter, I implement a io.Writer which is able to write data to the Windows Event Log and I would like to use that writer.

Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
@ArthurSens ArthurSens merged commit 40d6251 into prometheus:main Sep 14, 2024
@jkroepke jkroepke deleted the slog/writer branch September 14, 2024 19:07
tjhop added a commit to tjhop/prometheus that referenced this pull request Sep 27, 2024
For: prometheus#14355

Requires a new release of prometheus/common to be cut, as this depends
on the following PRs:

prometheus/common#694
prometheus/common#697

This commit updates Prometheus to adopt stdlib's log/slog package in
favor of go-kit/log. As part of converting to use slog, several other
related changes are required to get prometheus working, including:
- removed unused logging util func `RateLimit()`
- forward ported the util/logging/Deduper logging by implementing a small custom slog.Handler that does the deduping before chaining log calls to the underlying real slog.Logger
- move some of the json file logging functionality to use prom/common package functionality
- refactored some of the new json file logging for scraping
- changes to promql.QueryLogger interface to swap out logging methods for relevant slog sugar wrappers
- updated lots of tests that used/replicated custom logging functionality, attempting to keep the logical goal of the tests consistent after the transition
- added a healthy amount of `if logger == nil { $makeLogger }` type conditional checks amongst various functions where none were provided -- old code that used the go-kit/log.Logger interface had several places where there were nil references when trying to use functions like `With()` to add keyvals on the new *slog.Logger type

Signed-off-by: TJ Hoplock <t.hoplock@gmail.com>
tjhop added a commit to tjhop/prometheus that referenced this pull request Sep 29, 2024
For: prometheus#14355

Requires a new release of prometheus/common to be cut, as this depends
on the following PRs:

prometheus/common#694
prometheus/common#697

This commit updates Prometheus to adopt stdlib's log/slog package in
favor of go-kit/log. As part of converting to use slog, several other
related changes are required to get prometheus working, including:
- removed unused logging util func `RateLimit()`
- forward ported the util/logging/Deduper logging by implementing a small custom slog.Handler that does the deduping before chaining log calls to the underlying real slog.Logger
- move some of the json file logging functionality to use prom/common package functionality
- refactored some of the new json file logging for scraping
- changes to promql.QueryLogger interface to swap out logging methods for relevant slog sugar wrappers
- updated lots of tests that used/replicated custom logging functionality, attempting to keep the logical goal of the tests consistent after the transition
- added a healthy amount of `if logger == nil { $makeLogger }` type conditional checks amongst various functions where none were provided -- old code that used the go-kit/log.Logger interface had several places where there were nil references when trying to use functions like `With()` to add keyvals on the new *slog.Logger type

Signed-off-by: TJ Hoplock <t.hoplock@gmail.com>
tjhop added a commit to tjhop/prometheus that referenced this pull request Sep 29, 2024
temporarily pinning prom/common to latest commit @main for access to
prometheus/common#694 and prometheus/common#697 which haven't made it to
a release yet

Signed-off-by: TJ Hoplock <t.hoplock@gmail.com>
tjhop added a commit to tjhop/prometheus that referenced this pull request Sep 29, 2024
temporarily pinning prom/common to latest commit @main for access to
prometheus/common#694 and prometheus/common#697 which haven't made it to
a release yet

Signed-off-by: TJ Hoplock <t.hoplock@gmail.com>
tjhop added a commit to tjhop/prometheus that referenced this pull request Sep 29, 2024
temporarily pinning prom/common to latest commit @main for access to
prometheus/common#694 and prometheus/common#697 which haven't made it to
a release yet

Signed-off-by: TJ Hoplock <t.hoplock@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants