MPDScrobbler: log formating
authorkaliko <kaliko.jack@azylum.org>
Sat, 5 Jan 2013 17:37:08 +0000 (18:37 +0100)
committerkaliko <kaliko.jack@azylum.org>
Sat, 5 Jan 2013 17:37:08 +0000 (18:37 +0100)
misc/MPDScrobbler/mpdscrobbler.py

index 95246d1..bdf31f5 100755 (executable)
@@ -51,7 +51,6 @@ LEVELS = {'debug': logging.DEBUG,
           'critical': logging.CRITICAL}
 
 logging.basicConfig(format='%(asctime)s  %(levelname)s  %(message)s', level=LEVELS.get(LOGLEVEL))
-DATE_FMT = "%Y-%m-%d %H:%M:%S"
 
 class QueuManagement(threading.Thread):
 
@@ -65,11 +64,11 @@ class QueuManagement(threading.Thread):
         try:
             scrobble(trk=track, user=USER, pwd=PWD, srv=SCSERVER)
         except URLError as err:
-            logging.warning('Failed catching up with "%s": %s' % (track, err))
+            logging.warning('scrobbler: Failed catching up with "%s": %s' % (track, err))
             self.queu.appendleft(track)
             return False
         except Exception as err:
-            logging.warning('Unhandled exception: %s' % err)
+            logging.warning('scrobbler: Unhandled exception: %s' % err)
             self.queu.appendleft(track)
             return False
         logging.info('Catching up with {0}'.format(track))
@@ -96,7 +95,7 @@ class MpdScrobbler(Player):
             self.connect()
             logging.info("Connected to %s" % MPDSERVER)
         except Exception as err:
-            logging.error(err)
+            logging.error('player: {0}'.format(err))
             sys.exit(1)
         try:
             self.run()
@@ -106,7 +105,7 @@ class MpdScrobbler(Player):
 
     def scrobble(self):
         if self.failed_sc_cache:
-            logging.info('Got %i in queu' % len(self.failed_sc_cache))
+            logging.debug('Got %i in queu' % len(self.failed_sc_cache))
         logging.info(self.current_track)
         art = self.current_track.get_artist()
         tit = self.current_track.get_title()
@@ -118,12 +117,13 @@ class MpdScrobbler(Player):
             scrobble(trk=self.current_track, user=USER, pwd=PWD, srv=SCSERVER)
         except HTTPError as err:
             if hasattr(err, 'read'):
-                logging.error(u'%s: %s' % (err, err.read().decode('utf-8')))
+                logging.error(u'scrobbler: http-error %s' % err)
+                logging.debug(u'scrobbler: http-error %s→\ns' % (err, err.read().decode('utf-8')))
             else:
-                logging.error(err)
+                logging.error('scrobbler: {0}'.format(err))
             self.failed_sc_cache.append(self.current_track)
         except URLError as err:
-            logging.error(err)
+            logging.error('scrobbler: {0}'.format(err))
             self.failed_sc_cache.append(self.current_track)
         else:
             # Deal with the queu if last scrobble went fine
@@ -149,7 +149,7 @@ class MpdScrobbler(Player):
             try:
                 self.idle()
             except Exception as err:
-                logging.error(err)
+                logging.error('player: {0}'.format(err))
                 sys.exit(1)
             if self.status().get('state') != 'play':
                 logging.info('not playing')