Merge pull request #4872 from ryanpetrello/log-aggregration-auditing

add a settings flag for writing all external logs to disk
This commit is contained in:
Ryan Petrello 2019-10-09 21:09:19 -04:00 committed by GitHub
commit cc27c95187
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 0 deletions

View File

@ -749,6 +749,16 @@ register(
category=_('Logging'),
category_slug='logging',
)
register(
'LOG_AGGREGATOR_AUDIT',
field_class=fields.BooleanField,
allow_null=True,
default=False,
label=_('Enabled external log aggregation auditing'),
help_text=_('When enabled, all external logs emitted by Tower will also be written to /var/log/tower/external.log'),
category=_('Logging'),
category_slug='logging',
)
register(

View File

@ -294,6 +294,18 @@ class AWXProxyHandler(logging.Handler):
super(AWXProxyHandler, self).__init__(**kwargs)
self._handler = None
self._old_kwargs = {}
self._auditor = logging.handlers.RotatingFileHandler(
filename='/var/log/tower/external.log',
maxBytes=1024 * 1024 * 50, # 50 MB
backupCount=5,
)
class WritableLogstashFormatter(LogstashFormatter):
@classmethod
def serialize(cls, message):
return json.dumps(message)
self._auditor.setFormatter(WritableLogstashFormatter())
def get_handler_class(self, protocol):
return HANDLER_MAPPING.get(protocol, AWXNullHandler)
@ -327,6 +339,9 @@ class AWXProxyHandler(logging.Handler):
def emit(self, record):
if AWXProxyHandler.thread_local.enabled:
actual_handler = self.get_handler()
if settings.LOG_AGGREGATOR_AUDIT:
self._auditor.setLevel(settings.LOG_AGGREGATOR_LEVEL)
self._auditor.emit(record)
return actual_handler.emit(record)
def perform_test(self, custom_settings):

View File

@ -1226,6 +1226,8 @@ LOGGING = {
},
}
}
LOG_AGGREGATOR_AUDIT = False
# Apply coloring to messages logged to the console
COLOR_LOGS = False