Skip to content

Commit

Permalink
When logging repr of an object, prefer to use %r
Browse files Browse the repository at this point in the history
- This will defer any encoding related exceptions, ensuring we don't crash
- Fixes #229
  • Loading branch information
virtuald committed Apr 21, 2017
1 parent 5de495d commit fd49845
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion plugins/daapclient/daap.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ def main():
session = connection.login()

library = session.library()
log.debug("Library name is '%s'", repr(library.name))
log.debug("Library name is `%r`", library.name)

tracks = library.tracks()

Expand Down
2 changes: 1 addition & 1 deletion plugins/daapserver/spydaap/daap.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ def main():
session = connection.login()

library = session.library()
log.debug("Library name is '%s'", repr(library.name))
log.debug("Library name is '%r'", library.name)

tracks = library.tracks()

Expand Down
2 changes: 1 addition & 1 deletion xl/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ def joiner(value):
album = joiner(tr.get_tag_raw('album'))
artist = joiner(tr.get_tag_raw('artist'))
except Exception:
logger.warning("Error while checking for compilation: " + repr(tr))
logger.warning("Error while checking for compilation: %s", tr)
return
if not basedir or not album or not artist: return
album = album.lower()
Expand Down
6 changes: 2 additions & 4 deletions xl/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,8 @@ def _emit(self, event, exc_callbacks, emit_logmsg, emit_verbose):
logger.exception("Event callback exception caught!")

if emit_logmsg:
logger.debug("Sent '%(type)s' event from "
"'%(object)s' with data '%(data)s'." %
{'type' : event.type, 'object' : repr(event.object),
'data' : repr(event.data)})
logger.debug("Sent '%s' event from '%r' with data '%r'",
event.type, event.object, event.data)

def emit_async(self, event):
"""
Expand Down
2 changes: 1 addition & 1 deletion xl/hal.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ def connect(self):
hal_obj = self.bus.get_object('org.freedesktop.Hal',
'/org/freedesktop/Hal/Manager')
self.hal = dbus.Interface(hal_obj, 'org.freedesktop.Hal.Manager')
logger.debug("HAL Providers: %s" % repr(self.get_providers()))
logger.debug("HAL Providers: %r", self.get_providers())
for p in self.get_providers():
try:
self.on_provider_added(p)
Expand Down
2 changes: 1 addition & 1 deletion xl/player/gst/gst_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def parse_stream_tags(track, tag_list):
try:
values = [unicode(v, 'utf-8') for v in values]
except UnicodeDecodeError:
logger.debug("Can't decode: " + repr(values))
logger.debug("Can't decode: `%r`", values)
continue

tags[k] = values
Expand Down
3 changes: 1 addition & 2 deletions xlgui/playlist_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,7 @@ def load_saved_tabs(self):
for i, name in enumerate(names):
match = name_re.match(name)
if not match or not match.group('tab') or not match.group('name'):
logger.error("%s did not match valid playlist file"
% repr(name))
logger.error("`%r` did not match valid playlist file", name)
continue

logger.debug("Adding playlist %d: %s" % (i, name))
Expand Down

0 comments on commit fd49845

Please sign in to comment.