Tiny script for integrating the Python's standard Logging output to the colorful logs by the Loguru library
Project description
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?
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file logging_loguru-0.4.4-py3-none-any.whl.
File metadata
- Download URL: logging_loguru-0.4.4-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
92b6a5c7c19a4d3331e1b5b0b4044b6e7124e6a279d3a38f34401823bf0af2e0
|
|
| MD5 |
c6bf4bfca99aeda25f1b1a2d29edd576
|
|
| BLAKE2b-256 |
df1cecca9794de07f03decd657b8915910b92808fd65ef3b103f7364f78e7a24
|