-
Notifications
You must be signed in to change notification settings - Fork 0
/
log_setup.py
35 lines (31 loc) · 1021 Bytes
/
log_setup.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
"""
Logging setup.
Log to screen and file.
"""
import logging
import logging.handlers
def get_logger():
# For console logging.
logging.basicConfig(
level=logging.WARNING,
format='[%(asctime)s] p%(process)s {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s',
)
# File handler and formatting.
handler = logging.handlers.RotatingFileHandler(
"data/etl.log",
maxBytes=10*1024*1024,
backupCount=5,
)
lformat = logging.Formatter("%(asctime)s] p%(process)s {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s")
handler.setFormatter(lformat)
# Module logging
logging.getLogger("requests").setLevel(logging.WARNING)
logging.getLogger("urllib3").setLevel(logging.WARNING)
backend = logging.getLogger("backend")
backend.setLevel(logging.INFO)
backend.addHandler(handler)
# Harvest/load scripts logging
logger = logging.getLogger('rap')
logger.setLevel(logging.INFO)
logger.addHandler(handler)
return logger