python-can icon indicating copy to clipboard operation
python-can copied to clipboard

Generalize the RotatingLogger; size, time or first of the two trigger the rollover

Open j-c-cook opened this issue 3 years ago • 4 comments

A RotatingLogger object is created that constrains the file by file size, time or both. In the case of when both are constrained, the first that occurs will trigger the rollover.

  • [x] Adds a deprecation warning to the TimedRotatingLogger. The TimedRotatingLogger now inherits from the generalized RotatingLogger.
  • [x] When time is a constraint for the RotatingLogger, don't rollover if there have been no messages received since the last rollover
  • [x] Update the doc string under RotatingLogger
  • [x] Fix the tests to make them run with these changes

closes #1364

j-c-cook avatar Aug 07 '22 22:08 j-c-cook

The BLFWriter will be able to be used like the following:

python -m can.logger -i socketcan -c vcan0 -b 250000 -f file.blf -t 600 --compression-level=1 --max-container-size=200000

Here, a rollover would occur every 5 seconds, or when the buffer and file size becomes 200000. Note that the default max_container_size is 128 * 1024.

Another option would be:

python -m can.logger -i socketcan -c vcan0 -b 250000 -f file.log -t 600 -s 100000

A rollover would occur every 5 seconds, or when the file size becomes 100000 bytes.

j-c-cook avatar Aug 11 '22 14:08 j-c-cook

  • [x] When time is a constraint for the RotatingLogger, don't rollover if there have been no messages received since the last rollover

This is inherent to the implementation of logger. When a message is received then the logger is called. The file cannot rollover without there being a message passed to logger. https://github.com/hardbyte/python-can/blob/88fc8e5bcf56ab2f9f2041242733ad90bb7101b4/can/logger.py#L246-L251

j-c-cook avatar Aug 11 '22 21:08 j-c-cook

Codecov Report

Merging #1365 (22bf537) into develop (4b1acde) will increase coverage by 0.12%. The diff coverage is 100.00%.

:exclamation: Current head 22bf537 differs from pull request most recent head cabafb4. Consider uploading reports for the commit cabafb4 to get more accurate results

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1365      +/-   ##
===========================================
+ Coverage    65.16%   65.29%   +0.12%     
===========================================
  Files           81       81              
  Lines         8853     8779      -74     
===========================================
- Hits          5769     5732      -37     
+ Misses        3084     3047      -37     

codecov[bot] avatar Sep 29 '22 14:09 codecov[bot]

@zariiii9003 This RotatingLogger class has been successfully running on multiple devices, that I manage, for about a month now (prior to the refactoring I've done today). There have been tens and possibly hundreds of hours of testing on the class by now. It is ready for a review. Please let me know what you think, thanks.

j-c-cook avatar Sep 29 '22 15:09 j-c-cook