forked from propublica/Capitol-Words
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcli.py
More file actions
44 lines (34 loc) · 1004 Bytes
/
Copy pathcli.py
File metadata and controls
44 lines (34 loc) · 1004 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
34
35
36
37
38
39
40
41
42
43
44
import sys
import logging
DEFAULT_LOG_FORMAT = ' '.join([
'%(asctime)s',
'%(levelname)s',
'pid:%(process)d,',
'file:%(filename)s:%(lineno)d>',
'%(message)s',
])
LOGLEVELS = {
'CRITICAL': logging.CRITICAL,
'DEBUG': logging.DEBUG,
'WARN': logging.WARN,
'INFO': logging.INFO,
'ERROR': logging.ERROR,
}
CMD_LINE_DATE_FORMAT = '%Y-%m-%d'
def setup_logger(loglevel):
loglevel = LOGLEVELS.get(loglevel.upper())
if loglevel is None:
loglevel = LOGLEVELS['INFO']
logger = logging.getLogger()
logger.setLevel(loglevel)
formatter = logging.Formatter(DEFAULT_LOG_FORMAT)
console_handler = logging.StreamHandler(stream=sys.stdout)
console_handler.setLevel(loglevel)
console_handler.setFormatter(formatter)
logger.addHandler(console_handler)
def add_logging_options(parser):
parser.add_argument(
'--loglevel',
help='Log level, one of INFO, ERROR, WARN, DEBUG or CRITICAL.',
default='INFO',
)