forked from sakshi-mishra/REopt-API-analysis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.py
More file actions
33 lines (25 loc) · 885 Bytes
/
logger.py
File metadata and controls
33 lines (25 loc) · 885 Bytes
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
import logging
"""
Custom logging set up, with handlers for writing to .log file and console.
The _handler.setLevel determines the logging level to write to file or console.
Logging levels are:
Level Numeric value
CRITICAL 50
ERROR 40
WARNING 30
INFO 20
DEBUG 10
NOTSET 0
"""
log = logging.getLogger('my_log_file')
log.setLevel(logging.DEBUG)
file_handler = logging.FileHandler(filename='test_scenario.log', mode='w')
file_formatter = logging.Formatter('%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
file_handler.setFormatter(file_formatter)
file_handler.setLevel(logging.INFO)
console_handler = logging.StreamHandler()
console_formatter = logging.Formatter('%(name)-12s %(levelname)-8s %(message)s')
console_handler.setFormatter(console_formatter)
console_handler.setLevel(logging.INFO)
log.addHandler(file_handler)
log.addHandler(console_handler)