mirror of
https://github.com/ansible/awx.git
synced 2026-05-10 10:57:35 -02:30
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:
@@ -114,7 +114,13 @@ class CallbackBrokerWorker(ConsumerMixin):
|
||||
if 'job_id' not in body and 'ad_hoc_command_id' not in body:
|
||||
raise Exception('Payload does not have a job_id or ad_hoc_command_id')
|
||||
if settings.DEBUG:
|
||||
logger.info('Body: {}'.format(body))
|
||||
from pygments import highlight
|
||||
from pygments.lexers import PythonLexer
|
||||
from pygments.formatters import Terminal256Formatter
|
||||
from pprint import pformat
|
||||
logger.info('Body: {}'.format(
|
||||
highlight(pformat(body, width=160), PythonLexer(), Terminal256Formatter(style='friendly'))
|
||||
))
|
||||
try:
|
||||
if 'job_id' in body:
|
||||
JobEvent.create_from_data(**body)
|
||||
|
||||
@@ -225,7 +225,7 @@ def tower_periodic_scheduler(self):
|
||||
run_now = now()
|
||||
state = TowerScheduleState.get_solo()
|
||||
last_run = state.schedule_last_run
|
||||
logger.debug("Last run was: %s", last_run)
|
||||
logger.debug("Last scheduler run was: %s", last_run)
|
||||
state.schedule_last_run = run_now
|
||||
state.save()
|
||||
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user