-
Notifications
You must be signed in to change notification settings - Fork 633
Fix the sized rotating logger size bug for the blf writer #1360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
977e1e0
Add print statements to highlight the bug
824893b
Fix the rollover for the blf writer
6f0a298
Fix change to run with all logger types
276b253
Remove unnecessary statement
c195001
Remove unnecessary print statement for file.tell()
c68f155
Add **options to API of all Writers
j-c-cook 3c35108
Add type definition to **options
j-c-cook 611fc4f
Update help documentation for -s logger option
j-c-cook 55401ea
Refactor line width
j-c-cook File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
import datetime | ||
import time | ||
import logging | ||
from typing import List, BinaryIO, Generator, Union, Tuple, Optional, cast | ||
from typing import List, BinaryIO, Generator, Union, Tuple, Optional, cast, Any | ||
|
||
from ..message import Message | ||
from ..util import len2dlc, dlc2len, channel2int | ||
|
@@ -358,9 +358,6 @@ class BLFWriter(FileIOMessageWriter): | |
|
||
file: BinaryIO | ||
|
||
#: Max log container size of uncompressed data | ||
max_container_size = 128 * 1024 | ||
|
||
#: Application identifier for the log writer | ||
application_id = 5 | ||
|
||
|
@@ -370,6 +367,7 @@ def __init__( | |
append: bool = False, | ||
channel: int = 1, | ||
compression_level: int = -1, | ||
**options: Any, | ||
) -> None: | ||
""" | ||
:param file: a path-like object or as file-like object to write to | ||
|
@@ -400,6 +398,11 @@ def __init__( | |
self.compression_level = compression_level | ||
self._buffer: List[bytes] = [] | ||
self._buffer_size = 0 | ||
#: Max log container size of uncompressed data | ||
if "max_container_size" in options: | ||
self.max_container_size = options["max_container_size"] | ||
else: | ||
self.max_container_size = 128 * 1024 # bytes | ||
Comment on lines
+401
to
+405
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is now an adjustable max buffer size. |
||
if append: | ||
# Parse file header | ||
data = self.file.read(FILE_HEADER_STRUCT.size) | ||
|
@@ -530,6 +533,7 @@ def _add_object(self, obj_type, data, timestamp=None): | |
|
||
self._buffer_size += obj_size + padding_size | ||
self.object_count += 1 | ||
a = len(zlib.compress(memoryview(b"".join(self._buffer)), 1)) | ||
if self._buffer_size >= self.max_container_size: | ||
self._flush() | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -215,6 +215,7 @@ def main() -> None: | |
|
||
options = {"append": results.append} | ||
if results.file_size: | ||
options["max_container_size"] = results.file_size # bytes | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm now passing in |
||
logger = SizedRotatingLogger( | ||
base_filename=results.log_file, max_bytes=results.file_size, **options | ||
) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
**options
to BLFWriter API.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming that
compression_level
is specific to the BLFWriter, perhaps it should be moved into theoptions
dict as well?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Arguments specific to a
Writer
could be made more accessible if able to be set by**options
. Currently, the only way to setcompression_level
would be to bypass theLogger
(orRollingLogger
) object and call theBLFWriter
object itself.When going about these changes, I'll want to make sure that the API is either unaffected by this improvement, or that a deprecation warning is added (similar to what I did here for
SizedRotatingLogger
).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is specific to the BlfWriter (and soon Mf4Writer) but i think it's more readable if it is not hidden away in
**options
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have confirmed that
compression_level
can be modified by passing via the argument in**kwargs
. @zariiii9003's CLI arguments https://github.com/zariiii9003/python-can/tree/extra_args2 will provide the ability to modify variables such ascompression_level
. For example:Once #1366 is merged, I will close this PR. The combination of #1367 and #1366 will resolve everything I had intended from this PR.