-
Notifications
You must be signed in to change notification settings - Fork 19
/
main.py
38 lines (25 loc) · 971 Bytes
/
main.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
import logging
def make_handler(with_level=None):
hdlr_level = with_level if with_level is not None else "no level"
format_str = 'hdlr_level: {}'.format(hdlr_level)
format_str += ' - %(levelname)s - %(message)s'
formatter = logging.Formatter(format_str)
# make a handler with a level
handler = logging.StreamHandler()
handler.setFormatter(formatter)
if with_level is not None:
handler.setLevel(with_level)
return handler
def main():
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
# make a handler with a level
handler_with_level = make_handler(with_level=logging.ERROR)
# and without
handler_without = make_handler()
logger.addHandler(handler_with_level)
logger.addHandler(handler_without)
logger.info('My level my differ from my handler levels!')
logger.error('This should have only been handled by one handler!')
if __name__ == '__main__':
main()