Thanks to visit codestin.com
Credit goes to github.com

Skip to content

SizedRotatingLogger Filename Format Bug #1792

@KSpakes87

Description

@KSpakes87

Describe the bug

When giving a filename to SizedRotatingLogger that contains multiple periods/dots in the filename (ex 2017_Jeep_Grand_Cherokee_3.6L_V6.log), it returns a ValueError

It appears that whatever function is checking the file extension is splitting on the . and selecting element 1. If this is so, it would be better to split and select element -1.

Example:

filename = "2017_Jeep_Grand_Cherokee_3.6L_V6.log"
file_ext = filename.split('.')[-1]

To Reproduce

Add more than one . in the filename.

Expected behavior

The file extension at the end of the filename string should be checked, not element 1.

Additional context

OS and version: Windows 10 (WSL)
Python version: v3.10.12
python-can version: v4.3.1
python-can interface/s (if applicable): can0/vcan0

Traceback and logs
ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/REDACTED_PATH/venv/lib/python3.10/site-packages/uvicorn/protocols/http/h11_impl.py", line 408, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
  File "/REDACTED_PATH/venv/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 84, in __call__
    return await self.app(scope, receive, send)
  File "/REDACTED_PATH/venv/lib/python3.10/site-packages/fastapi/applications.py", line 1054, in __call__
    await super().__call__(scope, receive, send)
  File "/REDACTED_PATH/venv/lib/python3.10/site-packages/starlette/applications.py", line 116, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/REDACTED_PATH/venv/lib/python3.10/site-packages/starlette/middleware/errors.py", line 186, in __call__
    raise exc
  File "/REDACTED_PATH/venv/lib/python3.10/site-packages/starlette/middleware/errors.py", line 164, in __call__
    await self.app(scope, receive, _send)
  File "/REDACTED_PATH/venv/lib/python3.10/site-packages/starlette/middleware/cors.py", line 91, in __call__
    await self.simple_response(scope, receive, send, request_headers=headers)
  File "/REDACTED_PATH/venv/lib/python3.10/site-packages/starlette/middleware/cors.py", line 146, in simple_response
    await self.app(scope, receive, send)
  File "/REDACTED_PATH/venv/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 62, in __call__
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
  File "/REDACTED_PATH/venv/lib/python3.10/site-packages/starlette/_exception_handler.py", line 55, in wrapped_app
    raise exc
  File "/REDACTED_PATH/venv/lib/python3.10/site-packages/starlette/_exception_handler.py", line 44, in wrapped_app
    await app(scope, receive, sender)
  File "/REDACTED_PATH/venv/lib/python3.10/site-packages/starlette/routing.py", line 746, in __call__
    await route.handle(scope, receive, send)
  File "/REDACTED_PATH/venv/lib/python3.10/site-packages/starlette/routing.py", line 288, in handle
    await self.app(scope, receive, send)
  File "/REDACTED_PATH/venv/lib/python3.10/site-packages/starlette/routing.py", line 75, in app
    await wrap_app_handling_exceptions(app, request)(scope, receive, send)
  File "/REDACTED_PATH/venv/lib/python3.10/site-packages/starlette/_exception_handler.py", line 55, in wrapped_app
    raise exc
  File "/REDACTED_PATH/venv/lib/python3.10/site-packages/starlette/_exception_handler.py", line 44, in wrapped_app
    await app(scope, receive, sender)
  File "/REDACTED_PATH/venv/lib/python3.10/site-packages/starlette/routing.py", line 70, in app
    response = await func(request)
  File "/REDACTED_PATH/venv/lib/python3.10/site-packages/fastapi/routing.py", line 299, in app
    raise e
  File "/REDACTED_PATH/venv/lib/python3.10/site-packages/fastapi/routing.py", line 294, in app
    raw_response = await run_endpoint_function(
  File "/REDACTED_PATH/venv/lib/python3.10/site-packages/fastapi/routing.py", line 191, in run_endpoint_function
    return await dependant.call(**values)
  File "/REDACTED_PATH/main.py", line 220, in recordCANBus
    logger = cf.create_logger(filename=os.path.join(path, my_file))
  File "/REDACTED_PATH/tools/can_funcs.py", line 36, in create_logger
    logger = can.SizedRotatingLogger(base_filename=filename,
  File "/REDACTED_PATH/venv/lib/python3.10/site-packages/can/io/logger.py", line 263, in _get_new_writer
    raise ValueError(
  ValueError: The log format ".6L_V6.log" is not supported by SizedRotatingLogger. SizedRotatingLogger supports the following formats: .log, .blf, .csv, .txt, .asc
logger = can.SizedRotatingLogger(base_filename="2017_Jeep_Grand_Cherokee_3.6L_V6.log",
                                                       max_bytes=5 * 1024 ** 2)

Metadata

Metadata

Assignees

Labels

bugfile-ioabout reading & writing to files

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions