Skip to content

Commit 1f3983e

Browse files
committed
Allow http request logs to be logged using the python logging module
so the user can log these entries to a rotating log file.
1 parent ea0b857 commit 1f3983e

File tree

3 files changed

+73
-6
lines changed

3 files changed

+73
-6
lines changed

CHANGES.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,10 @@ Features:
230230
non-retired items) or True (for finding only retired items).
231231
- Requires Python 2.7 now, indicated in version_check.py
232232
and doc/installation.txt. (Bernhard Reiter)
233+
- New -L flag to roundup-server to send http/https request logs
234+
through the python logger module (using roundup.http). This allows
235+
automatic log rotation. Without it, log file rotation requires restarting
236+
the server. (John Rouillard)
233237

234238
Fixed:
235239

doc/upgrading.txt

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,52 @@ hidden field @old-queryname:
696696
With this addition, the index template is displayed if there is no
697697
error, and the user stays on the search template if there is an error.
698698

699+
New -L (loghttpvialogger) option to roundup-server
700+
--------------------------------------------------
701+
702+
Http request logs from roundup-server are sent to stderr or
703+
can be recorded in a log file (if -l or the logfile options
704+
is used). However there is no way to rotate the logfile
705+
without shutting down and restarting the roundup-server.
706+
707+
If the -L flag is used, the python logging module is used
708+
for logging the http requests. The name for the log
709+
(qualname) is 'roundup.http'. You can direct these messages
710+
to a rotating log file by putting the following::
711+
712+
[loggers]
713+
keys=roundup.http
714+
715+
[logger_roundup.http]
716+
level=INFO
717+
handlers=rotate_weblog
718+
qualname=roundup.http
719+
propagate=0
720+
721+
[handlers]
722+
keys=rotate_weblog
723+
724+
[handler_rotate_weblog]
725+
class=logging.handlers.RotatingFileHandler
726+
args=('httpd.log','a', 512000, 2)
727+
formatter=plain
728+
729+
[formatters]
730+
keys=plain
731+
732+
[formatter_plain]
733+
format=%(message)s
734+
735+
into a file (e.g. logging.ini). Then reference this file in
736+
the 'config' value of the [logging] section in the trackers
737+
config.ini file.
738+
739+
Note the log configuration above is an example and can be
740+
merged into a more full featured logging config file for
741+
your tracker if you wish. It will create a new file in the
742+
current working directory called 'httpd.log' and will rotate
743+
the log file at 500K and keep two old copies of the file.
744+
699745
Migrating from 1.5.0 to 1.5.1
700746
=============================
701747

roundup/scripts/roundup_server.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import sys
2525
import os.path as osp
2626

27+
import logging
28+
2729
thisdir = osp.dirname(osp.abspath(__file__))
2830
rootdir = osp.dirname(osp.dirname(thisdir))
2931
if (osp.exists(thisdir + '/__init__.py') and
@@ -437,12 +439,20 @@ def address_string(self):
437439
def log_message(self, format, *args):
438440
''' Try to *safely* log to stderr.
439441
'''
440-
try:
441-
BaseHTTPServer.BaseHTTPRequestHandler.log_message(self,
442-
format, *args)
443-
except IOError:
444-
# stderr is no longer viable
445-
pass
442+
if self.CONFIG['LOGHTTPVIALOGGER']:
443+
logger = logging.getLogger('roundup.http')
444+
445+
logger.info("%s - - [%s] %s" %
446+
(self.client_address[0],
447+
self.log_date_time_string(),
448+
format%args))
449+
else:
450+
try:
451+
BaseHTTPServer.BaseHTTPRequestHandler.log_message(self,
452+
format, *args)
453+
except IOError:
454+
# stderr is no longer viable
455+
pass
446456

447457
def start_response(self, headers, response):
448458
self.send_response(response)
@@ -552,6 +562,11 @@ class ServerConfig(configuration.Config):
552562
(configuration.BooleanOption, "log_hostnames", "no",
553563
"Log client machine names instead of IP addresses "
554564
"(much slower)"),
565+
(configuration.BooleanOption, "loghttpvialogger", "no",
566+
"Have http(s) request logging done via python logger module.\n"
567+
"If set to yes the python logging module is used with "
568+
"qualname\n'roundup.http'. Otherwise logging is done to "
569+
"stderr or the file\nspecified using the -l/logfile option."),
555570
(configuration.NullableFilePathOption, "pidfile", "",
556571
"File to which the server records "
557572
"the process id of the daemon.\n"
@@ -590,6 +605,7 @@ class ServerConfig(configuration.Config):
590605
"log_hostnames": "N",
591606
"multiprocess": "t:",
592607
"template": "i:",
608+
"loghttpvialogger": 'L',
593609
"ssl": "s",
594610
"pem": "e:",
595611
}
@@ -807,6 +823,7 @@ def usage(message=''):
807823
-N log client machine names instead of IP addresses (much slower)
808824
-i <fname> set tracker index template
809825
-s enable SSL
826+
-L http request logging uses python logging (roundup.http)
810827
-e <fname> PEM file containing SSL key and certificate
811828
-t <mode> multiprocess mode (default: %(mp_def)s).
812829
Allowed values: %(mp_types)s.

0 commit comments

Comments
 (0)