diff options
author | Christian Heimes <cheimes@redhat.com> | 2015-10-20 18:10:51 +0200 |
---|---|---|
committer | Simo Sorce <simo@redhat.com> | 2015-10-20 14:34:03 -0400 |
commit | 51a68745f39a209e9798663b283aa786cdbaf9f1 (patch) | |
tree | 296f92e8d665a4791845cd735bd4c5af963ca13e /custodia/httpd | |
parent | 424b17b477677e12ca7f53f132cfa46fb58038fa (diff) | |
download | custodia-51a68745f39a209e9798663b283aa786cdbaf9f1.tar.gz custodia-51a68745f39a209e9798663b283aa786cdbaf9f1.tar.xz custodia-51a68745f39a209e9798663b283aa786cdbaf9f1.zip |
Use Python's logging framework for logging
The custom logging and traceback functions as well as the audit logger
are replaced with Python's logging framework. For now the loggers are
hard-coded to use a StreamHandler(sys.stderr) as root handler and a
FileHandler for the audit log.
Signed-off-by: Christian Heimes <cheimes@redhat.com>
Reviewed-by: Simo Sorce <simo@redhat.com>
Diffstat (limited to 'custodia/httpd')
-rw-r--r-- | custodia/httpd/authenticators.py | 2 | ||||
-rw-r--r-- | custodia/httpd/authorizers.py | 2 | ||||
-rw-r--r-- | custodia/httpd/server.py | 19 |
3 files changed, 13 insertions, 10 deletions
diff --git a/custodia/httpd/authenticators.py b/custodia/httpd/authenticators.py index 33166ec..9ec622d 100644 --- a/custodia/httpd/authenticators.py +++ b/custodia/httpd/authenticators.py @@ -12,7 +12,7 @@ class HTTPAuthenticator(object): def __init__(self, config=None): self.config = config - self._auditlog = log.AuditLog(self.config) + self._auditlog = log.auditlog def handle(self, request): raise HTTPError(403) diff --git a/custodia/httpd/authorizers.py b/custodia/httpd/authorizers.py index 3758f3c..365b80c 100644 --- a/custodia/httpd/authorizers.py +++ b/custodia/httpd/authorizers.py @@ -9,7 +9,7 @@ class HTTPAuthorizer(object): def __init__(self, config=None): self.config = config - self._auditlog = log.AuditLog(self.config) + self._auditlog = log.auditlog self.store_name = None if self.config and 'store' in self.config: self.store_name = self.config['store'] diff --git a/custodia/httpd/server.py b/custodia/httpd/server.py index dfc89d6..656015c 100644 --- a/custodia/httpd/server.py +++ b/custodia/httpd/server.py @@ -1,6 +1,7 @@ # Copyright (C) 2015 Custodia Project Contributors - see LICENSE file import errno +import logging import os import shutil import socket @@ -22,6 +23,7 @@ except ImportError: from custodia import log +logger = logging.getLogger(__name__) SO_PEERCRED = getattr(socket, 'SO_PEERCRED', 17) SO_PEERSEC = getattr(socket, 'SO_PEERSEC', 31) @@ -35,7 +37,7 @@ class HTTPError(Exception): self.code = code if code is not None else 500 self.mesg = message errstring = '%d: %s' % (self.code, self.mesg) - log.debug(errstring) + logger.exception(errstring) super(HTTPError, self).__init__(errstring) @@ -60,7 +62,7 @@ class ForkingHTTPServer(ForkingTCPServer): self.config = config if 'server_string' in self.config: self.server_string = self.config['server_string'] - self._auditlog = log.AuditLog(self.config) + self._auditlog = log.auditlog class ForkingUnixHTTPServer(ForkingHTTPServer): @@ -158,8 +160,8 @@ class HTTPRequestHandler(BaseHTTPRequestHandler): creds = self.request.getsockopt(socket.SOL_SOCKET, SO_PEERSEC, SELINUX_CONTEXT_LEN) context = creds.decode('utf-8') - except Exception as e: - log.debug("Couldn't retrieve SELinux Context: (%s)" % str(e)) + except Exception: + log.debug("Couldn't retrieve SELinux Context", exc_info=True) context = None self._creds = {'pid': pid, 'uid': uid, 'gid': gid, 'context': context} @@ -256,8 +258,7 @@ class HTTPRequestHandler(BaseHTTPRequestHandler): self.close_connection = 1 return except Exception as e: # pylint: disable=broad-except - self.log_error("Handler failed: %r", e) - self.log_traceback() + self.log_error("Handler failed: %r", e, exc_info=True) self.send_error(500) self.wfile.flush() return @@ -280,8 +281,8 @@ class HTTPRequestHandler(BaseHTTPRequestHandler): self.close_connection = 1 return - def log_traceback(self): - self.log_error('Traceback:\n%s' % log.stacktrace()) + def log_error(self, format, *args, **kwargs): + logger.error(format, *args, **kwargs) def pipeline(self, config, request): """ @@ -388,6 +389,8 @@ class HTTPServer(object): else: raise ValueError('Unknown URL Scheme: %s' % url.scheme) + logger.debug('Serving on %s', address) + self.httpd = serverclass(address, HTTPRequestHandler, config) |