Robust and effective logging for Python 2 and 3.
Latest commit b5d49fc Mar 8, 2018



Latest version on PyPi Build status for master branch Documentation Status Updates Anaconda-Server Badge

Robust and effective logging for Python 2 and 3.



  • Easy logging to console and/or (rotating) file.
  • Provides a fully configured standard Python logger object.
  • Pretty formatting, including level-specific colors in the console.
  • Windows color output supported by colorama
  • Robust against str/bytes encoding problems, works with all kinds of character encodings and special characters.
  • Multiple loggers can write to the same logfile (also across multiple Python files).
  • Global default logger with logzero.logger and custom loggers with logzero.setup_logger(..).
  • Compatible with Python 2 and 3.
  • All contained in a single file.
  • Licensed under the MIT license.
  • Heavily inspired by the Tornado web framework.

Demo output in color

Example Usage

from logzero import logger


# This is how you'd log an exception
    raise Exception("this is a demo exception")
except Exception as e:

Adding a rotating logfile is that easy:

import logzero
from logzero import logger

# Setup rotating logfile with 3 rotations, each with a maximum filesize of 1MB:
logzero.logfile("/tmp/rotating-logfile.log", maxBytes=1e6, backupCount=3)

# Log messages"This log message goes to the console and the logfile")

Here are more examples which show how to use logfiles, custom formatters and setting a minimum loglevel:

import logging
import logzero
from logzero import logger

# This log message goes to the console

# Set a minimum log level

# Set a logfile (all future log messages are also saved there)

# You can also set a different loglevel for the file handler
logzero.logfile("/tmp/logfile.log", loglevel=logging.ERROR)

# Set a rotating logfile (replaces the previous logfile handler)
logzero.logfile("/tmp/rotating-logfile.log", maxBytes=1000000, backupCount=3)

# Disable logging to a file

# Set a custom formatter
formatter = logging.Formatter('%(name)s - %(asctime)-15s - %(levelname)s: %(message)s');

# Log some variables"var1: %s, var2: %s", var1, var2)

Take a look at the documentation for more information and examples:


Install logzero with pip:

$ pip install -U logzero

If you don't have pip installed, this Python installation guide can guide you through the process.

Alternatively, if you use the Anaconda distribution:

$ conda config --add channels conda-forge
$ conda install logzero

You can also install logzero from the public Github repo:

$ git clone
$ cd logzero
$ python install

On openSUSE you can install the current version from repos: python2-logzero, python3-logzero. In the newest openSUSE release you can install it with zypper: sudo zypper in python2-logzero.


See the changelog here:


All kinds of feedback and contributions are welcome.