logging-loguru
Tiny script for integrating the Python's standard Logging output to the colorful logs by the Loguru library.
RLY 3kb: 1 file, 1 class, 1 function
API
class InterceptHandler(logging.Handler):
def __init__(self, logger=loguru.logger)
def emit(self, record: logging.LogRecord) -> None
def adapt(logger=loguru.logger, log=logging, level=0)
usage
default behavior
# file.py begin
import logging
import loguru
import logging_loguru
logging_loguru.adapt()
import ...
...
catches logging.Logger all log's messages and pipes them all to default loguru.logger handler
choose Logger
log = logging.getLogger("example") # ex: "flask", "WSGI", "peewee" etc, see docs
logging_loguru.adapt(log=log)
catches example's logger messages and pipes them to default loguru.logger handler
tune handler
from loguru import logger as file_logger
LOG_FORMAT = "<green>{time:YYYY-MM-DD HH:mm:ss.SSS}</green> | <level>{level: <8}</level> | <cyan>{name}</cyan>:<cyan>{function}</cyan>:<cyan>{line}</cyan> - <level>{message}</level>"
file_logger.add(
"example.dev-{time}.log",
colorize=False,
compression="gz",
format=LOG_FORMAT,
level="DEBUG",
retention="10 days",
rotation="4 hours",
enqueue=True,
)
log = logging.getLogger("example")
logging_loguru.adapt(logger=file_logger, log=log, level="INFO")
That's all, folks!
ps: yeah, script is very similar to https://github.com/MatthewScholefield/loguru-logging-intercept/, but how could it have been written differently?
Metadata
Release files for logging-loguru 0.4.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| logging_loguru-0.4.6-py3-none-any.whl | Python 3 | none | any | Details |
Release files / logging_loguru-0.4.6-py3-none-any.whl
| Download URL | logging_loguru-0.4.6-py3-none-any.whl |
|---|---|
| Size | 6.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
830696edfac4d0bcd321440bfd2448cbc91480b1729a4db3ae7fc65d97bd1077
|
|
BLAKE2b-256 checksum How to use checksums |
ba632b526416a558eaef5e9d696c1666c025e590afd7ef52ba86e48b96622a6b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.6
|