Skip to content

Introduce support for multiple logging providers.#135

Merged
fr33r merged 19 commits intomasterfrom
freer/logger-adapters
Jan 20, 2025
Merged

Introduce support for multiple logging providers.#135
fr33r merged 19 commits intomasterfrom
freer/logger-adapters

Conversation

@fr33r
Copy link
Contributor

@fr33r fr33r commented Jan 18, 2025

Description

Up to this point, we only supported using zap as the logging package. These changes add support for the following packages:

  • log
  • log/slog
  • logrus

Additionally, the unit.WithLogger option allows for supporting arbitrary custom loggers that support the unit.Logger interface.

NOTE: Since log/slog was introduced in 1.21, these changes also update CI to only support 1.21, 1.22, and 1.23 for V4.

Rationale

Supporting only zap imposes this package on clients of this package if they desire to having logging enabled. There are many logging solutions available, so only supporting a single package limiting.

Suggested Version

v4.0.0-beta.7

Example Usage

// use a *log.Logger.
opt := unit.WithStandardLogger(log.Default())

// use a *slog.Logger.
opt = unit.WithStructuredLogger(slog.Default())

// use a *logrus.Logger.
opt = unit.WithLogrusLogger(logrus.StandardLogger())

// use a custom logger satisfying unit.Logger interface.
opt = unit.WithLogger(&adapters.NewLogrusLogger(logrus.StandardLogger()))

@codecov
Copy link

codecov bot commented Jan 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.35%. Comparing base (9687196) to head (cf47207).
Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #135      +/-   ##
==========================================
+ Coverage   98.72%   99.35%   +0.63%     
==========================================
  Files          14       14              
  Lines        1407     1391      -16     
==========================================
- Hits         1389     1382       -7     
+ Misses         14        7       -7     
+ Partials        4        2       -2     
Flag Coverage Δ
v3 98.71% <ø> (ø)
v4 99.86% <100.00%> (+1.14%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@fr33r fr33r marked this pull request as ready for review January 18, 2025 18:51
@fr33r fr33r merged commit 5887997 into master Jan 20, 2025
16 checks passed
@fr33r fr33r deleted the freer/logger-adapters branch January 20, 2025 07:19
@fr33r fr33r self-assigned this Jan 20, 2025
@fr33r fr33r mentioned this pull request Jan 20, 2025
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.

1 participant