remove formatters dependency on settings

This commit is contained in:
Chris Meyers
2017-02-21 12:31:15 -05:00
parent 60aa22b01b
commit e78377dcfc
2 changed files with 8 additions and 6 deletions

View File

@@ -2,7 +2,6 @@
# All Rights Reserved. # All Rights Reserved.
from logstash.formatter import LogstashFormatterVersion1 from logstash.formatter import LogstashFormatterVersion1
from django.conf import settings
from copy import copy from copy import copy
import json import json
import time import time
@@ -10,9 +9,11 @@ import time
class LogstashFormatter(LogstashFormatterVersion1): class LogstashFormatter(LogstashFormatterVersion1):
def __init__(self, **kwargs): def __init__(self, **kwargs):
settings_module = kwargs.pop('settings_module', None)
ret = super(LogstashFormatter, self).__init__(**kwargs) ret = super(LogstashFormatter, self).__init__(**kwargs)
self.host_id = settings.CLUSTER_HOST_ID if settings_module:
self.tower_uuid = getattr(settings, "LOG_AGGREGATOR_TOWER_UUID", None) self.host_id = settings_module.CLUSTER_HOST_ID
self.tower_uuid = settings_module.LOG_AGGREGATOR_TOWER_UUID
return ret return ret
def reformat_data_for_log(self, raw_data, kind=None): def reformat_data_for_log(self, raw_data, kind=None):
@@ -140,11 +141,12 @@ class LogstashFormatter(LogstashFormatterVersion1):
# Extra Fields # Extra Fields
'level': record.levelname, 'level': record.levelname,
'logger_name': record.name, 'logger_name': record.name,
'cluster_host_id': self.host_id
} }
if self.tower_uuid: if getattr(self, 'tower_uuid', None):
message['tower_uuid'] = self.tower_uuid message['tower_uuid'] = self.tower_uuid
if getattr(self, 'host_id', None):
message['cluster_host_id'] = self.host_id
# Add extra fields # Add extra fields
message.update(self.get_extra_fields(record)) message.update(self.get_extra_fields(record))

View File

@@ -189,7 +189,7 @@ def configure_external_logger(settings_module, async_flag=True, is_startup=True)
instance = None instance = None
if is_enabled: if is_enabled:
instance = BaseHTTPSHandler.from_django_settings(settings_module, async=async_flag) instance = BaseHTTPSHandler.from_django_settings(settings_module, async=async_flag)
instance.setFormatter(LogstashFormatter()) instance.setFormatter(LogstashFormatter(settings_module=settings_module))
awx_logger_instance = instance awx_logger_instance = instance
if is_enabled and 'awx' not in settings_module.LOG_AGGREGATOR_LOGGERS: if is_enabled and 'awx' not in settings_module.LOG_AGGREGATOR_LOGGERS:
awx_logger_instance = None awx_logger_instance = None