From ca1db05c4e600cce5d2b6f615b548c5fb2116279 Mon Sep 17 00:00:00 2001 From: Matthew Tretter Date: Wed, 17 Oct 2012 21:00:32 -0400 Subject: [PATCH] Use named logger --- imagekit/files.py | 6 ++---- imagekit/utils.py | 8 ++++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/imagekit/files.py b/imagekit/files.py index 1f590f1..12852cc 100644 --- a/imagekit/files.py +++ b/imagekit/files.py @@ -2,11 +2,10 @@ from django.conf import settings from django.core.files.base import ContentFile, File from django.core.files.images import ImageFile from django.utils.encoding import smart_str, smart_unicode -import logging import os from .signals import before_access from .utils import (suggest_extension, format_to_mimetype, - extension_to_mimetype) + extension_to_mimetype, get_logger) class BaseIKFile(File): @@ -115,8 +114,7 @@ class ImageSpecCacheFile(BaseIKFile, ImageFile): actual_name = self.storage.save(self.name, content) if actual_name != self.name: - # TODO: Use named logger? - logging.warning('The storage backend %s did not save the file' + get_logger().warning('The storage backend %s did not save the file' ' with the requested name ("%s") and instead used' ' "%s". This may be because a file already existed with' ' the requested name. If so, you may have meant to call' diff --git a/imagekit/utils.py b/imagekit/utils.py index 1c76977..282b739 100644 --- a/imagekit/utils.py +++ b/imagekit/utils.py @@ -1,3 +1,4 @@ +import logging import os import mimetypes import sys @@ -398,3 +399,10 @@ def autodiscover(): # attempting to import it, otherwise we want it to bubble up. if module_has_submodule(mod, 'imagespecs'): raise + + +def get_logger(logger_name='imagekit', add_null_handler=True): + logger = logging.getLogger(logger_name) + if add_null_handler: + logger.addHandler(logging.NullHandler()) + return logger