File: examples.rst

package info (click to toggle)
python-picologging 0.9.4-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 752 kB
  • sloc: python: 3,921; cpp: 2,430; makefile: 41; sh: 18
file content (39 lines) | stat: -rw-r--r-- 1,222 bytes parent folder | download
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.