http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10931
Revision: 10931 Author: drtrigon Date: 2013-01-15 18:00:15 +0000 (Tue, 15 Jan 2013) Log Message: ----------- follow-up; to r10918 in order to shorten this improvement; prepared to switch logging format (in order to have the same as in rewrite)
Modified Paths: -------------- trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/wikipedia.py =================================================================== --- trunk/pywikipedia/wikipedia.py 2013-01-15 17:17:46 UTC (rev 10930) +++ trunk/pywikipedia/wikipedia.py 2013-01-15 18:00:15 UTC (rev 10931) @@ -8722,37 +8722,32 @@ backupCount=config.logfilecount, encoding='utf-8') else: - try: - fh = logging.handlers.TimedRotatingFileHandler(logfn, - when='midnight', - utc=False, - #encoding='bz2-codec') - encoding='utf-8') - except TypeError: - # For Python 2.5 - fh = logging.handlers.TimedRotatingFileHandler(logfn, - when='midnight', - #encoding='bz2-codec') - encoding='utf-8') + ver = int( '%02i%02i' % (sys.version_info.major, + sys.version_info.minor) ) + kwargs = { when='midnight', + #encoding='bz2-codec') + encoding='utf-8' } + if ver > int('0205'): + # For Python > 2.5 (added in version 2.6) + kwargs['utc'] = True + fh = logging.handlers.TimedRotatingFileHandler(logfn, kwargs) # patch for "Issue 8117: TimedRotatingFileHandler doesn't rotate log # file at startup." # applies to python2.6 only, solution filched from python2.7 source: # http://hg.python.org/cpython-fullhistory/diff/a566e53f106d/Lib/logging/handl... - if os.path.exists(logfn): + if os.path.exists(logfn) and (ver == int('0206')): t = os.stat(logfn).st_mtime - try: - fh.rolloverAt = fh.computeRollover(t) - except AttributeError: - # Python 2.5 does not have it - pass + fh.rolloverAt = fh.computeRollover(t)
fh.setLevel(logging.DEBUG if debug else logging.INFO) # create console handler with a higher log level ch = logging.StreamHandler() ch.setLevel(logging.INFO) - # create formatter and add it to the handlers + # create formatter and add it to the handlers (using LogRecord attributes) formatter = logging.Formatter( fmt='%(asctime)s %(name)18s: %(levelname)-8s %(message)s', + #fmt="%(asctime)s %(filename)18s, %(lineno)4s " + # "in %(funcName)18s: %(levelname)-8s %(message)s", datefmt="%Y-%m-%d %H:%M:%S" ) fh.setFormatter(formatter)
pywikipedia-svn@lists.wikimedia.org