- Notifications
You must be signed in to change notification settings - Fork 236
/
Copy pathlogger.py
48 lines (32 loc) · 1.29 KB
/
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
35
36
37
38
39
40
41
42
43
44
45
"""
Exposes logging and debugging operations.
Use the 'debug', 'info', 'warning', 'error', or 'critial' methods on the 'log'
object to send messages to the stderr (which appear in the console in Sublime).
A log file is also created in the plugin folder for messages at the level set
by the properties below.
"""
importlogging
fromosimportpath
from .global_varsimportLOG_CONSOLE_LEVEL, LOG_FILE_LEVEL
# The default path to the log file created for diagnostic output
_pluginRoot=path.dirname(path.dirname(path.abspath(__file__)))
filePath=path.join(_pluginRoot, 'TS.log')
log=logging.getLogger('TS')
log.setLevel(logging.WARN)
_logFormat=logging.Formatter('%(asctime)s: %(thread)d: %(levelname)s: %(message)s')
logFile=logging.FileHandler(filePath, mode='w')
logFile.setLevel(logging.DEBUG)
logFile.setFormatter(_logFormat)
log.addHandler(logFile)
console=logging.StreamHandler()
console.setLevel(logging.INFO)
console.setFormatter(_logFormat)
log.addHandler(console)
log.info('Logging configured to log to file: {0}'.format(filePath))
defview_debug(view, message):
filename=view.file_name()
view_name=view.name()
name=view_nameiffilenameisNoneelsefilename
log.debug(message+": "+name)
logFile.setLevel(LOG_FILE_LEVEL)
console.setLevel(LOG_CONSOLE_LEVEL)