digineo / texd

texd wraps TeX in a web API
MIT License
8 stars 1 forks source link

refactor: replace logger #108

Open dmke opened 7 months ago

dmke commented 7 months ago

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:

Issue: #1

codecov[bot] commented 7 months ago

Codecov Report

Attention: 14 lines in your changes are missing coverage. Please review.

Comparison is base (5712300) 80.92% compared to head (4ce3741) 80.92%.

Files Patch % Lines
service/renderer.go 44.44% 10 Missing :warning:
service/service.go 57.14% 3 Missing :warning:
service/middleware/logging.go 88.88% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #108 +/- ## ======================================= Coverage 80.92% 80.92% ======================================= Files 30 30 Lines 1594 1594 ======================================= Hits 1290 1290 Misses 243 243 Partials 61 61 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.