Mercurial > p > roundup > code
changeset 5323:762222535a0b
Allow http request logs to be logged using the python logging module
so the user can log these entries to a rotating log file.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Fri, 25 May 2018 21:23:44 -0400 |
| parents | 875605281b02 |
| children | 7c7f3faa5e10 |
| files | CHANGES.txt doc/upgrading.txt roundup/scripts/roundup_server.py |
| diffstat | 3 files changed, 73 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/CHANGES.txt Sat May 12 21:28:02 2018 -0400 +++ b/CHANGES.txt Fri May 25 21:23:44 2018 -0400 @@ -230,6 +230,10 @@ non-retired items) or True (for finding only retired items). - Requires Python 2.7 now, indicated in version_check.py and doc/installation.txt. (Bernhard Reiter) +- New -L flag to roundup-server to send http/https request logs + through the python logger module (using roundup.http). This allows + automatic log rotation. Without it, log file rotation requires restarting + the server. (John Rouillard) Fixed:
--- a/doc/upgrading.txt Sat May 12 21:28:02 2018 -0400 +++ b/doc/upgrading.txt Fri May 25 21:23:44 2018 -0400 @@ -696,6 +696,52 @@ With this addition, the index template is displayed if there is no error, and the user stays on the search template if there is an error. +New -L (loghttpvialogger) option to roundup-server +-------------------------------------------------- + +Http request logs from roundup-server are sent to stderr or +can be recorded in a log file (if -l or the logfile options +is used). However there is no way to rotate the logfile +without shutting down and restarting the roundup-server. + +If the -L flag is used, the python logging module is used +for logging the http requests. The name for the log +(qualname) is 'roundup.http'. You can direct these messages +to a rotating log file by putting the following:: + + [loggers] + keys=roundup.http + + [logger_roundup.http] + level=INFO + handlers=rotate_weblog + qualname=roundup.http + propagate=0 + + [handlers] + keys=rotate_weblog + + [handler_rotate_weblog] + class=logging.handlers.RotatingFileHandler + args=('httpd.log','a', 512000, 2) + formatter=plain + + [formatters] + keys=plain + + [formatter_plain] + format=%(message)s + +into a file (e.g. logging.ini). Then reference this file in +the 'config' value of the [logging] section in the trackers +config.ini file. + +Note the log configuration above is an example and can be +merged into a more full featured logging config file for +your tracker if you wish. It will create a new file in the +current working directory called 'httpd.log' and will rotate +the log file at 500K and keep two old copies of the file. + Migrating from 1.5.0 to 1.5.1 =============================
--- a/roundup/scripts/roundup_server.py Sat May 12 21:28:02 2018 -0400 +++ b/roundup/scripts/roundup_server.py Fri May 25 21:23:44 2018 -0400 @@ -24,6 +24,8 @@ import sys import os.path as osp +import logging + thisdir = osp.dirname(osp.abspath(__file__)) rootdir = osp.dirname(osp.dirname(thisdir)) if (osp.exists(thisdir + '/__init__.py') and @@ -437,12 +439,20 @@ def log_message(self, format, *args): ''' Try to *safely* log to stderr. ''' - try: - BaseHTTPServer.BaseHTTPRequestHandler.log_message(self, - format, *args) - except IOError: - # stderr is no longer viable - pass + if self.CONFIG['LOGHTTPVIALOGGER']: + logger = logging.getLogger('roundup.http') + + logger.info("%s - - [%s] %s" % + (self.client_address[0], + self.log_date_time_string(), + format%args)) + else: + try: + BaseHTTPServer.BaseHTTPRequestHandler.log_message(self, + format, *args) + except IOError: + # stderr is no longer viable + pass def start_response(self, headers, response): self.send_response(response) @@ -552,6 +562,11 @@ (configuration.BooleanOption, "log_hostnames", "no", "Log client machine names instead of IP addresses " "(much slower)"), + (configuration.BooleanOption, "loghttpvialogger", "no", + "Have http(s) request logging done via python logger module.\n" + "If set to yes the python logging module is used with " + "qualname\n'roundup.http'. Otherwise logging is done to " + "stderr or the file\nspecified using the -l/logfile option."), (configuration.NullableFilePathOption, "pidfile", "", "File to which the server records " "the process id of the daemon.\n" @@ -590,6 +605,7 @@ "log_hostnames": "N", "multiprocess": "t:", "template": "i:", + "loghttpvialogger": 'L', "ssl": "s", "pem": "e:", } @@ -807,6 +823,7 @@ -N log client machine names instead of IP addresses (much slower) -i <fname> set tracker index template -s enable SSL + -L http request logging uses python logging (roundup.http) -e <fname> PEM file containing SSL key and certificate -t <mode> multiprocess mode (default: %(mp_def)s). Allowed values: %(mp_types)s.
