mirror of
https://github.com/ansible/awx.git
synced 2026-05-07 09:27:36 -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:
2
Makefile
2
Makefile
@@ -430,7 +430,7 @@ uwsgi: collectstatic
|
|||||||
@if [ "$(VENV_BASE)" ]; then \
|
@if [ "$(VENV_BASE)" ]; then \
|
||||||
. $(VENV_BASE)/tower/bin/activate; \
|
. $(VENV_BASE)/tower/bin/activate; \
|
||||||
fi; \
|
fi; \
|
||||||
uwsgi -b 32768 --socket 127.0.0.1:8050 --module=awx.wsgi:application --home=/venv/tower --chdir=/tower_devel/ --vacuum --processes=5 --harakiri=120 --master --no-orphans --py-autoreload 1 --max-requests=1000 --stats /tmp/stats.socket --master-fifo=/awxfifo --lazy-apps
|
uwsgi -b 32768 --socket 127.0.0.1:8050 --module=awx.wsgi:application --home=/venv/tower --chdir=/tower_devel/ --vacuum --processes=5 --harakiri=120 --master --no-orphans --py-autoreload 1 --max-requests=1000 --stats /tmp/stats.socket --master-fifo=/awxfifo --lazy-apps --logformat "%(addr) %(method) %(uri) - %(proto) %(status)"
|
||||||
|
|
||||||
daphne:
|
daphne:
|
||||||
@if [ "$(VENV_BASE)" ]; then \
|
@if [ "$(VENV_BASE)" ]; then \
|
||||||
|
|||||||
@@ -114,7 +114,13 @@ class CallbackBrokerWorker(ConsumerMixin):
|
|||||||
if 'job_id' not in body and 'ad_hoc_command_id' not in body:
|
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')
|
raise Exception('Payload does not have a job_id or ad_hoc_command_id')
|
||||||
if settings.DEBUG:
|
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:
|
try:
|
||||||
if 'job_id' in body:
|
if 'job_id' in body:
|
||||||
JobEvent.create_from_data(**body)
|
JobEvent.create_from_data(**body)
|
||||||
|
|||||||
@@ -225,7 +225,7 @@ def tower_periodic_scheduler(self):
|
|||||||
run_now = now()
|
run_now = now()
|
||||||
state = TowerScheduleState.get_solo()
|
state = TowerScheduleState.get_solo()
|
||||||
last_run = state.schedule_last_run
|
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.schedule_last_run = run_now
|
||||||
state.save()
|
state.save()
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ from requests.exceptions import RequestException
|
|||||||
# loggly
|
# loggly
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
from requests_futures.sessions import FuturesSession
|
from requests_futures.sessions import FuturesSession
|
||||||
|
|
||||||
# AWX
|
# 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):
|
def _add_or_remove_logger(address, instance):
|
||||||
specific_logger = logging.getLogger(address)
|
specific_logger = logging.getLogger(address)
|
||||||
for i, handler in enumerate(specific_logger.handlers):
|
for i, handler in enumerate(specific_logger.handlers):
|
||||||
|
|||||||
@@ -917,9 +917,9 @@ LOGGING = {
|
|||||||
},
|
},
|
||||||
'handlers': {
|
'handlers': {
|
||||||
'console': {
|
'console': {
|
||||||
|
'()': 'logging.StreamHandler',
|
||||||
'level': 'DEBUG',
|
'level': 'DEBUG',
|
||||||
'filters': ['require_debug_true_or_test'],
|
'filters': ['require_debug_true_or_test'],
|
||||||
'class': 'logging.StreamHandler',
|
|
||||||
'formatter': 'simple',
|
'formatter': 'simple',
|
||||||
},
|
},
|
||||||
'null': {
|
'null': {
|
||||||
@@ -1091,3 +1091,4 @@ LOGGING = {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
COLOR_LOGS = False
|
||||||
|
|||||||
@@ -19,6 +19,11 @@ from split_settings.tools import optional, include
|
|||||||
# Load default settings.
|
# Load default settings.
|
||||||
from defaults import * # NOQA
|
from defaults import * # NOQA
|
||||||
|
|
||||||
|
# show colored logs in the dev environment
|
||||||
|
# to disable this, set `COLOR_LOGS = False` in awx/settings/local_settings.py
|
||||||
|
LOGGING['handlers']['console']['()'] = 'awx.main.utils.handlers.ColorHandler'
|
||||||
|
COLOR_LOGS = True
|
||||||
|
|
||||||
ALLOWED_HOSTS = ['*']
|
ALLOWED_HOSTS = ['*']
|
||||||
|
|
||||||
mimetypes.add_type("image/svg+xml", ".svg", True)
|
mimetypes.add_type("image/svg+xml", ".svg", True)
|
||||||
@@ -40,6 +45,9 @@ TEMPLATE_LOADERS = (
|
|||||||
if 'celeryd' in sys.argv:
|
if 'celeryd' in sys.argv:
|
||||||
SQL_DEBUG = False
|
SQL_DEBUG = False
|
||||||
|
|
||||||
|
CELERYD_HIJACK_ROOT_LOGGER = False
|
||||||
|
CELERYD_LOG_COLOR = True
|
||||||
|
|
||||||
CALLBACK_QUEUE = "callback_tasks"
|
CALLBACK_QUEUE = "callback_tasks"
|
||||||
|
|
||||||
# Enable PROOT for tower-qa integration tests.
|
# Enable PROOT for tower-qa integration tests.
|
||||||
|
|||||||
@@ -10,5 +10,6 @@ pytest-cov
|
|||||||
pytest-django
|
pytest-django
|
||||||
pytest-pythonpath
|
pytest-pythonpath
|
||||||
pytest-mock
|
pytest-mock
|
||||||
|
logutils
|
||||||
flower
|
flower
|
||||||
uwsgitop
|
uwsgitop
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ from celery.contrib.rdb import Rdb
|
|||||||
|
|
||||||
import cmd
|
import cmd
|
||||||
import contextlib
|
import contextlib
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
import pprint
|
import pprint
|
||||||
import re
|
import re
|
||||||
@@ -27,6 +28,8 @@ from pygments import highlight
|
|||||||
from pygments.lexers import PythonLexer
|
from pygments.lexers import PythonLexer
|
||||||
from pygments.formatters import Terminal256Formatter
|
from pygments.formatters import Terminal256Formatter
|
||||||
|
|
||||||
|
logger = logging.getLogger('awx')
|
||||||
|
|
||||||
|
|
||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
def style(im_self, filepart=None, lexer=None):
|
def style(im_self, filepart=None, lexer=None):
|
||||||
@@ -158,6 +161,9 @@ class CustomPdb(Rdb):
|
|||||||
)
|
)
|
||||||
return (sock, port)
|
return (sock, port)
|
||||||
|
|
||||||
|
def say(self, m):
|
||||||
|
logger.warning(m)
|
||||||
|
|
||||||
|
|
||||||
CustomPdb.complete = rlcompleter.Completer(locals()).complete
|
CustomPdb.complete = rlcompleter.Completer(locals()).complete
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user