From 6f6c3256a8fb7487818753f971e24b3278ff9d50 Mon Sep 17 00:00:00 2001 From: j-c-cook Date: Thu, 29 Sep 2022 10:07:11 -0500 Subject: [PATCH 01/11] Modify `file_size` help doc string --- can/logger.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/can/logger.py b/can/logger.py index 0b73dd785..6364cd86c 100644 --- a/can/logger.py +++ b/can/logger.py @@ -193,9 +193,8 @@ def main() -> None: "--file_size", dest="file_size", type=int, - help="Maximum file size in bytes (or for the case of blf, maximum " - "buffer size before compression and flush to file). Rotate log " - "file when size threshold is reached.", + help="Maximum file size in bytes. Rotate log file when size threshold " + "is reached.", default=None, ) From 18241acc527b82ee81aa0e546410a158b18ad1d1 Mon Sep 17 00:00:00 2001 From: j-c-cook Date: Thu, 29 Sep 2022 11:08:49 -0500 Subject: [PATCH 02/11] Add note to BLFWriter --- can/io/blf.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/can/io/blf.py b/can/io/blf.py index 93fa54ca2..ca6733651 100644 --- a/can/io/blf.py +++ b/can/io/blf.py @@ -359,6 +359,13 @@ def _parse_data(self, data): class BLFWriter(FileIOMessageWriter): """ Logs CAN data to a Binary Logging File compatible with Vector's tools. + + .. note:: + The `buffer_size` will always stay under the `max_container_size`, which + is enforced at the end of the `_add_object` function. If the + `max_container_size > :attr:io.logger.RotatingLogger.max_bytes` then + the resulting file size will be less than described due to an + unaccounted compression of the buffer when writing to the file. """ file: BinaryIO From b26fd57cb9193c7d708a6e2fc5650e10942200e5 Mon Sep 17 00:00:00 2001 From: j-c-cook Date: Thu, 29 Sep 2022 17:08:11 -0500 Subject: [PATCH 03/11] Revert "Add note to BLFWriter" This reverts commit 18241acc527b82ee81aa0e546410a158b18ad1d1. --- can/io/blf.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/can/io/blf.py b/can/io/blf.py index ca6733651..93fa54ca2 100644 --- a/can/io/blf.py +++ b/can/io/blf.py @@ -359,13 +359,6 @@ def _parse_data(self, data): class BLFWriter(FileIOMessageWriter): """ Logs CAN data to a Binary Logging File compatible with Vector's tools. - - .. note:: - The `buffer_size` will always stay under the `max_container_size`, which - is enforced at the end of the `_add_object` function. If the - `max_container_size > :attr:io.logger.RotatingLogger.max_bytes` then - the resulting file size will be less than described due to an - unaccounted compression of the buffer when writing to the file. """ file: BinaryIO From a4d04dcbcf4991ab1017998c7f1b32cc4e37c197 Mon Sep 17 00:00:00 2001 From: j-c-cook Date: Thu, 29 Sep 2022 17:10:09 -0500 Subject: [PATCH 04/11] Add in a note about the nuanced file size in help statement based on input from @zariiii9003 --- can/logger.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/can/logger.py b/can/logger.py index 6364cd86c..adf7803eb 100644 --- a/can/logger.py +++ b/can/logger.py @@ -194,7 +194,9 @@ def main() -> None: dest="file_size", type=int, help="Maximum file size in bytes. Rotate log file when size threshold " - "is reached.", + "is reached. (The resulting file size is dependent on the logger " + "implementation and is not guaranteed to be exactly what is specified" + "here.)", default=None, ) From cced4ad8a2be32f0237dbd2e68ca30f8243134aa Mon Sep 17 00:00:00 2001 From: j-c-cook Date: Thu, 29 Sep 2022 17:25:00 -0500 Subject: [PATCH 05/11] Modify help statement to clarify consistency --- can/logger.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/can/logger.py b/can/logger.py index adf7803eb..bf257debc 100644 --- a/can/logger.py +++ b/can/logger.py @@ -194,9 +194,9 @@ def main() -> None: dest="file_size", type=int, help="Maximum file size in bytes. Rotate log file when size threshold " - "is reached. (The resulting file size is dependent on the logger " - "implementation and is not guaranteed to be exactly what is specified" - "here.)", + "is reached. (The resulting file sizes will be consistent, but is not " + "guaranteed to be exactly what is specified here due to the rollover " + "conditions being specific on the logger implementation.)", default=None, ) From 87ecc6421992d3492f55d6c5f5f392150b186471 Mon Sep 17 00:00:00 2001 From: j-c-cook Date: Thu, 29 Sep 2022 17:26:45 -0500 Subject: [PATCH 06/11] Minor tweak --- can/logger.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/can/logger.py b/can/logger.py index bf257debc..38b160617 100644 --- a/can/logger.py +++ b/can/logger.py @@ -196,7 +196,7 @@ def main() -> None: help="Maximum file size in bytes. Rotate log file when size threshold " "is reached. (The resulting file sizes will be consistent, but is not " "guaranteed to be exactly what is specified here due to the rollover " - "conditions being specific on the logger implementation.)", + "conditions being logger implementation specific.)", default=None, ) From c39719ccf88ef9c6eae8facffcac063a10f519c5 Mon Sep 17 00:00:00 2001 From: j-c-cook Date: Thu, 29 Sep 2022 18:06:31 -0500 Subject: [PATCH 07/11] Control BLFWriter max container size --- can/io/logger.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/can/io/logger.py b/can/io/logger.py index ec34079b4..dc616d6f4 100644 --- a/can/io/logger.py +++ b/can/io/logger.py @@ -325,6 +325,12 @@ def __init__( self.base_filename = os.path.abspath(base_filename) self.max_bytes = max_bytes + # BLFWriter specific + _128_kb = 128 * 1024 + if kwargs.get('max_container_size', 1) and max_bytes > 0: + kwargs['max_container_size'] = \ + _128_kb if max_bytes > _128_kb else max_bytes * 0.1 + self._writer = self._get_new_writer(self.base_filename) def should_rollover(self, msg: Message) -> bool: From 3afb140a09c4c0a5394f5a89d7e0d49397c4a37d Mon Sep 17 00:00:00 2001 From: j-c-cook Date: Thu, 29 Sep 2022 18:11:47 -0500 Subject: [PATCH 08/11] Fix formatting --- can/io/logger.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/can/io/logger.py b/can/io/logger.py index dc616d6f4..e7438abc5 100644 --- a/can/io/logger.py +++ b/can/io/logger.py @@ -327,9 +327,10 @@ def __init__( # BLFWriter specific _128_kb = 128 * 1024 - if kwargs.get('max_container_size', 1) and max_bytes > 0: - kwargs['max_container_size'] = \ + if kwargs.get("max_container_size", 1) and max_bytes > 0: + kwargs["max_container_size"] = ( _128_kb if max_bytes > _128_kb else max_bytes * 0.1 + ) self._writer = self._get_new_writer(self.base_filename) From 42c06becd1a3f9d6c3ef09395289c309b71a2d93 Mon Sep 17 00:00:00 2001 From: Jack Cook Date: Mon, 3 Oct 2022 08:41:58 -0500 Subject: [PATCH 09/11] Update can/logger.py Co-authored-by: zariiii9003 <52598363+zariiii9003@users.noreply.github.com> --- can/logger.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/can/logger.py b/can/logger.py index 38b160617..8cb201987 100644 --- a/can/logger.py +++ b/can/logger.py @@ -194,7 +194,7 @@ def main() -> None: dest="file_size", type=int, help="Maximum file size in bytes. Rotate log file when size threshold " - "is reached. (The resulting file sizes will be consistent, but is not " + "is reached. (The resulting file sizes will be consistent, but are not " "guaranteed to be exactly what is specified here due to the rollover " "conditions being logger implementation specific.)", default=None, From 6fa459d1d694646e8ae0aa5f56142e120cc8a1d9 Mon Sep 17 00:00:00 2001 From: j-c-cook Date: Mon, 3 Oct 2022 08:44:11 -0500 Subject: [PATCH 10/11] Revert "Fix formatting" This reverts commit 3afb140a09c4c0a5394f5a89d7e0d49397c4a37d. --- can/io/logger.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/can/io/logger.py b/can/io/logger.py index e7438abc5..dc616d6f4 100644 --- a/can/io/logger.py +++ b/can/io/logger.py @@ -327,10 +327,9 @@ def __init__( # BLFWriter specific _128_kb = 128 * 1024 - if kwargs.get("max_container_size", 1) and max_bytes > 0: - kwargs["max_container_size"] = ( + if kwargs.get('max_container_size', 1) and max_bytes > 0: + kwargs['max_container_size'] = \ _128_kb if max_bytes > _128_kb else max_bytes * 0.1 - ) self._writer = self._get_new_writer(self.base_filename) From 053ead411d6b69f54fde6381845ac0a7fa914a3f Mon Sep 17 00:00:00 2001 From: j-c-cook Date: Mon, 3 Oct 2022 08:47:31 -0500 Subject: [PATCH 11/11] Revert "Control BLFWriter max container size" This reverts commit c39719ccf88ef9c6eae8facffcac063a10f519c5. --- can/io/logger.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/can/io/logger.py b/can/io/logger.py index dc616d6f4..ec34079b4 100644 --- a/can/io/logger.py +++ b/can/io/logger.py @@ -325,12 +325,6 @@ def __init__( self.base_filename = os.path.abspath(base_filename) self.max_bytes = max_bytes - # BLFWriter specific - _128_kb = 128 * 1024 - if kwargs.get('max_container_size', 1) and max_bytes > 0: - kwargs['max_container_size'] = \ - _128_kb if max_bytes > _128_kb else max_bytes * 0.1 - self._writer = self._get_new_writer(self.base_filename) def should_rollover(self, msg: Message) -> bool: