blob: 409a2531029615f92f9ce26ce35623ea21380435 (
plain)
| 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
40
41
42
43
44
 | #!/usr/bin/env python
"""
Helper functions for zmq video messaging.
"""
__author__ = "Franoosh Corporation"
import logging
class CustomLoggingFormatter(logging.Formatter):
    """Custom logging formatter"""
    debug_fmt = 'DEBUG: %(filename)s:%(lineno)d %(asctime)s %(message)s'
    info_fmt = 'INFO: %(asctime)s %(message)s'
    warning_fmt = 'WARNING: %(asctime)s %(message)s'
    error_fmt = 'ERROR: %(asctime)s %(message)s'
    critical_fmt = 'CRITICAL: %(asctime)s %(message)s'
    def __init__(self):
        super().__init__(
            fmt="%(levelno)d: %s(asctime)s %(message)s",
            datefmt=None,
        )
    def format(self, record):
        orig_fmt = self._style._fmt
        if record.levelno == logging.DEBUG:
            self._style._fmt = CustomLoggingFormatter.debug_fmt
        elif record.levelno == logging.INFO:
            self._style._fmt = CustomLoggingFormatter.info_fmt
        elif record.levelno == logging.WARNING:
            self._style._fmt = CustomLoggingFormatter.warning_fmt
        elif record.levelno == logging.ERROR:
            self._style._fmt = CustomLoggingFormatter.error_fmt
        elif record.levelno == logging.CRITICAL:
            self._style._fmt = CustomLoggingFormatter.critical_fmt
        result = logging.Formatter.format(self, record)
        self._style._fmt = orig_fmt
        return result
 |