Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace logger #108

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft

refactor: replace logger #108

wants to merge 7 commits into from

Conversation

dmke
Copy link
Member

@dmke dmke commented Jan 25, 2024

This replaces the zap logging engine with Go 1.21's new structured logger, log/slog, or more precisely a thin wrapper around that (xlog).

The log/slog package has a few things missing, which are present in xlog:

  1. xlog provides a no-op logger, which simply discards any log output. This is extensively used in our tests.
  2. xlog has a Fatal() output method, which simply calls Error() and then os.Exit(1).
  3. xlog does not provide global convenience functions to access a default logger instance; all calls must go through a Logger instance created with New().
  4. xlog treats error values as first-class citizen. Since (log/slog).Error() is a convenience function for their default logger instance, there is no built-in way to treat errors as values. In comparison, (xlog).Error(err) constructs an slog.Attr.

Point (2) is debatable, since xlog.Fatal is only used in cmd/texd/main.go, so I'd be willing to forfeit it.

Some TODOs remain:

  • xlog, i.e. its extension over log/slog, is not really tested
  • more documentation
  • switch to functional options for xlog.New()
  • colorization (at least for local development)

Issue: #1

@dmke dmke added the enhancement New feature or request label Jan 25, 2024
Copy link

codecov bot commented Jan 25, 2024

Codecov Report

Attention: Patch coverage is 47.03390% with 125 lines in your changes missing coverage. Please review.

Please upload report for BASE (master@7e9eb47). Learn more about missing BASE report.

Files with missing lines Patch % Lines
xlog/xlog.go 21.31% 48 Missing ⚠️
cmd/texd/main.go 0.00% 32 Missing ⚠️
xlog/options.go 74.19% 14 Missing and 2 partials ⚠️
service/renderer.go 44.44% 10 Missing ⚠️
xlog/discard.go 0.00% 8 Missing ⚠️
xlog/attrs.go 0.00% 6 Missing ⚠️
service/service.go 57.14% 3 Missing ⚠️
refstore/nop/nop_store.go 50.00% 1 Missing ⚠️
service/middleware/logging.go 88.88% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             master     #108   +/-   ##
=========================================
  Coverage          ?   69.80%           
=========================================
  Files             ?       38           
  Lines             ?     1984           
  Branches          ?        0           
=========================================
  Hits              ?     1385           
  Misses            ?      534           
  Partials          ?       65           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dmke dmke force-pushed the refactor/slog branch 3 times, most recently from 6d2020a to 150f5a4 Compare January 28, 2024 22:43
@dmke dmke force-pushed the refactor/slog branch 5 times, most recently from 9d525cc to 9d10789 Compare October 30, 2024 20:45
dmke added 6 commits October 31, 2024 17:21
This replaces the zap logging engine with Go 1.21's structured
logger, log/slog, or more precisely a thin wrapper around that
("xlog").

The log/slog package has a few things missing, which are
present in xlog:

1. xlog provides a no-op logger, which simply discards any log output.
   This is extensively used in our tests.
2. xlog has a Fatal() output method, which simply calls Error() and then
   os.Exit(1).
3. xlog treats error values as first-class citizen. Since (log/slog).Error()
   is a convenience function for their default logger instance, there is
   no built-in way to treat errors as values. In comparison, (xlog).Error()
   constructs an slog.Attr, since xlog does not provide a default logger.

Point (2) is debatable, since xlog.Fatal is only used in cmd/texd/main.go,
so I'd be willing to forfeit it.

Some TODOs remain:

- xlog, i.e. its extension over log/slog, is not really tested
- documentation is missing
- the current xlog constructor (New) is a bit clunky to use,
  maybe switch to functional options?
- some tests create a local buffer as log output target - this
  could be made easier with a `log, buf := xlog.NewBuffered()`
  constructor (albeit, the overhead is minimal)
- for local development, I still like to have some colorization

Issue: #1
Y'know, for performance. Logging is intense
@dmke dmke force-pushed the refactor/slog branch 2 times, most recently from e233bba to 7ef0add Compare October 31, 2024 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant