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

Code size Downloads 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, 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

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.6-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: logging_loguru-0.4.6-py3-none-any.whl
  • Upload date:
  • Size: 6.7 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.6-py3-none-any.whl
Algorithm Hash digest
SHA256 830696edfac4d0bcd321440bfd2448cbc91480b1729a4db3ae7fc65d97bd1077
MD5 322eb82401614a2841c4443f3553a6f1
BLAKE2b-256 ba632b526416a558eaef5e9d696c1666c025e590afd7ef52ba86e48b96622a6b

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