Skip to content
This repository has been archived by the owner on Dec 3, 2019. It is now read-only.

Commit

Permalink
Use logger in get_static_renderers for logging
Browse files Browse the repository at this point in the history
  • Loading branch information
hyperair committed Mar 6, 2014
1 parent d154614 commit d1b8252
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
10 changes: 9 additions & 1 deletion django_medusa/log.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
from django.conf import settings
import logging
from .utils import ProxyLogHandler


class ProxyLogHandler(logging.Handler):
def __init__(self, logger):
logging.Handler.__init__(self)
self.__logger = logger

def emit(self, record):
self.__logger.handle(record)

listener = None

Expand Down
31 changes: 13 additions & 18 deletions django_medusa/utils.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import imp
from django.conf import settings
from importlib import import_module
import logging
import sys

from .log import get_logger


def get_static_renderers():
module_name = 'renderers'
renderers = []
logger = get_logger()

modules_to_check = []

Expand All @@ -33,34 +35,27 @@ def get_static_renderers():
import_module(app)
app_path = sys.modules[app].__path__
except AttributeError:
print "Skipping app '%s'... (Not found)" % app
logger.error("Skipping app '%s'... (Not found)", app)
continue
try:
imp.find_module(module_name, app_path)
except ImportError:
print "Skipping app '%s'... (No 'renderers.py')" % app
logger.info("Skipping app '%s'... (No 'renderers.py')", app)
continue
try:
app_render_module = import_module('%s.%s' % (app, module_name))
if hasattr(app_render_module, "renderers"):
renderers += getattr(app_render_module, module_name)
else:
print "Skipping app '%s'... ('%s.renderers' does not contain "\
"'renderers' var (list of render classes)" % (app, app)
logger.error("Skipping app '%s'... "
"('%s.renderers' does not contain "
"'renderers' var (list of render classes)",
app, app)
except AttributeError:
print "Skipping app '%s'... (Error importing '%s.renderers')" % (
app, app
)
logger.error("Skipping app '%s'... (Error importing "
"'%s.renderers')", app, app,
exc_info=True)
continue
print "Found renderers for '%s'..." % app
logger.info("Found renderers for '%s'...", app)
print
return tuple(renderers)


class ProxyLogHandler(logging.Handler):
def __init__(self, logger):
logging.Handler.__init__(self)
self.__logger = logger

def emit(self, record):
self.__logger.handle(record)

0 comments on commit d1b8252

Please sign in to comment.