Codebase list logbook / 854b2064-14b6-4be9-9d9b-f6a59b8db224/main docs / cookbook.rst

Tree @854b2064-14b6-4be9-9d9b-f6a59b8db224/main (Download .tar.gz)

cookbook.rst @854b2064-14b6-4be9-9d9b-f6a59b8db224/mainraw · history · blame


Filtering Records Based on Extra Info

.. code-block:: python

    # This code demonstrates the usage of the `extra` argument for log records to enable advanced filtering of records through handlers

    import logbook

    if __name__ == "__main__":

	only_interesting = logbook.FileHandler('/tmp/interesting.log', filter=lambda r, h: r.extra['interesting'])
	everything = logbook.FileHandler('/tmp/all.log', bubble=True)

	with only_interesting, everything:'this is interesting', extra={'interesting': True})'this is not interesting')