improve readability of the honcho console logs in the dev environment

* colorize uwsgi and celery logs; DEBUG lines are green, WARN lines
  are yellow, ERROR lines (and tracebacks) are red
* pretty-print fact callback receiver JSON
* simplify the uwsgi log format so it's more legible
This commit is contained in:
Ryan Petrello
2017-06-21 23:58:59 -04:00
parent 238e069bf3
commit 45bdd9f747
8 changed files with 54 additions and 4 deletions

View File

@@ -17,6 +17,7 @@ from requests.exceptions import RequestException
# loggly
import traceback
from django.conf import settings
from requests_futures.sessions import FuturesSession
# AWX
@@ -304,6 +305,33 @@ HANDLER_MAPPING = {
}
ColorHandler = logging.StreamHandler
if settings.COLOR_LOGS is True:
try:
from logutils.colorize import ColorizingStreamHandler
class ColorHandler(ColorizingStreamHandler):
def format(self, record):
message = logging.StreamHandler.format(self, record)
return '\n'.join([
self.colorize(line, record)
for line in message.splitlines()
])
level_map = {
logging.DEBUG: (None, 'green', True),
logging.INFO: (None, None, True),
logging.WARNING: (None, 'yellow', True),
logging.ERROR: (None, 'red', True),
logging.CRITICAL: (None, 'red', True),
}
except ImportError:
# logutils is only used for colored logs in the dev environment
pass
def _add_or_remove_logger(address, instance):
specific_logger = logging.getLogger(address)
for i, handler in enumerate(specific_logger.handlers):