-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.py
34 lines (22 loc) · 860 Bytes
/
logger.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
import logging
import platform
import subprocess
LOG_FILE = './copy-files.log'
FORMAT = '[%(asctime)-15s %(filename)s:%(lineno)s - %(funcName)20s() %(levelname)s] %(message)s'
TRACE = 8
logging.addLevelName(TRACE, 'TRACE')
def trace(self, message, *args, **kws):
if self.isEnabledFor(TRACE):
# Yes, logger takes its '*args' as 'args'.
self._log(TRACE, message, args, **kws)
logging.trace = trace
logging.Logger.trace = trace
log_level = logging.DEBUG
def config(logfile=LOG_FILE, level=log_level):
logging.basicConfig(filename=get_path(logfile),
level=level, format=FORMAT, filemode='a')
def get_path(argpath):
"""Convert path to cygwin format if running on a cygwin platform"""
if 'CYGWIN' in platform.system():
argpath = subprocess.getoutput('cygpath ' + argpath)
return argpath