allow users to test log aggregration if awx isn't in the loggers list

This commit is contained in:
Ryan Petrello
2020-04-23 15:15:37 -04:00
parent c0e07198cf
commit 31c6b3337c
2 changed files with 13 additions and 7 deletions

View File

@@ -170,7 +170,13 @@ class SettingLoggingTest(GenericAPIView):
return Response({'error': 'Logging not enabled'}, status=status.HTTP_409_CONFLICT)
# Send test message to configured logger based on db settings
logging.getLogger('awx').error('AWX Connection Test Message')
try:
default_logger = settings.LOG_AGGREGATOR_LOGGERS[0]
if default_logger != 'awx':
default_logger = f'awx.analytics.{default_logger}'
except IndexError:
default_logger = 'awx'
logging.getLogger(default_logger).error('AWX Connection Test Message')
hostname = getattr(settings, 'LOG_AGGREGATOR_HOST', None)
protocol = getattr(settings, 'LOG_AGGREGATOR_PROTOCOL', None)