From f158adbf6e9edd73903650d2453c0ba58840e1e1 Mon Sep 17 00:00:00 2001 From: Rotem Yaari Date: Tue, 11 Oct 2016 17:34:19 +0300 Subject: [PATCH] Add cookbook section to docs --- docs/cookbook.rst | 20 ++++++++++++++++++++ docs/index.rst | 1 + 2 files changed, 21 insertions(+) create mode 100644 docs/cookbook.rst diff --git a/docs/cookbook.rst b/docs/cookbook.rst new file mode 100644 index 00000000..51ac28e3 --- /dev/null +++ b/docs/cookbook.rst @@ -0,0 +1,20 @@ +Cookbook +======== + +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: + logbook.info('this is interesting', extra={'interesting': True}) + logbook.info('this is not interesting') diff --git a/docs/index.rst b/docs/index.rst index 82ddee9a..44e8dad0 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -38,6 +38,7 @@ Documentation api/index designexplained designdefense + cookbook changelog Project Information