-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloggingConfig.py
28 lines (20 loc) · 929 Bytes
/
loggingConfig.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
import logging
import os
logging_dir = '/usr/local/imagerCache/logs/'
log_format = '%(asctime)s.%(msecs)03d - %(levelname)s : %(message)s'
date_format = '%m/%d/%y %H:%M:%S'
def setup_logger(name, log_file, level=logging.INFO):
"""To setup as many loggers as you want"""
# Make sure directory exists
os.makedirs(logging_dir, mode=0o777, exist_ok=True)
# Config the handler which specifies the format of the file
handler = logging.FileHandler(logging_dir + log_file)
handler.setFormatter(logging.Formatter(log_format, date_format))
# Actually create the logger
logger = logging.getLogger(name)
logger.setLevel(level)
logger.addHandler(handler)
return logger
# Create the main logger, which is the root logger since no name is given
logger = setup_logger(None, 'imager.log', level=logging.DEBUG)
logger.info('====================== Starting Imager =============================')