Mercurial > p > roundup > code
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 5322:875605281b02 | 5323:762222535a0b |
|---|---|
| 21 | 21 |
| 22 | 22 |
| 23 # --- patch sys.path to make sure 'import roundup' finds correct version | 23 # --- patch sys.path to make sure 'import roundup' finds correct version |
| 24 import sys | 24 import sys |
| 25 import os.path as osp | 25 import os.path as osp |
| 26 | |
| 27 import logging | |
| 26 | 28 |
| 27 thisdir = osp.dirname(osp.abspath(__file__)) | 29 thisdir = osp.dirname(osp.abspath(__file__)) |
| 28 rootdir = osp.dirname(osp.dirname(thisdir)) | 30 rootdir = osp.dirname(osp.dirname(thisdir)) |
| 29 if (osp.exists(thisdir + '/__init__.py') and | 31 if (osp.exists(thisdir + '/__init__.py') and |
| 30 osp.exists(rootdir + '/roundup/__init__.py')): | 32 osp.exists(rootdir + '/roundup/__init__.py')): |
| 435 return socket.getfqdn(host) | 437 return socket.getfqdn(host) |
| 436 | 438 |
| 437 def log_message(self, format, *args): | 439 def log_message(self, format, *args): |
| 438 ''' Try to *safely* log to stderr. | 440 ''' Try to *safely* log to stderr. |
| 439 ''' | 441 ''' |
| 440 try: | 442 if self.CONFIG['LOGHTTPVIALOGGER']: |
| 441 BaseHTTPServer.BaseHTTPRequestHandler.log_message(self, | 443 logger = logging.getLogger('roundup.http') |
| 442 format, *args) | 444 |
| 443 except IOError: | 445 logger.info("%s - - [%s] %s" % |
| 444 # stderr is no longer viable | 446 (self.client_address[0], |
| 445 pass | 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 def start_response(self, headers, response): | 457 def start_response(self, headers, response): |
| 448 self.send_response(response) | 458 self.send_response(response) |
| 449 for key, value in headers: | 459 for key, value in headers: |
| 450 self.send_header(key, value) | 460 self.send_header(key, value) |
| 550 (configuration.BooleanOption, "nodaemon", "no", | 560 (configuration.BooleanOption, "nodaemon", "no", |
| 551 "don't fork (this overrides the pidfile mechanism)'"), | 561 "don't fork (this overrides the pidfile mechanism)'"), |
| 552 (configuration.BooleanOption, "log_hostnames", "no", | 562 (configuration.BooleanOption, "log_hostnames", "no", |
| 553 "Log client machine names instead of IP addresses " | 563 "Log client machine names instead of IP addresses " |
| 554 "(much slower)"), | 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 (configuration.NullableFilePathOption, "pidfile", "", | 570 (configuration.NullableFilePathOption, "pidfile", "", |
| 556 "File to which the server records " | 571 "File to which the server records " |
| 557 "the process id of the daemon.\n" | 572 "the process id of the daemon.\n" |
| 558 "If this option is not set, " | 573 "If this option is not set, " |
| 559 "the server will run in foreground\n"), | 574 "the server will run in foreground\n"), |
| 588 "pidfile": "d:", | 603 "pidfile": "d:", |
| 589 "nodaemon": "D", | 604 "nodaemon": "D", |
| 590 "log_hostnames": "N", | 605 "log_hostnames": "N", |
| 591 "multiprocess": "t:", | 606 "multiprocess": "t:", |
| 592 "template": "i:", | 607 "template": "i:", |
| 608 "loghttpvialogger": 'L', | |
| 593 "ssl": "s", | 609 "ssl": "s", |
| 594 "pem": "e:", | 610 "pem": "e:", |
| 595 } | 611 } |
| 596 | 612 |
| 597 def __init__(self, config_file=None): | 613 def __init__(self, config_file=None): |
| 805 -p <port> set the port to listen on (default: %(port)s) | 821 -p <port> set the port to listen on (default: %(port)s) |
| 806 -l <fname> log to the file indicated by fname instead of stderr/stdout | 822 -l <fname> log to the file indicated by fname instead of stderr/stdout |
| 807 -N log client machine names instead of IP addresses (much slower) | 823 -N log client machine names instead of IP addresses (much slower) |
| 808 -i <fname> set tracker index template | 824 -i <fname> set tracker index template |
| 809 -s enable SSL | 825 -s enable SSL |
| 826 -L http request logging uses python logging (roundup.http) | |
| 810 -e <fname> PEM file containing SSL key and certificate | 827 -e <fname> PEM file containing SSL key and certificate |
| 811 -t <mode> multiprocess mode (default: %(mp_def)s). | 828 -t <mode> multiprocess mode (default: %(mp_def)s). |
| 812 Allowed values: %(mp_types)s. | 829 Allowed values: %(mp_types)s. |
| 813 %(os_part)s | 830 %(os_part)s |
| 814 | 831 |
