forked from guillermooo/Vintageous
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
60 lines (44 loc) · 1.56 KB
/
__init__.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import logging
import sublime
LOG_LEVEL = None
# XXX: Can't we do this better?
def plugin_loaded():
global LOG_LEVEL
LOG_LEVEL = get_logging_level()
def get_logging_level():
global LOG_LEVEL
if LOG_LEVEL is not None:
return LOG_LEVEL
v = sublime.active_window().active_view()
level = v.settings().get('vintageous_log_level', 'ERROR')
return getattr(logging, level.upper(), logging.ERROR)
def get_logger(name):
global LOG_LEVEL
logger = logging.getLogger(name)
logger.setLevel(LOG_LEVEL)
return logger
# XXX: Why don't we use a logging config file?
# Work around ST3 delayed loading of plugins. We cannot call the API until
# after the plugin file has been loaded. We just need the api to retrieve
# the setting indicating the logging level. It's probably best to have
# a proper config file for loggers instead of this.
def local_logger(name):
"""
Returns a generator that in turn returns a valid logger for @name. Once
the ST3 API is active, `local_logger` will always return the same
logger. In the meantime, it will return a logger with a default config so
calls to it won't fail.
"""
_logger = None
def loggers():
nonlocal _logger
while True:
try:
if _logger is None:
_logger = get_logger(name)
yield _logger
except TypeError:
temp_logger = logging.getLogger(name)
temp_logger.setLevel(logging.ERROR)
yield temp_logger
return lambda: next(loggers())