anatoly techtonik avatar anatoly techtonik committed 5396f8c

In debug mode log messages to console (fixes issue #7)

Comments (0)

Files changed (1)

 # system imports
 import sys, os, urllib, cStringIO, traceback, cgi, binascii, gzip
 import time, random, smtplib, base64, email, types, urlparse
-import re, zipfile, logging, shutil, Cookie, subprocess, hashlib
+import re, zipfile, shutil, Cookie, subprocess, hashlib
+import logging
 from zope.pagetemplate.pagetemplatefile import PageTemplateFile
 from distutils.util import rfc822_escape
 from distutils2.metadata import Metadata
         # configure logging
         if self.config.logfile or self.config.mailhost:
             root = logging.getLogger()
-            hdlrs = []
+            if self.config.debug_mode == 'yes':
+                root.setLevel(logging.DEBUG)
+                hdlr = logging.StreamHandler()
+                hdlr.setFormatter(logging.Formatter(
+                    fmt='%(asctime)s:%(levelname)s %(message)s',
+                    datefmt='%H:%M:%S'))
+                root.addHandler(hdlr)
+      "--- Running PyPI in DEBUG mode ---")
             if self.config.logfile:
                 hdlr = logging.FileHandler(self.config.logfile)
                 formatter = logging.Formatter(
                     '%(asctime)s %(name)s:%(levelname)s %(message)s')
-                hdlrs.append(hdlr)
+                root.addHandler(hdlr)
             if self.config.logging_mailhost:
                 hdlr = MailingLogger.MailingLogger(self.config.logging_mailhost,
                     self.config.fromaddr, self.config.toaddrs,
                     '[PyPI] %(line)s', False, flood_level=10)
-                hdlrs.append(hdlr)
-            root.handlers = hdlrs
+                root.addHandler(hdlr)
     def run(self):
         ''' Run the request, handling all uncaught errors and finishing off
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.