1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
.. _examples:
Examples
========
Basic logging
-------------
The most basic usage for picologging is to call the debug, info, warning, error, critical and exception functions directly on the picologging module:
.. code-block:: python
import picologging
picologging.basicConfig(level=picologging.DEBUG)
picologging.debug("This is a debug message")
picologging.info("This is an info message")
picologging.warning("This is a warning message")
picologging.error("This is an error message")
picologging.critical("This is a critical message")
This will use the default handler and formatter. You can specify a different formatter with the formatter keyword argument:
.. code-block:: python
import picologging
picologging.basicConfig(level=picologging.DEBUG, formatter=picologging.Formatter("%(levelname)s:%(message)s"))
picologging.debug("This is a debug message")
# Output:
# DEBUG:This is a debug message
Using custom handlers
---------------------
Picologging has custom handlers beyond the StreamHandler and FileHandler. You can write your own handler by implementing the Handler class.
There are a collection of pre-built handlers in the :ref:`handlers` module.
|