http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10895
Revision: 10895 Author: drtrigon Date: 2013-01-12 16:17:54 +0000 (Sat, 12 Jan 2013) Log Message: ----------- follow-up; to r10875 and r10891 in order to enable choice between different loggin rotation handlers (come even closer to rewrite)
Modified Paths: -------------- trunk/pywikipedia/config.py trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/config.py =================================================================== --- trunk/pywikipedia/config.py 2013-01-12 13:49:07 UTC (rev 10894) +++ trunk/pywikipedia/config.py 2013-01-12 16:17:54 UTC (rev 10895) @@ -199,6 +199,20 @@ # be used to generate so-called warnfiles. # This setting can be overridden by the -log or -nolog command-line arguments. log = ['interwiki'] +# maximal size of a logfile in kilobytes. If the size reached that limit the +# logfile will be renamed (if logfilecount is not 0) and the old file is filled +# again. logfilesize must be an integer value +logfilesize = 1024 +# Number of rotating logfiles are created. The older files get the higher +# number. If logfilecount is 0, no logfile will be archived but the current +# logfile will be overwritten if the file size reached the logfilesize above. +# If logfilecount is -1 there are no rotating logfiles but the files where +# renamed if the logfile is full. The newest file gets the highest number until +# some logfiles where deleted. +logfilecount = 5 +# logging handler to use, you can choose between: 'TRFH' (TimedRotatingFile- +# Handler), 'RFH' (RotatingFileHandler), ... more might come. +loghandler = 'TRFH'
############## INTERWIKI SETTINGS ##############
Modified: trunk/pywikipedia/wikipedia.py =================================================================== --- trunk/pywikipedia/wikipedia.py 2013-01-12 13:49:07 UTC (rev 10894) +++ trunk/pywikipedia/wikipedia.py 2013-01-12 16:17:54 UTC (rev 10895) @@ -8506,6 +8506,8 @@ setLogfileStatus(True) elif arg.startswith('-log:'): setLogfileStatus(True, arg[5:]) + elif arg.startswith('-loghandler:'): + config.loghandler = arg[12:] elif arg == '-nolog': setLogfileStatus(False) elif arg in ['-verbose', '-v']: @@ -8586,18 +8588,22 @@
-help Show this help text.
+-loghandler:xyz Choose a value for 'xyz' from 'TRFH' (TimedRotatingFile- + Handler) or 'RFH' (RotatingFileHandler). Has to be defined + before '-log' on command line. + -log Enable the logfile, using the default filename "%s.log" Logs will be stored in the logs subdirectory.
-log:xyz Enable the logfile, using 'xyz' as the filename.
+-nolog Disable the logfile (if it is enabled by default). + -maxlag Sets a new maxlag parameter to a number of seconds. Defer bot edits during periods of database server lag. Default is set by config.py
--nolog Disable the logfile (if it is enabled by default). - -putthrottle:n Set the minimum time (in seconds) the bot will wait between -pt:n saving pages.
@@ -8699,11 +8705,24 @@ return logger.setLevel(logging.DEBUG) # create file handler which logs even debug messages - fh = logging.handlers.TimedRotatingFileHandler(logfn, - when='midnight', - utc=False, - #encoding='bz2-codec') - encoding='utf-8') + if config.loghandler.upper() == 'TRFH': + fh = logging.handlers.TimedRotatingFileHandler(logfn, + when='midnight', + utc=False, + #encoding='bz2-codec') + encoding='utf-8') + # 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 + fh.rolloverAt = fh.computeRollover(t) + elif config.loghandler.upper() == 'RFH': + fh = logging.handlers.RotatingFileHandler(filename=logfn, + maxBytes=1024 * config.logfilesize, + backupCount=config.logfilecount, + encoding='utf-8') #fh.setLevel(logging.DEBUG if debug else logging.INFO) fh.setLevel(logging.DEBUG) # create console handler with a higher log level @@ -8720,14 +8739,6 @@ 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 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 = logging.getLogger('pywikibot') else: # disable the log file @@ -8745,7 +8756,7 @@ # save the text in a logfile (will be written in utf-8) type = plaintext.split(':') func = 'info' - if len(type): + if len(type) > 1: func = type[0].strip().lower() if func not in ['debug', 'warning', 'error', 'critical', 'info']: func = 'info'