add the ability to toggle DEBUG logging on dynamically

This commit is contained in:
Ryan Petrello
2019-05-13 15:35:53 -04:00
parent efddd9f679
commit b1d75327e3
9 changed files with 112 additions and 130 deletions

View File

@@ -19,11 +19,12 @@ from django.conf import settings
from requests_futures.sessions import FuturesSession
# AWX
from awx.main.constants import LOGGER_BLACKLIST
from awx.main.utils.formatters import LogstashFormatter
__all__ = ['BaseHTTPSHandler', 'TCPHandler', 'UDPHandler',
'AWXProxyHandler']
'AWXProxyHandler', 'RotatingProductionLogHandler']
logger = logging.getLogger('awx.main.utils.handlers')
@@ -91,6 +92,28 @@ class SocketResult:
return self
class DynamicLevelMixin(object):
@property
def level(self):
from django.conf import settings
for logger_name in LOGGER_BLACKLIST:
if self.name.startswith(logger_name):
return 30 # WARNING
try:
return logging._nameToLevel[settings.LOG_AGGREGATOR_LEVEL]
except Exception:
return 30 # WARNING
@level.setter
def level(self, level):
pass # no-op, this value comes from the database
class RotatingProductionLogHandler(logging.handlers.RotatingFileHandler, DynamicLevelMixin):
pass
class BaseHandler(logging.Handler):
def __init__(self, host=None, port=None, indv_facts=None, **kwargs):
super(BaseHandler, self).__init__()
@@ -272,7 +295,7 @@ HANDLER_MAPPING = {
}
class AWXProxyHandler(logging.Handler):
class AWXProxyHandler(logging.Handler, DynamicLevelMixin):
'''
Handler specific to the AWX external logging feature