Builtin logging
The following api:
sublime.logger('{{PLUGIN_NAME}}').emergency(message)
sublime.logger('{{PLUGIN_NAME}}').alert(message)
sublime.logger('{{PLUGIN_NAME}}').critical(message)
sublime.logger('{{PLUGIN_NAME}}').error(message)
sublime.logger('{{PLUGIN_NAME}}').warning(message)
sublime.logger('{{PLUGIN_NAME}}').notice(message)
sublime.logger('{{PLUGIN_NAME}}').info(message)
sublime.logger('{{PLUGIN_NAME}}').debug(message)
sublime.logger('{{PLUGIN_NAME}}').log($level, message)
`{{PLUGIN_NAME}}` is optional. Default to global logger.
Logging is enabled/disabled as follows:
`sublime.active_window().active_view().settings().get('log_level')`
`sublime.active_window().active_view().settings().get('{{PLUGIN_NAME}}.log_level')`
Default log_level
is info
To disable logger set to null
.
Motivation
Removes a lot of plugin boilerplate.
Typically I use the following boilerplate in a lot of plugins:
DEBUG_MODE=bool(os.getenv('SUBLIME_{{PLUGIN_NAME}}_DEBUG'))
if DEBUG_MODE:
def debug_message(message):
"""
Prints a debug level message.
"""
print('[{{PLUGIN_NAME}}] %s' % str(message))
else:
def debug_message(message):
pass
Vintageous writes its own plugin logger. One problem with that is that it puts log files in Packages/.log/*.log
. Ideally they would be put somewhere more appropriate.