log.py 664 Bytes
Newer Older
Michal Horejsek's avatar
Michal Horejsek committed
1 2 3 4
"""
Log utilities.
"""

5 6 7 8 9 10
import logging

from twisted.python import log


def init_python_logging(filename, level):
Michal Horejsek's avatar
Michal Horejsek committed
11 12 13 14 15
    """
    Starts Twisted observer sending all log messages to Python
    logging system and makes basic configuration as file name
    and log level.
    """
16 17 18 19 20 21 22 23 24 25
    observer = log.PythonLoggingObserver()
    observer.start()

    logging.basicConfig(
        filename=filename,
        level={
            'error': logging.ERROR,
            'warning': logging.WARNING,
            'debug': logging.DEBUG,
        }.get(level, logging.INFO),
Michal Horejsek's avatar
Michal Horejsek committed
26 27
        format='%(asctime)s %(levelname)s %(name)s %(message)s',
        datefmt='%Y-%m-%dT%H:%M:%S',
28
    )