summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@plope.com>2011-07-24 02:08:51 -0400
committerChris McDonough <chrism@plope.com>2011-07-24 02:08:51 -0400
commit3a80546633185b64390b7779bab459a7e58f22c4 (patch)
tree8ef6e1be76ff8110783f85fd304dc1608c9f1fc3
parent695dad38bd13514482ea324ba1196dc5d9bab9f6 (diff)
downloadpyramid-3a80546633185b64390b7779bab459a7e58f22c4.tar.gz
pyramid-3a80546633185b64390b7779bab459a7e58f22c4.tar.bz2
pyramid-3a80546633185b64390b7779bab459a7e58f22c4.zip
- The Pyramid debug logger now uses the standard logging configuration
(usually set up by Paste as part of startup). This means that output from e.g. ``debug_notfound``, ``debug_authorization``, etc. will go to the normal logging channels. The logger name of the debug logger will be the package name of the *caller* of the Configurator's constructor. - If a string is passed as the ``debug_logger`` parameter to a Configurator, that string is considered to be the name of a global Python logger rather than a dotted name to an instance of a logger.
-rw-r--r--CHANGES.txt15
-rw-r--r--pyramid/config.py28
-rw-r--r--pyramid/log.py16
-rw-r--r--pyramid/tests/test_config.py13
-rw-r--r--pyramid/tests/test_log.py16
5 files changed, 33 insertions, 55 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index c9c95fd7f..e14d4629b 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -8,7 +8,7 @@ Features
``rendering_val``. This can be used to introspect the value returned by a
view in a BeforeRender subscriber.
-- New configurator directive:
+- New configurator directive:^
``pyramid.config.Configurator.add_request_handler``. This directive adds
a request handler factory.
@@ -66,6 +66,19 @@ Features
same name in the same configuration (unless automatic_conflict_resolution
is able to resolve the conflict or this is an autocommitting configurator).
+- The Pyramid debug logger now uses the standard logging configuration
+ (usually set up by Paste as part of startup). This means that output from
+ e.g. ``debug_notfound``, ``debug_authorization``, etc. will go to the
+ normal logging channels. The logger name of the debug logger will be the
+ package name of the *caller* of the Configurator's constructor.
+
+Backwards Incompatibilities
+---------------------------
+
+- If a string is passed as the ``debug_logger`` parameter to a Configurator,
+ that string is considered to be the name of a global Python logger rather
+ than a dotted name to an instance of a logger.
+
1.1 (2011-07-22)
================
diff --git a/pyramid/config.py b/pyramid/config.py
index d6a87c7ad..cf6fb4182 100644
--- a/pyramid/config.py
+++ b/pyramid/config.py
@@ -1,4 +1,5 @@
import inspect
+import logging
import os
import re
import sys
@@ -62,7 +63,6 @@ from pyramid.httpexceptions import default_exceptionresponse_view
from pyramid.httpexceptions import HTTPForbidden
from pyramid.httpexceptions import HTTPNotFound
from pyramid.i18n import get_localizer
-from pyramid.log import make_stream_logger
from pyramid.mako_templating import renderer_factory as mako_renderer_factory
from pyramid.path import caller_package
from pyramid.path import package_path
@@ -195,12 +195,12 @@ class Configurator(object):
:meth:`pyramid.config.Configurator.add_renderer`). If
it is not passed, a default set of renderer factories is used.
- If ``debug_logger`` is not passed, a default debug logger that
- logs to stderr will be used. If it is passed, it should be an
- instance of the :class:`logging.Logger` (PEP 282) standard library
- class or a :term:`dotted Python name` to same. The debug logger
- is used by :app:`Pyramid` itself to log warnings and
- authorization debugging information.
+ If ``debug_logger`` is not passed, a default debug logger that logs to a
+ logger will be used (the logger name will be the package name of the
+ *caller* of this configurator). If it is passed, it should be an
+ instance of the :class:`logging.Logger` (PEP 282) standard library class
+ or a Python logger name. The debug logger is used by :app:`Pyramid`
+ itself to log warnings and authorization debugging information.
If ``locale_negotiator`` is passed, it should be a :term:`locale
negotiator` implementation or a :term:`dotted Python name` to
@@ -726,9 +726,12 @@ class Configurator(object):
# cope with WebOb exc objects not decoratored with IExceptionResponse
from webob.exc import WSGIHTTPException as WebobWSGIHTTPException
registry.registerSelfAdapter((WebobResponse,), IResponse)
- debug_logger = self.maybe_dotted(debug_logger)
+
if debug_logger is None:
- debug_logger = make_stream_logger('pyramid.debug', sys.stderr)
+ debug_logger = logging.getLogger(self.package_name)
+ elif isinstance(debug_logger, basestring):
+ debug_logger = logging.getLogger(debug_logger)
+
registry.registerUtility(debug_logger, IDebugLogger)
if authentication_policy or authorization_policy:
self._set_security_policies(authentication_policy,
@@ -953,16 +956,11 @@ class Configurator(object):
"""
def register():
registry = self.registry
- existing_factory = registry.queryUtility(IRequestHandlerFactory,
- name=name)
registry.registerUtility(handler_factory, IRequestHandlerFactory,
name=name)
existing_names = registry.queryUtility(IRequestHandlerFactories,
default=[])
- if not existing_factory:
- # don't replace a name if someone is trying to override
- # through a commit
- existing_names.append(name)
+ existing_names.append(name)
registry.registerUtility(existing_names, IRequestHandlerFactories)
self.action(('requesthandler', name), register)
diff --git a/pyramid/log.py b/pyramid/log.py
deleted file mode 100644
index 8a29ca919..000000000
--- a/pyramid/log.py
+++ /dev/null
@@ -1,16 +0,0 @@
-import logging
-
-def make_stream_logger(
- name, stream, levelname='DEBUG', fmt='%(asctime)s %(message)s'):
- """ Return an object which implements
- ``pyramid.interfaces.IDebugLogger`` (ie. a Python PEP 282 logger
- instance) with the name ``name`` using the stream (or open
- filehandle) ``stream``, logging at ``levelname`` log level or
- above with format ``fmt``. """
- handler = logging.StreamHandler(stream)
- formatter = logging.Formatter(fmt)
- handler.setFormatter(formatter)
- logger = logging.Logger(name)
- logger.addHandler(handler)
- logger.setLevel(getattr(logging, levelname))
- return logger
diff --git a/pyramid/tests/test_config.py b/pyramid/tests/test_config.py
index 630fe43ce..57ec1c044 100644
--- a/pyramid/tests/test_config.py
+++ b/pyramid/tests/test_config.py
@@ -153,7 +153,7 @@ class ConfiguratorTests(unittest.TestCase):
from pyramid.interfaces import IDebugLogger
config = self._makeOne()
logger = config.registry.getUtility(IDebugLogger)
- self.assertEqual(logger.name, 'pyramid.debug')
+ self.assertEqual(logger.name, 'pyramid.tests')
def test_ctor_noreg_debug_logger_non_None(self):
from pyramid.interfaces import IDebugLogger
@@ -401,7 +401,7 @@ class ConfiguratorTests(unittest.TestCase):
config = self._makeOne(reg)
config.setup_registry()
logger = reg.getUtility(IDebugLogger)
- self.assertEqual(logger.name, 'pyramid.debug')
+ self.assertEqual(logger.name, 'pyramid.tests')
def test_setup_registry_debug_logger_non_None(self):
from pyramid.registry import Registry
@@ -413,15 +413,14 @@ class ConfiguratorTests(unittest.TestCase):
result = reg.getUtility(IDebugLogger)
self.assertEqual(logger, result)
- def test_setup_registry_debug_logger_dottedname(self):
+ def test_setup_registry_debug_logger_name(self):
from pyramid.registry import Registry
from pyramid.interfaces import IDebugLogger
reg = Registry()
config = self._makeOne(reg)
- config.setup_registry(debug_logger='pyramid.tests')
+ config.setup_registry(debug_logger='foo')
result = reg.getUtility(IDebugLogger)
- import pyramid.tests
- self.assertEqual(result, pyramid.tests)
+ self.assertEqual(result.name, 'foo')
def test_setup_registry_authentication_policy(self):
from pyramid.registry import Registry
@@ -628,7 +627,7 @@ class ConfiguratorTests(unittest.TestCase):
config.add_request_handler(factory2, 'name2')
config.add_request_handler(factory3, 'name1')
names = config.registry.queryUtility(IRequestHandlerFactories)
- self.assertEqual(names, ['name1', 'name2'])
+ self.assertEqual(names, ['name1', 'name2', 'name1'])
f3 = config.registry.getUtility(IRequestHandlerFactory, name='name1')
self.assertEqual(f3, factory3)
diff --git a/pyramid/tests/test_log.py b/pyramid/tests/test_log.py
deleted file mode 100644
index 63add76ef..000000000
--- a/pyramid/tests/test_log.py
+++ /dev/null
@@ -1,16 +0,0 @@
-import unittest
-
-class TestFunctions(unittest.TestCase):
- def test_make_stream_logger(self):
- from pyramid.log import make_stream_logger
- import logging
- import sys
- logger = make_stream_logger('foo', sys.stderr, levelname='DEBUG',
- fmt='%(message)s')
- self.assertEqual(logger.name, 'foo')
- self.assertEqual(logger.handlers[0].stream, sys.stderr)
- self.assertEqual(logger.handlers[0].formatter._fmt, '%(message)s')
- self.assertEqual(logger.level, logging.DEBUG)
-
-
-