logzero

1.7.0 · active · verified Sun Apr 12

logzero is a Python library (version 1.7.0) that provides robust and effective logging for both Python 2 and 3. It simplifies logging to the console with pretty, level-specific colored output and supports logging to rotating files. The library also includes built-in JSON logging capabilities, aiming for a low-boilerplate approach to standard Python logging. Its release cadence is generally stable with occasional updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates basic console and rotating file logging, setting a global log level, and handling exceptions with `logger.exception()`.

from logzero import logger, logfile
import os

# Configure a logfile that rotates after 1MB, keeping 3 backups
log_file_path = os.path.join(os.getcwd(), "app.log")
logfile(log_file_path, maxBytes=1_000_000, backupCount=3)

# Set the global minimum log level to INFO
logger.setLevel(os.environ.get('LOG_LEVEL', 'INFO'))

logger.debug("This is a debug message - won't show with INFO level.")
logger.info("Application started successfully.")
logger.warning("Disk space is getting low.")

try:
    1 / 0
except ZeroDivisionError as e:
    logger.exception(f"An error occurred: {e}")

view raw JSON →