-
Notifications
You must be signed in to change notification settings - Fork 6
/
base.py
55 lines (44 loc) · 1.22 KB
/
base.py
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
## @package PyHoot.base
# Base module
## @file base.py Implementation of @ref PyHoot.base
import logging
class Base(object):
"""Base of all objects"""
## Log prefix to use.
LOG_PREFIX = 'my'
@property
def logger(self):
"""Logger."""
return self._logger
def __init__(self):
"""Contructor."""
self._logger = logging.getLogger(
'%s.%s' % (
self.LOG_PREFIX,
self.__module__,
),
)
def setup_logging(stream=None, level=logging.INFO):
"""Setup logging system.
@returns (logger) program logger.
"""
logger = logging.getLogger(Base.LOG_PREFIX)
logger.propagate = False
logger.setLevel(level)
try:
h = logging.StreamHandler(stream)
h.setLevel(logging.DEBUG)
h.setFormatter(
logging.Formatter(
fmt=(
'%(asctime)-15s '
'[%(levelname)-7s] '
'%(name)s::%(funcName)s:%(lineno)d '
'%(message)s'
),
),
)
logger.addHandler(h)
except IOError:
logging.warning('Cannot initialize logging', exc_info=True)
return logger