Skip to content

[WIP] Add DEVSERVER_LOG_HANDLER setting #90

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
0.6.2 patched

* Added DEVSERVER_LOG_HANDLER setting

0.3.1

* Fixed a bug when --wsgi-app was not provided.
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -93,6 +93,9 @@ DEVSERVER_MODULES = []
DEVSERVER_IGNORED_PREFIXES = ['/media', '/uploads']
A list of prefixes to surpress and skip process on. By default, ``ADMIN_MEDIA_PREFIX``, ``MEDIA_URL`` and ``STATIC_URL`` (for Django >= 1.3) will be ignored (assuming ``MEDIA_URL`` and ``STATIC_URL`` is relative)::

DEVSERVER_LOG_HANDLER
A name of logging handler. Default is None, if None logs are written to stdout


-------
Modules
13 changes: 12 additions & 1 deletion devserver/logger.py
Original file line number Diff line number Diff line change
@@ -7,10 +7,18 @@
from django.core.management.color import color_style
from django.utils import termcolors

from devserver import settings


_bash_colors = re.compile(r'\x1b\[[^m]*m')


if settings.DEVSERVER_LOG_HANDLER:
logger = logging.getLogger(settings.DEVSERVER_LOG_HANDLER)
else:
logger = None


def strip_bash_colors(string):
return _bash_colors.sub('', string)

@@ -68,7 +76,10 @@ def log(self, message, *args, **kwargs):

message = '%s %s' % (tpl, '\n'.join(new_message))

sys.stdout.write(' ' + message + '\n')
if logger is None:
sys.stdout.write(' ' + message + '\n')
else:
logger.log(level, message)

warn = lambda x, *a, **k: x.log(level=logging.WARN, *a, **k)
info = lambda x, *a, **k: x.log(level=logging.INFO, *a, **k)
2 changes: 2 additions & 0 deletions devserver/settings.py
Original file line number Diff line number Diff line change
@@ -25,3 +25,5 @@
DEVSERVER_SQL_MIN_DURATION = getattr(settings, 'DEVSERVER_SQL_MIN_DURATION', None)

DEVSERVER_AUTO_PROFILE = getattr(settings, 'DEVSERVER_AUTO_PROFILE', False)

DEVSERVER_LOG_HANDLER = getattr(settings, 'DEVSERVER_LOG_HANDLER', None)