Verbosity affects plugins (#1208)

This restores the -v flag affecting plugins. By default, plugin loggers use
the NOTSET level, which just reuses the base `beets` logger level. The level
is only auto-adjusted for the importer when not in verbose mode.
This commit is contained in:
Adrian Sampson 2015-01-11 15:00:20 -08:00
parent 24317fd4c7
commit f871ef9e21
3 changed files with 15 additions and 6 deletions

View file

@ -64,7 +64,7 @@ class BeetsPlugin(object):
logger_name = '{0}.{1}'.format('beets', self.name)
self._log = logging.getLogger(logger_name)
self._log.setLevel(logging.INFO)
self._log.setLevel(logging.NOTSET) # Use `beets` logger level.
def commands(self):
"""Should return a list of beets.ui.Subcommand objects for
@ -84,12 +84,21 @@ class BeetsPlugin(object):
for import_stage in self.import_stages]
def _set_log_level(self, log_level, func):
"""Wrap `func` to temporarily set this plugin's logger level to
`log_level` (and restore it after the function returns).
The level is *not* adjusted when beets is in verbose
mode---i.e., the plugin logger continues to delegate to the base
beets logger.
"""
@wraps(func)
def wrapper(*args, **kwargs):
old_log_level = self._log.getEffectiveLevel()
self._log.setLevel(log_level)
if not beets.config['verbose']:
old_log_level = self._log.level
self._log.setLevel(log_level)
result = func(*args, **kwargs)
self._log.setLevel(old_log_level)
if not beets.config['verbose']:
self._log.setLevel(old_log_level)
return result
return wrapper

View file

@ -191,7 +191,7 @@ class BeatportPlugin(BeetsPlugin):
try:
return self._get_releases(query)
except BeatportAPIError as e:
self._log.debug(u'Beatport API Error: {0} (query: {1})', e, query)
self._log.debug(u'API Error: {0} (query: {1})', e, query)
return []
def item_candidates(self, item, artist, title):

View file

@ -131,7 +131,7 @@ class InfoPlugin(BeetsPlugin):
try:
data = data_emitter()
except mediafile.UnreadableFileError as ex:
self._log.error(u'cannot read file: {0}', ex.message)
self._log.error(u'cannot read file: {0}', ex)
continue
if opts.summarize: