From 52192bcc10c29ddd559b7b2881d9aa4fa3018bd7 Mon Sep 17 00:00:00 2001 From: Andy Dirnberger Date: Tue, 8 Mar 2016 17:44:31 -0500 Subject: [PATCH] Replace Henson's logger When initializing a Henson application, Henson-Logging will now replace Henson's logger with itself. This will cause all logs for an application to be formatted with structlog. --- CHANGES.rst | 2 +- docs/index.rst | 8 ++++---- henson_logging/__init__.py | 7 ++++--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 1ba8702..b6d65fa 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,7 +1,7 @@ Version 0.3.0 ============= -Release TBD +- Replace Henson's logger with the instance of ``Logging`` Version 0.2.0 diff --git a/docs/index.rst b/docs/index.rst index 8958cb9..20be698 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -13,11 +13,11 @@ Quickstart from henson import Application from henson_logging import Logging - logger = Logging() - app = Application(__name__, logger=logger) - logger.init_app(app) + app = Application(__name__) + logger = Logging(app) -.. todo:: Fix this API. It's awkward. +In addition to giving you a logger that can be used throughout your +application, it will replace Henson's internal logger with the new one. Configuration ============= diff --git a/henson_logging/__init__.py b/henson_logging/__init__.py index 7ecbb05..be6800b 100644 --- a/henson_logging/__init__.py +++ b/henson_logging/__init__.py @@ -62,10 +62,11 @@ class Logging(Extension): def __init__(self, app=None): """Initialize the instance.""" - self._logger = None - super().__init__(app) + self._logger = None + app.logger = self + critical = lambda s, *a, **kw: s.logger.critical(*a, **kw) debug = lambda s, *a, **kw: s.logger.debug(*a, **kw) error = lambda s, *a, **kw: s.logger.error(*a, **kw) @@ -73,6 +74,7 @@ def __init__(self, app=None): exception = lambda s, *a, **kw: s.logger.exception(*a, **kw) fatal = lambda s, *a, **kw: s.logger.fatal(*a, **kw) log = lambda s, *a, **kw: s.logger.log(*a, **kw) + setLevel = lambda s, l: s.logger.setLevel(l) warning = lambda s, *a, **kw: s.logger.warning(*a, **kw) @property @@ -83,7 +85,6 @@ def logger(self): logging.RootLogger: The logger. """ if not self._logger: - settings = { 'version': self.app.settings['LOG_VERSION'], 'formatters': {