$ show Delgan/loguru
Loguru is a Python logging library that provides a pre-instantiated global logger with minimal boilerplate. Its architecture centers on a singleton `logger` object (defined in `_logger.py`) that delegates to a `Core` managing levels, handlers, and activation state. The primary entry point is `logger.add()`, which registers sinks (streams, files, callables, coroutines, or standard logging handlers) with optional formatting, filtering, rotation, retention, compression, enqueueing, and async support. Log messages are generated via level methods (`trace`, `debug`, `info`, `warning`, `error`, `critical`, `exception`) and flow through a `Handler` class (`_handler.py`) that applies formatting (colorized via `_colorizer.py`), filtering (level, function, or callable), and dispatching to the underlying sink. External dependencies are minimal and optional: `colorama` for Windows ANSI support, `win32_setctime` for file creation times, `exceptiongroup` for Python <3.11, and `aiocontextvars` for Python <3.7. The library also offers advanced exception formatting (`_better_exceptions.py`) with variable diagnostics, backtrace display, and chained/grouped exception support. It is designed for both application and library use, with `disable()`/`enable()` per module and `LOGURU_*` environment variable configuration. The codebase demonstrates high craftsmanship with clean abstractions, thorough test coverage (including snapshot-based exception formatting tests), and compatibility across Python 3.5–3.14.
The LLM identified 3 files worth highlighting for reuse:
Implements a lightweight markup language (`<red>`, `<b>`, hex colors, `fg`/`bg`) that can be embedded in log format strings. The `Colorizer` class compiles markup patterns into ANSI escape sequences, supports `str.format` integration, and provides color stripping/wrapping. This module is fully self-contained (no internal imports beyond standard library) and could be extracted and reused in any project requiring colorized text output with a simple markup syntax.
Defines a custom `datetime` subclass with a token-based formatter (e.g., `YYYY`, `MM`, `DD`, `HH`, `mm`, `ss`, `SSS`, `Z`, `!UTC`) that is more expressive than `strftime`. It compiles format strings into a sequence of tokens for efficient formatting, supports timezone conversion via `!UTC` suffix, and falls back to `strftime` for unrecognized tokens. This module is isolated and reusable as a general-purpose datetime formatting utility.
Provides functions to parse human-readable strings into programmatic values: `parse_size` (e.g., '500 MB'), `parse_duration` (e.g., '1h 30min'), `parse_frequency` (e.g., '1 week', 'every day'), and `parse_daytime` (e.g., '12:00'). Each parser is a standalone utility that returns a numeric or timedelta/timedelta-like value. These are used by the file sink's rotation/retention machinery but are completely decoupled and reusable in any Python project that needs to interpret user-facing configuration strings.