Skip to main content

Tiny script for integrating the Python's standard Logging output to the colorful logs by the Loguru library

Project description

logging-loguru

Lines of code Downloads Statistic License Code style: black


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


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

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

logging_loguru-0.4.3-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file logging_loguru-0.4.3-py3-none-any.whl.

File metadata

  • Download URL: logging_loguru-0.4.3-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.6

File hashes

Hashes for logging_loguru-0.4.3-py3-none-any.whl
Algorithm Hash digest
SHA256 168ec3fc2405bcc441f3594e521b480bc212ce14793eeee4023343898f47e2a5
MD5 26201e62773a510f70d75025b8773055
BLAKE2b-256 d4483be8f14b15fe7047849ae6ef65bf77f24b94ba3b49fd78c44a793adb1813

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page