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 begins

import logging
import loguru
import logging_loguru

logging_loguru.adapt()

import ...
...

catches all logging.Logger 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.2-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: logging_loguru-0.4.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a18128c0e9d0a6abf73059bc540bf0bbe5920c02b3ec3e2cdcdbd60959059d62
MD5 1e09928313fb6ed7ac36615189088695
BLAKE2b-256 d65a0374106941e64aa49fe37306092a1d8555395c06559556390cf903a9daba

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