Skip to content

Loguru logging - #122

Draft
Hendrik-code wants to merge 5 commits into
mainfrom
loguru-logging
Draft

Loguru logging#122
Hendrik-code wants to merge 5 commits into
mainfrom
loguru-logging

Conversation

@Hendrik-code

Copy link
Copy Markdown
Owner

No description provided.

Hendrik-code and others added 5 commits June 29, 2026 11:51
…vels)

Add loguru dep and a new TPTBox/logger/_loguru_backend.py: each Log_Type maps to
a custom TPTBOX_* Loguru level whose color markup reproduces the exact ANSI of
type2bcolors (light-cyan->96, bg blue->44, ...). print_to_terminal now emits via
a colorized Loguru function-sink (writing to the live sys.stdout, honoring end so
end='\r' progress lines are intact). WARNING_THROW still routes to warnings.warn.

Public API/classes/verbose semantics unchanged. Verified: 28/28 golden cases
render identically (only invisible reset-code differences) and all 15 non-default
Log_Types emit the exact expected color code.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…on/retention)

Logger now writes via a Loguru file sink instead of raw file.write. Default
keeps its own handle behind a Loguru function-sink (flush() works, 'end'
honored, ANSI-free, atexit-safe duration line). New rotation=/retention=/enqueue
kwargs switch to a Loguru-owned path sink for rotation & retention. Per-instance
record filtering keeps multiple Loggers' files isolated.

Verified: exact filename scheme + header/duration lines, no ANSI in files,
rotation produces multiple files, two-logger isolation, and the duration line is
still written at interpreter exit for unclosed loggers.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…r sinks

print_error now also emits a structured Loguru record (opt(exception=True), bound
to an 'exception' channel the default sinks ignore) so user sinks capture the
traceback; the human-readable text output is unchanged. Add install_excepthook()
to route uncaught exceptions through Loguru (opt-in). Re-export configure,
install_excepthook, and the configured loguru_logger from TPTBox.logger so callers
can attach their own sinks (JSON via serialize=True, level filtering on TPTBOX_*).

Configure now runs eagerly at import so the take-over logger.remove() only drops
Loguru's own default handler and never wipes user sinks added afterwards.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add unit_tests/test_logger.py (10 tests) asserting the backwards-compat contract:
per-Log_Type terminal coloring matches type2bcolors, carriage-return end
preserved, WARNING_THROW->warnings.warn, verbose gating, ANSI-free + isolated
file output, and structured exception capture into user sinks. Document the
Loguru backend, TPTBOX_* levels, take-over opt-out, rotation/retention, user
sinks, and exception capture in the logger README.

Full unit suite: 405 passed / 4 skipped; thread safety verified (3200 concurrent
lines, no interleaving).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@Hendrik-code Hendrik-code self-assigned this Aug 10, 2026
@Hendrik-code Hendrik-code added the documentation Improvements or additions to documentation label Aug 10, 2026
@Hendrik-code Hendrik-code linked an issue Aug 10, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use Loguru

1 participant