123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- =======
- Logging
- =======
- OpenLEADR uses the standard Python Logging facility. Following the `Python guidelines <https://docs.python.org/3/howto/logging.html#configuring-logging-for-a-library>`_, no default handlers are configured, but you can easily get going if you want to:
- Log to standard output
- ----------------------
- To print logs to your standard output, you can use the following convenience method:
- .. code-block:: python3
- import openleadr
- import logging
- openleadr.enable_default_logging(level=logging.INFO)
- Which is the same as:
- .. code-block:: python3
- import logging
- logger = logging.getLogger('openleadr')
- handler = logging.StreamHandler()
- handler.setLevel(logging.INFO)
- logger.addHandler(handler)
- Setting the logging level
- -------------------------
- You can set different logging levels for the logging generated by OpenLEADR:
- .. code-block:: python3
- import logging
- logger = logging.getLogger('openleadr')
- logger.setLevel(logging.WARNING)
- The different `logging levels <https://docs.python.org/3/library/logging.html#levels>`_ are:
- .. code-block:: python3
- logging.DEBUG
- logging.INFO
- logging.WARNING
- logging.ERROR
- logging.CRITICAL
- Redirecting logs to a different file
- ------------------------------------
- To write logs to a file:
- .. code-block:: python3
- import logging
- logger = logging.getLogger('openleadr')
- handler = logging.FileHandler('mylogfile.txt')
- logger.addHandler(logger)
- More info
- ---------
- Detailed info on logging configuration can be found on `the official Python documentation <https://docs.python.org/3/library/logging.html>`_.
|