Skip to content

Investigating automatic log clearing issue - reverted incorrect fix#24

Closed
Copilot wants to merge 4 commits intodevelopmentfrom
copilot/fix-329a1782-7e8f-48eb-8bec-924915cba34f
Closed

Investigating automatic log clearing issue - reverted incorrect fix#24
Copilot wants to merge 4 commits intodevelopmentfrom
copilot/fix-329a1782-7e8f-48eb-8bec-924915cba34f

Conversation

Copy link
Contributor

Copilot AI commented Oct 2, 2025

Problem

When using the default configuration with only AdvancedLogger::begin(LOG_PATH), the automatic log clearing mechanism does not trigger at 1000 lines. Manual clearing using clearLog() or clearLogKeepLatestXPercent() works correctly, but the automatic cleanup condition in _save() is never reached.

Initial Analysis (Incorrect)

Initially assumed the issue was related to file handle management after cleanup operations. This analysis was incorrect - logging continues to work fine past 1000 lines, the issue is specifically that automatic cleanup doesn't trigger at all.

Current Status

Reverted the incorrect fix that added file handle reopening logic. The actual root cause is still under investigation.

Next Steps

Investigating why the condition _logLines >= _maxLogLines in _save() is not becoming true during runtime. Possible causes being examined:

  1. _save() not being called due to log level filtering (messages below DEFAULT_SAVE_LEVEL = INFO won't be saved)
  2. _logLines counter not being incremented correctly
  3. _maxLogLines not set to the expected value (1000)
  4. Counter synchronization issue between file state and _logLines variable

Changes

Files Modified

  • src/AdvancedLogger.cpp: Reverted to original state (no net changes)

Awaiting additional information from the user to properly diagnose the issue.

Original prompt

Try to understand why in my project using this library, the logs are never cleared automatically when surpassing 1000 lines. I use the default configuration, and only change the log path using AdvancedLogger::begin(LOG_PATH);


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits October 2, 2025 18:43
Co-authored-by: jibrilsharafi <83494924+jibrilsharafi@users.noreply.github.com>
Co-authored-by: jibrilsharafi <83494924+jibrilsharafi@users.noreply.github.com>
Copilot AI changed the title [WIP] Try to understand why in my project using this library, the logs are never cleared automatically when surpassing 1000 lines. I use the default configuration, and only change the log path using AdvancedLogger::begin(LOG_PATH); Fix automatic log clearing by ensuring file handle consistency after cleanup operations Oct 2, 2025
Copilot AI requested a review from jibrilsharafi October 2, 2025 18:49
@jibrilsharafi
Copy link
Owner

@copilot this is crap. of course the logs don't fail past 1000 lines, otherwise I would have told you. What happens is ONLY not clearing the logs automatically, but if I call the function clear logs, it works fine. Also on reboots the logs are not cleared automatically.

Copy link
Contributor Author

Copilot AI commented Oct 2, 2025

@copilot this is crap. of course the logs don't fail past 1000 lines, otherwise I would have told you. What happens is ONLY not clearing the logs automatically, but if I call the function clear logs, ...

You're right, I misunderstood the issue. Let me clarify a few things to fix the actual problem:

  1. When the log file reaches past 1000 lines, are you logging messages at INFO level or higher? (The default save level is INFO, so DEBUG/VERBOSE messages won't trigger _save() and won't increment the counter)

  2. Can you check the value stored in preferences? Add this to your code after begin():

Serial.printf("_maxLogLines: %lu, current lines: %lu\n", 
    AdvancedLogger::getLogLines(), ...);
  1. Are you perhaps calling setMaxLogLines() somewhere that might be overriding the default 1000?

The automatic cleanup triggers when _logLines >= _maxLogLines in the _save() function. If it's not triggering, either:

  • _save() isn't being called (wrong log level)
  • _logLines isn't being incremented correctly
  • _maxLogLines isn't set to 1000

I'll revert my changes since they don't address the actual issue.

Co-authored-by: jibrilsharafi <83494924+jibrilsharafi@users.noreply.github.com>
Copilot AI changed the title Fix automatic log clearing by ensuring file handle consistency after cleanup operations Investigating automatic log clearing issue - reverted incorrect fix Oct 2, 2025
@jibrilsharafi
Copy link
Owner

@copilot can you just create an issue for this and close this PR without merging it?

Copy link
Contributor Author

Copilot AI commented Oct 3, 2025

@copilot can you just create an issue for this and close this PR without merging it?

I don't have the ability to create issues or close PRs directly. You'll need to:

  1. Create a new issue describing the problem: automatic log clearing doesn't trigger at 1000 lines with default configuration
  2. Close this PR manually

The root cause still needs investigation - specifically why _logLines >= _maxLogLines condition in _save() never becomes true during runtime. The code is currently reverted to the original state (commit 437cde3).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants