Merge pull request #1996 from AlanCoding/null_handler_again

Interpret null protocol as logging.NullHandler
This commit is contained in:
Alan Rominger 2018-05-30 15:49:15 -04:00 committed by GitHub
commit 7aa1c64fac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View File

@ -127,6 +127,17 @@ def test_invalid_kwarg_to_real_handler():
assert not hasattr(handler, 'verify_cert')
def test_protocol_not_specified():
settings = LazySettings()
settings.configure(**{
'LOG_AGGREGATOR_HOST': 'https://server.invalid',
'LOG_AGGREGATOR_PORT': 22222,
'LOG_AGGREGATOR_PROTOCOL': None # awx/settings/defaults.py
})
handler = AWXProxyHandler().get_handler(custom_settings=settings)
assert isinstance(handler, logging.NullHandler)
def test_base_logging_handler_emit_system_tracking(dummy_log_record):
handler = BaseHandler(host='127.0.0.1', indv_facts=True)
handler.setFormatter(LogstashFormatter())

View File

@ -257,6 +257,15 @@ class UDPHandler(BaseHandler):
return SocketResult(True, reason=self.message)
class AWXNullHandler(logging.NullHandler):
'''
Only additional this does is accept arbitrary __init__ params because
the proxy handler does not (yet) work with arbitrary handler classes
'''
def __init__(self, *args, **kwargs):
super(AWXNullHandler, self).__init__()
HANDLER_MAPPING = {
'https': BaseHTTPSHandler,
'tcp': TCPHandler,
@ -285,7 +294,7 @@ class AWXProxyHandler(logging.Handler):
self._old_kwargs = {}
def get_handler_class(self, protocol):
return HANDLER_MAPPING[protocol]
return HANDLER_MAPPING.get(protocol, AWXNullHandler)
def get_handler(self, custom_settings=None, force_create=False):
new_kwargs = {}