|
24 | 24 | import sys |
25 | 25 | import os.path as osp |
26 | 26 |
|
| 27 | +import logging |
| 28 | + |
27 | 29 | thisdir = osp.dirname(osp.abspath(__file__)) |
28 | 30 | rootdir = osp.dirname(osp.dirname(thisdir)) |
29 | 31 | if (osp.exists(thisdir + '/__init__.py') and |
@@ -437,12 +439,20 @@ def address_string(self): |
437 | 439 | def log_message(self, format, *args): |
438 | 440 | ''' Try to *safely* log to stderr. |
439 | 441 | ''' |
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 |
446 | 456 |
|
447 | 457 | def start_response(self, headers, response): |
448 | 458 | self.send_response(response) |
@@ -552,6 +562,11 @@ class ServerConfig(configuration.Config): |
552 | 562 | (configuration.BooleanOption, "log_hostnames", "no", |
553 | 563 | "Log client machine names instead of IP addresses " |
554 | 564 | "(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."), |
555 | 570 | (configuration.NullableFilePathOption, "pidfile", "", |
556 | 571 | "File to which the server records " |
557 | 572 | "the process id of the daemon.\n" |
@@ -590,6 +605,7 @@ class ServerConfig(configuration.Config): |
590 | 605 | "log_hostnames": "N", |
591 | 606 | "multiprocess": "t:", |
592 | 607 | "template": "i:", |
| 608 | + "loghttpvialogger": 'L', |
593 | 609 | "ssl": "s", |
594 | 610 | "pem": "e:", |
595 | 611 | } |
@@ -807,6 +823,7 @@ def usage(message=''): |
807 | 823 | -N log client machine names instead of IP addresses (much slower) |
808 | 824 | -i <fname> set tracker index template |
809 | 825 | -s enable SSL |
| 826 | + -L http request logging uses python logging (roundup.http) |
810 | 827 | -e <fname> PEM file containing SSL key and certificate |
811 | 828 | -t <mode> multiprocess mode (default: %(mp_def)s). |
812 | 829 | Allowed values: %(mp_types)s. |
|
0 commit comments