summaryrefslogtreecommitdiff
path: root/fixtures/_fixtures/logger.py
diff options
context:
space:
mode:
authorSean Dague <sean@dague.net>2014-09-26 08:48:10 +1200
committerRobert Collins <robertc@robertcollins.net>2014-09-26 08:48:10 +1200
commitcfe7eab29c2c305b3bff702e3e268292cb600a1b (patch)
tree010846dbfac77fe3a9306342cc2df5494ff8cec2 /fixtures/_fixtures/logger.py
parentf61bdd267c9f4a039bad10249e8ae618b29a515e (diff)
downloadfixtures-cfe7eab29c2c305b3bff702e3e268292cb600a1b.tar.gz
Add support for datefmt in FakeLogger
The logging fixture is extremely useful to be used a temp buffer for collecting log messages into a buffer, and only decide if we're going to emit them after some event in the future (like the failure or success of some future criteria). However, in it's current form we are not given access to the datefmt variable of the underlying Formatter, which means we always end up with the default python time string for %(asctime), which looks incorrectly localized many places. This merely adds the ability to pass the datefmt param through to the Formatter. Signed-off-by: Sean Dague <sean@dague.net>
Diffstat (limited to 'fixtures/_fixtures/logger.py')
-rw-r--r--fixtures/_fixtures/logger.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/fixtures/_fixtures/logger.py b/fixtures/_fixtures/logger.py
index e46de3a..59b849f 100644
--- a/fixtures/_fixtures/logger.py
+++ b/fixtures/_fixtures/logger.py
@@ -65,13 +65,16 @@ class LogHandler(Fixture):
class FakeLogger(Fixture):
"""Replace a logger and capture its output."""
- def __init__(self, name="", level=INFO, format=None, nuke_handlers=True):
+ def __init__(self, name="", level=INFO, format=None,
+ datefmt=None, nuke_handlers=True):
"""Create a FakeLogger fixture.
:param name: The name of the logger to replace. Defaults to "".
:param level: The log level to set, defaults to INFO.
:param format: Logging format to use. Defaults to capturing supplied
messages verbatim.
+ :param datefmt: Logging date format to use.
+ Mirrors the datefmt used in python loggging.
:param nuke_handlers: If True remove all existing handles (prevents
existing messages going to e.g. stdout). Defaults to True.
@@ -86,6 +89,7 @@ class FakeLogger(Fixture):
self._name = name
self._level = level
self._format = format
+ self._datefmt = datefmt
self._nuke_handlers = nuke_handlers
def setUp(self):
@@ -95,7 +99,7 @@ class FakeLogger(Fixture):
self._output = output
handler = StreamHandler(output)
if self._format:
- handler.setFormatter(Formatter(self._format))
+ handler.setFormatter(Formatter(self._format, self._datefmt))
self.useFixture(
LogHandler(handler, name=self._name, level=self._level,
nuke_handlers=self._nuke_handlers))