summaryrefslogtreecommitdiffstats
path: root/src/log.py
blob: 9d379eba3e65725fd58faa6e25abd0a24f017f1c (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import logging
import logging.config

DEFAULT_LOGGING_LINUX = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'formatter.syslog': {
            '()': 'logging.Formatter',
            'format': 'ogClient: [{levelname}] - {message}',
            'style': '{',
        },
        'formatter.console': {
            '()': 'logging.Formatter',
            'format': '[{levelname}] - {message}',
            'style': '{',
        },
    },
    'handlers': {
        'console': {
            'level': 'INFO',
            'class': 'logging.StreamHandler',
            'formatter': 'formatter.console',
            'stream': 'ext://sys.stdout',
        },
        'syslog': {
            'level': 'DEBUG',
            'class': 'logging.handlers.SysLogHandler',
            'formatter': 'formatter.syslog',
            'address': '/dev/log',
        },
    },
    'loggers': {
        '': {
            'handlers': ['syslog', 'console'],
            'level': 'DEBUG',
        },
    }
}

DEFAULT_LOGGING_WIN = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'formatter.console': {
            '()': 'logging.Formatter',
            'format': 'ogClient: [{levelname}] - {message}',
            'style': '{',
        }
    },
    'handlers': {
        'console': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
            'formatter': 'formatter.console',
            'stream': 'ext://sys.stdout',
        },
    },
    'loggers': {
        '': {
            'handlers': ['console'],
            'level': 'DEBUG',
        },
    }
}

def configure_logging(mode):
    if mode == 'windows':
        DEFAULT_LOGGING = DEFAULT_LOGGING_WIN
    else:
        DEFAULT_LOGGING = DEFAULT_LOGGING_LINUX
    logging.config.dictConfig(DEFAULT_LOGGING)