Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
docs: how to add custom handlers (eg. RotatingFileHandler)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Hager committed Jul 2, 2017
1 parent f75d264 commit fc7eccf
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ This is how you can log variables too:
Setting the minimum loglevel
------------------

----------------------------

You can set the minimum logging level to any of the standard `Python log levels <https://docs.python.org/2/library/logging.html#logging-levels>`_.
For instance if you want to set the minimum logging level to `INFO` (default is `DEBUG`):
Expand All @@ -148,6 +147,32 @@ For instance if you want to set the minimum logging level to `INFO` (default is
setup_logger(level=logging.INFO)
Adding custom handlers (eg. RotatingLogFile)
--------------------------------------------

Since `logzero` uses the standard `Python logger object <https://docs.python.org/2/library/logging.html#module-level-functions>`_,
you can attach any `Python logging handlers <https://docs.python.org/2/library/logging.handlers.html>`_ you can imagine!

This is how you add a `RotatingFileHandler <https://docs.python.org/2/library/logging.handlers.html#rotatingfilehandler>`_:

.. code-block:: python
import logzero
import logging
from logging.handlers import RotatingFileHandler
# Setup the RotatingFileHandler
rotating_file_handler = RotatingFileHandler("/tmp/app-rotating.log", maxBytes=100000, backupCount=2)
rotating_file_handler.setLevel(logging.DEBUG)
rotating_file_handler.setFormatter(logzero.LogFormatter())
# Attach it to the logzero default logger
logzero.logger.addHandler(rotating_file_handler)
# Log stuff
logzero.logger.info("this is a test")
Documentation
=================

Expand Down

0 comments on commit fc7eccf

Please sign in to comment.