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

Support loguru log capture #28

Closed
etianen opened this issue Jan 24, 2024 · 2 comments · Fixed by #94
Closed

Support loguru log capture #28

etianen opened this issue Jan 24, 2024 · 2 comments · Fixed by #94
Labels
enhancement New feature or request
Milestone

Comments

@etianen
Copy link
Owner

etianen commented Jan 24, 2024

Supporting a basic loguru integration would be very easy by providing a context manager via a helper func using their LogHandler integration.

Alternatively, a Logot subclass called Logurot would be cheese and fun. That would allow the pytest plugin to provide a logurot fixture too (if loguru is installed).

@etianen etianen added the enhancement New feature or request label Jan 24, 2024
@etianen
Copy link
Owner Author

etianen commented Jan 27, 2024

Further API discussion and feedback from loguru devs in Delgan/loguru#1072 ❤️

@etianen etianen changed the title Support loguru Support loguru log capture Jan 27, 2024
@etianen
Copy link
Owner Author

etianen commented Jan 27, 2024

Proposed API

from logot.contrib.loguru import LoguruCapture

with Logot().capturing(LoguruCapture):
   pass

Any arguments given to capturing would be propagated to the LoguruCapture constructor. This would then unify capture between stdlib logging and loguru logging. The default capture backend would be the stdlib capture, and an @overload would ensure good typing. 💪

etianen added a commit that referenced this issue Jan 28, 2024
Although it's neat to validate all `int` log levels are registered with
the `logging` module, this falls flat for 3rd party logging frameworks
(e.g. `loguru`, see #28)
etianen added a commit that referenced this issue Jan 28, 2024
…ackends (#38)

- Added `Captured`, representing an abstract captured log.
- Added `_format` internal module, providing shared formatting logic for
`__str__` implementations.
- Bulk-renaming to represent decoupling from `logging` module. 😅 
- Removed log de-duplication, since it's non-portable and shouldn't be a
problem for users / is actually a feature.
- Added "Log capturing" docs page.

This is needed by #28.
etianen added a commit that referenced this issue Jan 29, 2024
`Captured` now takes an explicit `levelname` and `levelno`. This allows
3rd-party logging framework integrations to be freed of the obligation
to match stdlib `logging` levels.

The validation of `validate_levelno` was relaxed to just validate the
type of the input, and correspondingly renamed to `validate_level`.

The `DEFAULT_XXX` class attributes on `Logot` were updated to prefer
`str` and use string constants for easier reading in docs. The typing of
log levels everywhere was updated to prefer `str` for better
compatibility with 3rd-party logging frameworks.

The named logging helpers in `logged` were updated to use string level
names for better compatibility with 3rd-party logging frameworks.

Needed by #28.
etianen added a commit that referenced this issue Feb 2, 2024
- Reduced dependency on stdlib `logging` module to hopefully remove all
runtime dependencies when using 3rd-party logging frameworks (see #28)
  - No longer using `logging.getLoggerName()` to format log levels.
- No longer supporting `logging.Logger` type in default `Logot` class
attrs.
- Added `pytest` fixtures and config for `Logot` configuration
- Tested using `pytester` fixture.
- Updated docs.
@etianen etianen added this to the v1.0 milestone Feb 5, 2024
etianen added a commit that referenced this issue Feb 7, 2024
- Added abstract `Capturer` class.
- Removed `logging.Logger` type from all logger types, to fully break
the eager importing of `logging`.

Refs #28 
Closes #82
etianen added a commit that referenced this issue Feb 9, 2024
- Added `LoguruCapturer`.
- Refactored `logging` tests to include testing for filtering, catching
a bug!
- Switched to using low-level `_thread` module versus `threading`,
slightly trimming import size at no loss of clarity.

Closes #28
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 a pull request may close this issue.

1 participant