-
-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathlogging.py
More file actions
55 lines (43 loc) · 1.89 KB
/
logging.py
File metadata and controls
55 lines (43 loc) · 1.89 KB
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
# -*- coding: utf-8 -*-
"""Logging System
====================
.. module:: pcapkit.utilities.logging
:mod:`pcapkit.utilities.logging` contains naïve integration
of the Python logging system, i.e. a :class:`logging.Logger`
instance as :data:`~pcapkit.utilities.logging.logger`.
"""
import logging
import os
import sys
__all__ = ['logger']
###############################################################################
# Dev Mode
###############################################################################
# boolean mappings
BOOLEAN_STATES = {'1': True, '0': False,
'yes': True, 'no': False,
'true': True, 'false': False,
'on': True, 'off': False}
#: bool: Development mode flag.
DEVMODE = BOOLEAN_STATES.get(os.environ.get('PCAPKIT_DEVMODE', 'false').casefold(), False)
#: bool: Verbose output flag.
VERBOSE = BOOLEAN_STATES.get(os.environ.get('PCAPKIT_VERBOSE', 'false').casefold(), False)
###############################################################################
# Sphinx Mode
###############################################################################
#: bool: This is a workaround for :data:`typing.TYPE_CHECKING` in Sphinx.
SPHINX_TYPE_CHECKING = BOOLEAN_STATES.get(os.environ.get('PCAPKIT_SPHINX', 'false').casefold(), False)
###############################################################################
# Logger Setup
###############################################################################
#: logging.Logger: :class:`~logging.Logger` instance named after ``pcapkit``.
logger = logging.getLogger('pcapkit')
formatter = logging.Formatter(fmt='[%(levelname)s] %(asctime)s - %(message)s',
datefmt='%m/%d/%Y %I:%M:%S %p')
handler = logging.StreamHandler(sys.stderr)
if DEVMODE:
logger.setLevel(logging.DEBUG)
else:
logger.setLevel(logging.INFO)
handler.setFormatter(formatter)
logger.addHandler(handler)