-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathlog.py
More file actions
22 lines (16 loc) · 728 Bytes
/
log.py
File metadata and controls
22 lines (16 loc) · 728 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import logging
import logging.handlers
from env_vars import *
if not hasattr(logging, "set_up_done"):
logging.set_up_done = False
def init_logging(LOGGING_DIR):
if logging.set_up_done:
return
LOG_FILENAME = os.path.join(LOGGING_DIR, 'cfbreference.com.log').replace('\\', '/')
logging.basicConfig(level=logging.DEBUG)
rotatingFileHandler = logging.handlers.TimedRotatingFileHandler(filename=LOG_FILENAME, when='midnight')
rotatingFileHandler.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
rotatingFileHandler.setFormatter(formatter)
logging.getLogger().addHandler(rotatingFileHandler)
logging.set_up_done = True