Add and expose sanitizing logic
This commit is contained in:
@@ -80,6 +80,12 @@ std::string getLastLogs() {
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sanitizeLogHead() {
|
||||||
|
if (logHead >= MAX_LOG_LINES) {
|
||||||
|
logHead = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void clearLastLogs() {
|
void clearLastLogs() {
|
||||||
for (size_t i = 0; i < MAX_LOG_LINES; i++) {
|
for (size_t i = 0; i < MAX_LOG_LINES; i++) {
|
||||||
logMessages[i][0] = '\0';
|
logMessages[i][0] = '\0';
|
||||||
|
|||||||
@@ -57,6 +57,9 @@ void logPrintf(const char* level, const char* origin, const char* format, ...);
|
|||||||
|
|
||||||
std::string getLastLogs();
|
std::string getLastLogs();
|
||||||
void clearLastLogs();
|
void clearLastLogs();
|
||||||
|
// Clamps logHead into range without wiping messages — safe to call on panic
|
||||||
|
// reboots where the panic occurred before begin() ever had a chance to run.
|
||||||
|
void sanitizeLogHead();
|
||||||
|
|
||||||
class MySerialImpl : public Print {
|
class MySerialImpl : public Print {
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -76,6 +76,10 @@ void begin() {
|
|||||||
// `clearPanic()` to clear it after dumping
|
// `clearPanic()` to clear it after dumping
|
||||||
if (!isRebootFromPanic()) {
|
if (!isRebootFromPanic()) {
|
||||||
clearPanic();
|
clearPanic();
|
||||||
|
} else {
|
||||||
|
// Panic reboot: preserve logs and panic info, but clamp logHead in case the
|
||||||
|
// panic occurred before begin() ever ran (e.g. in a static constructor).
|
||||||
|
sanitizeLogHead();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user