This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Enhancement to Logging - Logging Stack
Type: enhancement Stage: resolved
Components: Library (Lib) Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: vinay.sajip Nosy List: dasilver@cisco.com, python-dev, r.david.murray, rhettinger, vinay.sajip
Priority: normal Keywords:

Created on 2015-10-08 17:05 by dasilver@cisco.com, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (5)
msg252557 - (view) Author: David Silverman (dasilver@cisco.com) Date: 2015-10-08 17:05
It would be useful to have the ability to push logs onto a stack. This way you can log events to the stack. If an error occurred, you could pop the stack and output the log events. If no error occurred, you could pop the stack and discard the logs.

An example would be when you call a function it could push logs onto the log stack as the function is executing. If an error is encountered, you can pop/output the logs to provide more details. But, if no error is encountered, the detailed logs can be popped and discarded.
msg252560 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015-10-08 17:24
I'm guessing you could write a custom hander that would do that.  It might be something more suited for a recipe or pypi package.
msg252576 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2015-10-09 00:44
This seems like a reasonable use case and is worth considering.

Offhand, I don't see how a user could easily implement this on their own without hacking the logging module internals.  What would be needed is some support for begin-logging-transaction, a series of normal logging calls, followed by either a transaction-commit or transaction-rollback.
msg252594 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2015-10-09 07:25
This is already supported. There is a logging.handlers.MemoryHandler which allows you to buffer logging events and then pass the buffered events to another handler when some condition is met, such as e.g. buffer full or some severity threshold is exceeded. Flushing the buffer to the other handler can be customised by subclassing and overriding shouldFlush() and perhaps flush() methods.

https://docs.python.org/2/library/logging.handlers.html#memoryhandler

I can perhaps add a cookbook recipe to illustrate, so I'll leave this issue open for now, as a reminder.
msg252675 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-10-09 23:54
New changeset 3ad8a2d34d01 by Vinay Sajip in branch '2.7':
Closes #25344: Added cookbook recipe to show buffering of logging events.
https://hg.python.org/cpython/rev/3ad8a2d34d01

New changeset 7cc3a8141022 by Vinay Sajip in branch '3.4':
Closes #25344: Added cookbook recipe to show buffering of logging events.
https://hg.python.org/cpython/rev/7cc3a8141022

New changeset be13ea160b1a by Vinay Sajip in branch '3.5':
Closes #25344: Merged fix from 3.4.
https://hg.python.org/cpython/rev/be13ea160b1a

New changeset 6c183537b2fb by Vinay Sajip in branch 'default':
Closes #25344: Merged fix from 3.5.
https://hg.python.org/cpython/rev/6c183537b2fb
History
Date User Action Args
2022-04-11 14:58:22adminsetgithub: 69531
2015-10-11 16:48:18azsorkinsetnosy: - azsorkin
2015-10-09 23:54:36python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg252675

resolution: fixed
stage: resolved
2015-10-09 07:25:38vinay.sajipsetmessages: + msg252594
2015-10-09 02:51:32azsorkinsetnosy: + azsorkin
2015-10-09 00:44:51rhettingersetassignee: vinay.sajip

messages: + msg252576
nosy: + rhettinger
2015-10-08 17:24:15r.david.murraysetnosy: + vinay.sajip, r.david.murray
messages: + msg252560
2015-10-08 17:05:58dasilver@cisco.comcreate