http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10891
Revision: 10891 Author: drtrigon Date: 2013-01-12 11:43:11 +0000 (Sat, 12 Jan 2013) Log Message: ----------- bug fix; follow-up to r10875 with simplification and some PEP 8
Modified Paths: -------------- trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/wikipedia.py =================================================================== --- trunk/pywikipedia/wikipedia.py 2013-01-12 11:37:01 UTC (rev 10890) +++ trunk/pywikipedia/wikipedia.py 2013-01-12 11:43:11 UTC (rev 10891) @@ -8689,9 +8689,14 @@ if enabled: if not logname: logname = '%s.log' % calledModuleName() + if pywikibot.throttle.pid > 1: + logname = '%s.%s.log' % (calledModuleName(), pywikibot.throttle.pid) logfn = config.datafilepath('logs', logname)
logger = logging.getLogger() # root logger + if logger.handlers: # init just once (if re-called) + logger = logging.getLogger('pywikibot') + return logger.setLevel(logging.DEBUG) # create file handler which logs even debug messages fh = logging.handlers.TimedRotatingFileHandler(logfn, @@ -8705,28 +8710,29 @@ ch = logging.StreamHandler() ch.setLevel(logging.INFO) # create formatter and add it to the handlers - formatter = logging.Formatter('%(asctime)s %(name)-20s %(levelname)-8s %(message)s') + formatter = logging.Formatter( + fmt='%(asctime)s %(name)18s: %(levelname)-8s %(message)s', + datefmt="%Y-%m-%d %H:%M:%S" + ) fh.setFormatter(formatter) #ch.setFormatter(formatter) # add the handlers to logger logger.addHandler(fh) # output to logfile #logger.addHandler(ch) # output to terminal/shell console
- # patch for Issue 8117: TimedRotatingFileHandler doesn't rotate log file at startup. - # applies to python2.6 only, solution from python2.7 source: + # 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): t = os.stat(logfn).st_mtime - logger.handlers[0].rolloverAt = logger.handlers[0].computeRollover(t) + logger.handlers[0].rolloverAt=logger.handlers[0].computeRollover(t)
logger = logging.getLogger('pywikibot') else: # disable the log file logger = None
-if '*' in config.log or calledModuleName() in config.log: - setLogfileStatus(True) - writeToCommandLogFile()
colorTagR = re.compile('\03{.*?}', re.UNICODE) @@ -8740,10 +8746,10 @@ type = plaintext.split(':') func = 'info' if len(type): - for func in ['debug', 'warning', 'error', 'critical', 'info']: - if func == type[0].strip().lower(): - break - getattr(logger, func)(plaintext.strip()) + func = type[0].strip().lower() + if func not in ['debug', 'warning', 'error', 'critical', 'info']: + func = 'info' + getattr(logger, func)(plaintext.rstrip().lstrip('\n'))
output_lock = threading.Lock() input_lock = threading.Lock() @@ -9049,6 +9055,9 @@ import pywikibot pywikibot.__dict__.update(locals())
+if '*' in config.log or calledModuleName() in config.log: + setLogfileStatus(True) + if __name__ == '__main__': import doctest print 'Pywikipediabot %s' % version.getversion()