diff --git a/can/io/asc.py b/can/io/asc.py index 3a320f007..c57866b02 100644 --- a/can/io/asc.py +++ b/can/io/asc.py @@ -349,9 +349,7 @@ class ASCWriter(FileIOMessageWriter): FORMAT_EVENT = "{timestamp: 9.6f} {message}\n" def __init__( - self, - file: Union[StringPathLike, TextIO], - channel: int = 1, + self, file: Union[StringPathLike, TextIO], channel: int = 1, **options: Any ) -> None: """ :param file: a path-like object or as file-like object to write to diff --git a/can/io/blf.py b/can/io/blf.py index efeba9488..0c8420ea6 100644 --- a/can/io/blf.py +++ b/can/io/blf.py @@ -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 if append: # Parse file header data = self.file.read(FILE_HEADER_STRUCT.size) diff --git a/can/io/canutils.py b/can/io/canutils.py index 0cca82eb8..5c11d4175 100644 --- a/can/io/canutils.py +++ b/can/io/canutils.py @@ -5,7 +5,7 @@ """ import logging -from typing import Generator, TextIO, Union +from typing import Generator, TextIO, Union, Any from can.message import Message from .generic import FileIOMessageWriter, MessageReader @@ -132,6 +132,7 @@ def __init__( file: Union[StringPathLike, TextIO], channel: str = "vcan0", append: bool = False, + **options: Any, ): """ :param file: a path-like object or as file-like object to write to diff --git a/can/io/csv.py b/can/io/csv.py index 0161b4f55..5c533939a 100644 --- a/can/io/csv.py +++ b/can/io/csv.py @@ -10,7 +10,7 @@ """ from base64 import b64encode, b64decode -from typing import TextIO, Generator, Union +from typing import TextIO, Generator, Union, Any from can.message import Message from .generic import FileIOMessageWriter, MessageReader @@ -87,7 +87,7 @@ class CSVWriter(FileIOMessageWriter): file: TextIO def __init__( - self, file: Union[StringPathLike, TextIO], append: bool = False + self, file: Union[StringPathLike, TextIO], append: bool = False, **options: Any ) -> None: """ :param file: a path-like object or a file-like object to write to. diff --git a/can/logger.py b/can/logger.py index 5aff5e4e1..1ec5afa48 100644 --- a/can/logger.py +++ b/can/logger.py @@ -170,8 +170,9 @@ def main() -> None: "--file_size", dest="file_size", type=int, - help="Maximum file size in bytes. Rotate log file when size threshold " - "is reached.", + 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.", default=None, ) @@ -215,6 +216,7 @@ def main() -> None: options = {"append": results.append} if results.file_size: + options["max_container_size"] = results.file_size # bytes logger = SizedRotatingLogger( base_filename=results.log_file, max_bytes=results.file_size, **options )