|
7 | 7 | from abc import ABC, abstractmethod
|
8 | 8 | from datetime import datetime
|
9 | 9 | import gzip
|
10 |
| -from typing import Any, Optional, Callable, Type, Tuple, cast, Dict, Set |
| 10 | +from typing import Any, Optional, Callable, Type, Tuple, cast, Dict |
11 | 11 |
|
12 | 12 | from types import TracebackType
|
13 | 13 |
|
14 | 14 | from typing_extensions import Literal
|
15 | 15 | from pkg_resources import iter_entry_points
|
16 | 16 |
|
| 17 | +import can.io |
17 | 18 | from ..message import Message
|
18 | 19 | from ..listener import Listener
|
19 | 20 | from .generic import BaseIOHandler, FileIOMessageWriter, MessageWriter
|
@@ -130,9 +131,8 @@ class BaseRotatingLogger(Listener, BaseIOHandler, ABC):
|
130 | 131 | :class:`~logging.handlers.BaseRotatingHandler`.
|
131 | 132 |
|
132 | 133 | Subclasses must set the `_writer` attribute upon initialization.
|
133 |
| - """ |
134 | 134 |
|
135 |
| - _supported_formats: Set[str] = set() |
| 135 | + """ |
136 | 136 |
|
137 | 137 | #: If this attribute is set to a callable, the :meth:`~BaseRotatingLogger.rotation_filename`
|
138 | 138 | #: method delegates to this callable. The parameters passed to the callable are
|
@@ -224,21 +224,17 @@ def _get_new_writer(self, filename: StringPathLike) -> FileIOMessageWriter:
|
224 | 224 | :return:
|
225 | 225 | An instance of a writer class.
|
226 | 226 | """
|
227 |
| - suffix = "".join(pathlib.Path(filename).suffixes[-2:]).lower() |
228 |
| - |
229 |
| - if suffix in self._supported_formats: |
230 |
| - logger = Logger(filename, *self.writer_args, **self.writer_kwargs) |
231 |
| - if isinstance(logger, FileIOMessageWriter): |
232 |
| - return logger |
233 |
| - elif isinstance(logger, Printer) and logger.file is not None: |
234 |
| - return cast(FileIOMessageWriter, logger) |
235 |
| - |
236 |
| - raise Exception( |
237 |
| - f'The log format "{suffix}" ' |
238 |
| - f"is not supported by {self.__class__.__name__}. " |
239 |
| - f"{self.__class__.__name__} supports the following formats: " |
240 |
| - f"{', '.join(self._supported_formats)}" |
241 |
| - ) |
| 227 | + |
| 228 | + logger = Logger(filename, *self.writer_args, **self.writer_kwargs) |
| 229 | + if isinstance(logger, FileIOMessageWriter): |
| 230 | + return logger |
| 231 | + elif isinstance(logger, Printer) and logger.file is not None: |
| 232 | + return cast(FileIOMessageWriter, logger) |
| 233 | + else: |
| 234 | + raise Exception( |
| 235 | + f"The log format \"{''.join(pathlib.Path(filename).suffixes[-2:])}" |
| 236 | + f'" is not supported by {self.__class__.__name__}' |
| 237 | + ) |
242 | 238 |
|
243 | 239 | def stop(self) -> None:
|
244 | 240 | """Stop handling new messages.
|
@@ -310,8 +306,6 @@ class SizedRotatingLogger(BaseRotatingLogger):
|
310 | 306 | :meth:`~can.Listener.stop` is called.
|
311 | 307 | """
|
312 | 308 |
|
313 |
| - _supported_formats = {".asc", ".blf", ".csv", ".log", ".txt"} |
314 |
| - |
315 | 309 | def __init__(
|
316 | 310 | self,
|
317 | 311 | base_filename: StringPathLike,
|
|
0 commit comments