Commits

Jun Omae committed f333647

passes format string and the arguments for logging api instead of formatted text

Comments (0)

Files changed (2)

trac/notification/api.py

                 continue
             if adverb == 'always':
                 self.log.debug("Adding (%s [%s]) for 'always' on rule (%s) "
-                               "for (%s)" % (sid, auth, rule, transport))
+                               "for (%s)", sid, auth, rule, transport)
                 yield (sid, auth, addr, transport, fmt)
             else:
                 self.log.debug("Ignoring (%s [%s]) for 'never' on rule (%s) "
-                               "for (%s)" % (sid, auth, rule, transport))
+                               "for (%s)", sid, auth, rule, transport)
             # Also keep subscriptions without sid (raw email subscription)
             if sid:
                 previous_combination = (transport, sid, auth)

trac/notification/mail.py

             if domain:
                 address = "%s@%s" % (address, domain)
             else:
-                self.env.log.info("Email address w/o domain: %s" % address)
+                self.env.log.info("Email address w/o domain: %s", address)
                 return None
 
         mo = self.shortaddr_re.search(address)
         mo = self.longaddr_re.search(address)
         if mo:
             return (sid, auth, mo.group(2))
-        self.env.log.info("Invalid email address: %s" % address)
+        self.env.log.info("Invalid email address: %s", address)
         return None
 
 
                 if realm == event.realm:
                     formats[style] = f
         if not formats:
-            self.log.error(
-                "EmailDistributor No formats found for %s %s" % (
-                    transport, event.realm))
+            self.log.error("EmailDistributor No formats found for %s %s",
+                           transport, event.realm)
             return
-        self.log.debug(
-            "EmailDistributor has found the following formats capable "
-            "of handling '%s' of '%s': %s" % (transport, event.realm,
-                ', '.join(formats.keys())))
+        self.log.debug("EmailDistributor has found the following formats "
+                       "capable of handling '%s' of '%s': %s",
+                       transport, event.realm, ', '.join(formats.keys()))
 
         msgdict = {}
         for sid, authed, addr, fmt in recipients:
             if fmt not in formats:
                 self.log.debug(
-                    "EmailDistributor format %s not available for %s %s" % (
-                        fmt, transport, event.realm))
+                    "EmailDistributor format %s not available for %s %s",
+                    fmt, transport, event.realm)
                 continue
 
             if sid and not addr:
                 for resolver in self.resolvers:
                     addr = resolver.get_address_for_session(sid, authed)
                     if addr:
-                        self.log.debug("EmailDistributor found the "
-                            "address '%s' for '%s (%s)' via: %s" % (
-                            addr, sid, 'authenticated' if authed else
-                            'not authenticated',
-                            resolver.__class__.__name__))
+                        self.log.debug(
+                            "EmailDistributor found the address '%s' for '%s "
+                            "(%s)' via: %s", addr, sid,
+                            'authenticated' if authed else 'not authenticated',
+                            resolver.__class__.__name__)
                         break
             if addr:
                 msgdict.setdefault(fmt, set()).add(addr)
             else:
                 self.log.debug("EmailDistributor was unable to find an "
-                        "address for: %s (%s)" % (sid,
-                        'authenticated' if authed else  'not authenticated'))
+                               "address for: %s (%s)", sid,
+                               'authenticated' if authed
+                                               else 'not authenticated')
 
         for fmt, addrs in msgdict.iteritems():
-            self.log.debug(
-                "EmailDistributor is sending event as '%s' to: %s" % (
-                    fmt, ', '.join(addrs)))
+            self.log.debug("EmailDistributor is sending event as '%s' to: %s",
+                           fmt, ', '.join(addrs))
             self._do_send(transport, event, fmt, addrs, formats[fmt])
 
     def _do_send(self, transport, event, format, recipients, formatter):
         # Ensure the message complies with RFC2822: use CRLF line endings
         message = fix_eol(message, CRLF)
 
-        self.log.info("Sending notification through SMTP at %s:%d to %s"
-                      % (self.smtp_server, self.smtp_port, recipients))
+        self.log.info("Sending notification through SMTP at %s:%d to %s",
+                      self.smtp_server, self.smtp_port, recipients)
         server = smtplib.SMTP(self.smtp_server, self.smtp_port)
         # server.set_debuglevel(True)
         if self.use_tls:
         server.sendmail(from_addr, recipients, message)
         t = time.time() - start
         if t > 5:
-            self.log.warning('Slow mail submission (%.2f s), '
-                             'check your mail setup' % t)
+            self.log.warning('Slow mail submission (%.2f s), check your mail '
+                             'setup', t)
         if self.use_tls:
             # avoid false failure detection when the server closes
             # the SMTP connection with TLS enabled
         # Use native line endings in message
         message = fix_eol(message, os.linesep)
 
-        self.log.info("Sending notification through sendmail at %s to %s"
-                      % (self.sendmail_path, recipients))
+        self.log.info("Sending notification through sendmail at %s to %s",
+                      self.sendmail_path, recipients)
         cmdline = [self.sendmail_path, "-i", "-f", from_addr]
         cmdline.extend(recipients)
-        self.log.debug("Sendmail command line: %s" % cmdline)
+        self.log.debug("Sendmail command line: %s", cmdline)
         child = Popen(cmdline, bufsize=-1, stdin=PIPE, stdout=PIPE,
                       stderr=PIPE, close_fds=close_fds)
         out, err = child.communicate(message)
         always_bcc = self.config.get('notification', 'smtp_always_bcc')
         for k, v in {'Cc': always_cc, 'Bcc': always_bcc}.items():
             if v:
-                self.log.debug("AlwaysEmailDecorator added '%s' "
-                        "because of rule: smtp_always_%s" % (v, k.lower())),
+                self.log.debug("AlwaysEmailDecorator added '%s' because of "
+                               "rule: smtp_always_%s", v, k.lower())
                 if message[k] and len(str(message[k]).split(',')) > 0:
                     recips = ', '.join([str(message[k]), v])
                 else: