mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-17 19:23:34 +08:00
feat(logger): add SDLOG_ROTATE, disentangle cleanup thresholds
The previous cleanup logic conflated two independent concerns into
SDLOG_MAX_SIZE: the maximum size of a single log file (rotation
trigger) AND the minimum free space to maintain. That was broken:
the 4095 MB default meant "keep 4 GB free", which over-cleaned on
large SD cards and was impossible to satisfy on small flash.
Disentangle the two:
- SDLOG_ROTATE (new, int %, default 90): maximum disk usage percentage.
Cleanup guarantees at least (100 - SDLOG_ROTATE)% free even during
writing of a new log file. Setting 0 disables space-based cleanup;
100 allows filling the disk completely.
- SDLOG_MAX_SIZE (default lowered from 4095 to 1024): pure max file
size. The value is added on top of the rotate-derived threshold as
headroom for the next file write, so the rotate guarantee holds
even mid-write.
- SDLOG_DIRS_MAX: removed. Directory count limits were confusing and
orthogonal to the space-management goal; free-space cleanup alone
covers the use case. Drop the param and all remaining overrides
(rc.board_defaults, rcS, rc.replay, 1002_standard_vtol.hil).
Cleanup threshold is now:
((100 - SDLOG_ROTATE)% of disk) + SDLOG_MAX_SIZE
Small-flash boards can override SDLOG_MAX_SIZE to get more retained
logs within the available space. kakuteh7v2 and airbrainh743 drop
their SDLOG_DIRS_MAX overrides accordingly.
Update docs/en/dev_log/logging.md with the new semantics and a
worked example for the typical 8 GB SD case.
This commit is contained in:
@@ -86,10 +86,19 @@ There are several scripts to analyze and convert logging files in the [pyulog](h
|
||||
## Log Cleanup
|
||||
|
||||
PX4 automatically manages log storage by cleaning up old logs when starting to log.
|
||||
Cleanup is triggered based on two criteria:
|
||||
Two parameters control how much space logs may use:
|
||||
|
||||
- **Storage-based cleanup**: Ensures minimum free space (300 MB or 10% of disk, whichever is smaller) is available.
|
||||
- **Count-based cleanup**: If [SDLOG_DIRS_MAX](../advanced_config/parameter_reference.md#SDLOG_DIRS_MAX) is set, limits the total number of log directories.
|
||||
- [SDLOG_ROTATE](../advanced_config/parameter_reference.md#SDLOG_ROTATE) is the maximum disk usage percentage (default 90).
|
||||
Cleanup ensures at least `(100 - SDLOG_ROTATE)%` of the disk stays free at all times, **even while writing a new log file**.
|
||||
Setting it to `0` disables space-based cleanup entirely; setting it to `100` lets logs fill the disk completely.
|
||||
- [SDLOG_MAX_SIZE](../advanced_config/parameter_reference.md#SDLOG_MAX_SIZE) is the maximum size of a single log file in MB
|
||||
(default 1024). It also reserves headroom so that a full new file always fits after cleanup.
|
||||
|
||||
At log start, the cleanup threshold is `((100 - SDLOG_ROTATE)% of disk) + SDLOG_MAX_SIZE`.
|
||||
Oldest logs are deleted until the free space meets this threshold.
|
||||
For example, on an 8 GB card with defaults, cleanup keeps at least `820 + 1024 = ~1.8 GB` free at log start,
|
||||
so ~6 GB is usable for logs and disk usage never exceeds 90% during writing.
|
||||
Small flash targets override `SDLOG_MAX_SIZE` to a smaller value to keep more logs within the available space.
|
||||
|
||||
The cleanup algorithm prioritizes deleting logs from the directory naming scheme not currently in use.
|
||||
PX4 uses two directory naming schemes:
|
||||
|
||||
Reference in New Issue
Block a user