since we use pytest-randomly to randomize the test execution, depending on when
this specific test is executed, it may have the side effect of configuring
the global logging configuration, causing other tests that capture logging
messages to fail.
E.g. see https://travis-ci.org/fonttools/fonttools/jobs/545680550
we can't set the logger.level directly because in py37 the logger has a _cache
attribute and that needs to be invalidated by calling setLevel method.
also, I noticed we weren't restoring the original 'disabled' attribute value...
And we need to also set/restore the 'propagate' attribute.
the logger name is constant (based on the user class's name and module)
so we can cache it.
(this means the LogMixin will only work on regular dict-based classes,
not on 'slotted' classes. But that's ok
This is useful to quickly add logging functionality to classes, and
to reduce boilerplate.
It adds a 'log' property to the class inheriting from it, which uses
logging.getLogger to get a logging.Logger (sigleton) object named after
<module>.<class> of self.
Can be useful for writing tests:
>>> with CapturingLogHandler(log, "WARNING") as captor:
... # do something with logging
>>> assert captor.match('some .* pattern')
Since py23 modifies some essential builtins, it's safe to import
everything all the time. At least, that's how it was designed.
It's a bug if importing * breaks some code.
Both _StderrHandler and Logger.callHandlers included here are taken from Python 3.5's
logging.py source.
I only set logging.lastResort if it's not already set (i.e. for Python < 3.2).