]> kaliko git repositories - sid.git/blobdiff - sid/sid.py
Better use of logging
[sid.git] / sid / sid.py
index 82dcab560d3ee1810e1b21bd32d32c184f053804..373209d2e6797c6040c27510b8e492d11745635e 100644 (file)
@@ -2,7 +2,7 @@
 
 # Copyright (C) 2007-2012 Thomas Perl <thp.io/about>
 # Copyright (C) 2010, 2011 AnaĆ«l Verrier <elghinn@free.fr>
-# Copyright (C) 2014 kaliko <kaliko@azylum.org>
+# Copyright (C) 2014-2015 kaliko <kaliko@azylum.org>
 
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -75,7 +75,7 @@ class MUCBot(sleekxmpp.ClientXMPP):
         for name, value in inspect.getmembers(self):
             if inspect.ismethod(value) and getattr(value, '_bot_command', False):
                 name = getattr(value, '_bot_command_name')
-                self.log.debug('Registered command: %s' % name)
+                self.log.debug('Registered command: %s', name)
                 self.commands[name] = value
 
     def __set_logger(self, log_file=None, log_level=logging.INFO):
@@ -87,7 +87,7 @@ class MUCBot(sleekxmpp.ClientXMPP):
         chandler.setFormatter(formatter)
         self.log.addHandler(chandler)
         self.log.setLevel(log_level)
-        self.log.debug('set logger, log level : %s' % log_level)
+        self.log.debug('set logger, log level : %s', log_level)
 
     def message(self, msg):
         if msg['type'] not in ('groupchat', 'chat'):
@@ -99,21 +99,20 @@ class MUCBot(sleekxmpp.ClientXMPP):
         if not body.startswith(MUCBot.prefix):
             return
         if msg['from'] not in self.__seen:
-            self.log.warning('Will not handle message '
-                             'from unseen jid: %s' % msg['from'])
+            self.log.warning('Will not handle message from unseen jid: %s', msg['from'])
             #return
         args = body[1:].split()
         cmd = args.pop(0)
         if cmd not in self.commands:
             return
-        self.log.debug('cmd: {0}'.format(cmd))
+        self.log.debug('cmd: %s', cmd)
         if args:
-            self.log.debug('arg: {0}'.format(args))
+            self.log.debug('arg: %s', args)
         try:
             self.commands[cmd](msg, args)
         except Exception as err:
             reply = ''.join(traceback.format_exc())
-            self.log.exception('An error occurred processing: {0}: {1}'.format(body, reply))
+            self.log.exception('An error occurred processing: %s: %s', body, reply)
             if self.log.level < 10 and reply:
                 self.send_message(mto=msg['from'].bare, mbody=reply, mtype='groupchat')
 
@@ -149,19 +148,19 @@ class MUCBot(sleekxmpp.ClientXMPP):
             if inspect.ismethod(value) and getattr(value, '_bot_command',
                                                    False):
                 name = getattr(value, '_bot_command_name')
-                self.log.debug('Registered command: %s' % name)
+                self.log.debug('Registered command: %s', name)
                 self.commands[name] = value
 
     def foreach_plugin(self, method, *args, **kwds):
         for plugin in self.plugins:
-            self.log.debug('shuting down %s' % plugin.__str__)
+            self.log.debug('shuting down %s', plugin.__str__)
             getattr(plugin, method)(*args, **kwds)
 
     def shutdown_plugins(self):
         # TODO: why can't use event session_end|disconnected?
         self.log.info('shuting down')
         for plugin in self.plugins:
-            self.log.debug('shuting down %s' % plugin)
+            self.log.debug('shuting down %s', plugin)
             getattr(plugin, 'shutdown')()
 
     @botcmd