Mercurial > p > roundup > code
diff roundup/scripts/roundup_server.py @ 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 | 5017c3422334 |
| children | 66a17c80e035 |
line wrap: on
line diff
--- 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.
