forked from anjesh/pdf-processor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProcessLogger.py
More file actions
30 lines (22 loc) · 839 Bytes
/
ProcessLogger.py
File metadata and controls
30 lines (22 loc) · 839 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
import logging
import logging.handlers
import os
import sys
LOG_DIR = 'logs'
def getLogger(loggername, filename = 'processing.log'):
scriptPath = os.path.dirname(os.path.abspath(__file__))
if not os.path.exists(os.path.join(scriptPath, LOG_DIR)):
os.makedirs(os.path.join(scriptPath, LOG_DIR))
logfile = os.path.join(scriptPath, LOG_DIR, filename)
logger = logging.getLogger(loggername)
logger.setLevel(logging.DEBUG)
handler = logging.FileHandler(logfile)
handler.setLevel(logging.DEBUG)
consolehandler = logging.StreamHandler()
consolehandler.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s %(name)s %(levelname)s - %(message)s')
handler.setFormatter(formatter)
consolehandler.setFormatter(formatter)
logger.addHandler(handler)
logger.addHandler(consolehandler)
return logger