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: logging.handlers.BufferingHandler capacity is unclearly specified
Type: Stage: resolved
Components: Documentation Versions: Python 3.9, Python 3.8, Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: vinay.sajip Nosy List: enrico, vinay.sajip
Priority: normal Keywords: patch

Created on 2018-02-24 10:24 by enrico, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 14498 merged vinay.sajip, 2019-07-01 06:44
PR 14507 merged miss-islington, 2019-07-01 11:42
PR 14508 merged miss-islington, 2019-07-01 11:42
Messages (6)
msg312709 - (view) Author: Enrico Zini (enrico) Date: 2018-02-24 10:24
BufferingHandler's documentatio says "Initializes the handler with a buffer of the specified capacity." but it does not specify what capacity means. One would assume the intention is to give a bound to memory usage, and that capacity is bytes.

Looking at the source instead, the check is:

        return (len(self.buffer) >= self.capacity)

and self.buffer is initialised with an empty list, so capacity is a number of lines, which cannot be used to constrain memory usage, and for which I struggle to see a use case.

I believe that the current behaviour is counterintuitive enough to deserve, if not changing, at least documenting
msg346277 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2019-06-22 12:46
Python isn't a low-level language, and there isn't *in general* a particular intention "to give a bound to memory usage". When using "buffer" in a general sense, rather than a buffer object (which is more akin to a byte-array), it's usually understood to mean a Python list (used as an array) and the capacity refers to the number of elements.

You may struggle to see a use case for specifying a buffer capacity as a number of elements rather than a byte size, but that doesn't mean that such use cases don't exist.

Are you perhaps using MicroPython in a constrained-memory environment?

In the 17 years that this code has been in Python, it's the first time AFAIK that anyone has raised the term "capacity" as potentially confusing, so I don't think such confusion is common. However, I'll be happy to update the documentation to clarify that "capacity" means "number of records buffered".
msg346320 - (view) Author: Enrico Zini (enrico) Date: 2019-06-23 13:16
Thanks! Clarifying "number of records buffered" would perfectly solve the problem for me.
msg347005 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2019-07-01 11:41
New changeset 84de34e39eb9e49b2ae691c6f67df8d7da3561de by Vinay Sajip in branch 'master':
bpo-32934: Clarified meaning of 'capacity' for BufferingHandler and MemoryHandler. (GH-14498)
https://github.com/python/cpython/commit/84de34e39eb9e49b2ae691c6f67df8d7da3561de
msg347007 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2019-07-01 12:12
New changeset 471d785dc759eb2e9c06f077f323cf136d32506b by Vinay Sajip (Miss Islington (bot)) in branch '3.7':
bpo-32934: Clarified meaning of 'capacity' for BufferingHandler and MemoryHandler. (GH-14498) (GH-14508)
https://github.com/python/cpython/commit/471d785dc759eb2e9c06f077f323cf136d32506b
msg347008 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2019-07-01 12:12
New changeset 3db5c5c7630af92336a8c0a269e05607cd68f9e7 by Vinay Sajip (Miss Islington (bot)) in branch '3.8':
bpo-32934: Clarified meaning of 'capacity' for BufferingHandler and MemoryHandler. (GH-14498) (GH-14507)
https://github.com/python/cpython/commit/3db5c5c7630af92336a8c0a269e05607cd68f9e7
History
Date User Action Args
2022-04-11 14:58:58adminsetgithub: 77115
2019-07-01 12:12:59vinay.sajipsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2019-07-01 12:12:13vinay.sajipsetmessages: + msg347008
2019-07-01 12:12:02vinay.sajipsetmessages: + msg347007
2019-07-01 11:42:16miss-islingtonsetpull_requests: + pull_request14324
2019-07-01 11:42:08miss-islingtonsetpull_requests: + pull_request14323
2019-07-01 11:41:25vinay.sajipsetmessages: + msg347005
2019-07-01 06:44:28vinay.sajipsetkeywords: + patch
stage: needs patch -> patch review
pull_requests: + pull_request14314
2019-06-23 13:16:48enricosetmessages: + msg346320
2019-06-22 12:46:26vinay.sajipsetmessages: + msg346277

assignee: vinay.sajip
components: + Documentation, - Library (Lib)
type: behavior ->
stage: needs patch
2019-06-22 04:45:10xtreaksetnosy: + vinay.sajip

type: behavior
versions: + Python 3.7, Python 3.8, Python 3.9, - Python 3.6
2018-02-24 10:24:49enricocreate