openclaw - 💡(How to fix) Fix [Feature]: Log files are created but never used for writing (no effective log rotation) [1 participants]

Official PRs (…)
ON THIS PAGE

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#70896Fetched 2026-04-24 10:38:07
View on GitHub
Comments
0
Participants
1
Timeline
1
Reactions
0
Author
Participants
Timeline (top)
labeled ×1

Log files can be created but logger does not switch write target, lacking effective log rotation

Root Cause

Log files can be created but logger does not switch write target, lacking effective log rotation

RAW_BUFFERClick to expand / collapse

Summary

Log files can be created but logger does not switch write target, lacking effective log rotation

Problem to solve

Currently, the gateway may generate new log files (e.g., with date-based filenames), but the logger continues writing to the originally opened file.

Even when a new log file exists (such as after a date change), it is not used for subsequent log writes. This results in:

  • Logs continuously accumulating in a single file
  • Newly created log files remaining empty or unused
  • No effective log rotation mechanism in practice

This behavior suggests that the logger holds a persistent file descriptor and does not support reopening or switching the output target.

As a result, users must manually restart the gateway or rely on external tools (e.g., logrotate) to achieve log separation.

Proposed solution

Implement a proper log rotation mechanism that allows the logger to switch its write target when conditions change.

Expected behavior:

  • When a new log file is generated (e.g., due to date change), the logger should automatically switch to writing into the new file
  • Alternatively, support time-based (daily) or size-based rotation
  • Provide configuration options for log management (e.g., rotation policy, retention)

Possible implementation approaches:

  • Detect date changes and reopen the log file
  • Recreate or rebind the file stream when rotation conditions are met
  • Integrate a rotating file transport mechanism

Alternatives considered

Using external tools such as logrotate can partially mitigate the issue, but has limitations:

  • Requires additional system-level configuration
  • Not cross-platform friendly (especially for non-Linux environments)
  • Does not address the underlying issue that the logger does not switch file descriptors

Manually restarting the gateway also works but is not practical for long-running deployments.

Impact

Affected:

  • All long-running gateway deployments
  • Users relying on built-in logging behavior

Severity:

  • Medium (does not break core functionality, but impacts maintainability)

Frequency:

  • Always (occurs in any long-running session)

Consequence:

  • Log files grow indefinitely
  • Increased difficulty in debugging and log analysis
  • Additional operational overhead (manual restarts or external tooling)

Evidence/examples

Observed behavior:

  • A new log file with a new date may appear
  • However, subsequent logs continue to be written into the old file

This indicates that log file creation and log writing are not properly synchronized.

This behavior can be reproduced by:

  1. Starting the gateway before midnight
  2. Letting it run across a date boundary
  3. Observing that logging continues in the original file

Additional information

The current behavior may be misleading, as date-based filenames suggest support for daily log separation, but actual write behavior does not reflect this.

A proper log rotation mechanism would significantly improve usability and operational reliability for long-running services.

Backward compatibility with existing configurations should be maintained.

extent analysis

TL;DR

Implement a log rotation mechanism that allows the logger to switch its write target when conditions change, such as detecting date changes and reopening the log file.

Guidance

  • Detect date changes and reopen the log file to ensure the logger writes to the new file.
  • Consider integrating a rotating file transport mechanism to support time-based or size-based rotation.
  • Provide configuration options for log management, such as rotation policy and retention, to improve usability.
  • To verify the fix, test the logger by running it across a date boundary and checking that subsequent logs are written to the new file.

Example

import logging
from logging.handlers import RotatingFileHandler

# Create a rotating file handler
handler = RotatingFileHandler('log_file.log', maxBytes=1000000, backupCount=5)

# Create a logger and add the handler
logger = logging.getLogger()
logger.addHandler(handler)

# Test the logger by writing logs across a date boundary

Notes

The proposed solution should maintain backward compatibility with existing configurations. The implementation approach may vary depending on the specific logging framework and language used.

Recommendation

Apply a workaround by integrating a rotating file transport mechanism, as it provides a more robust and flexible solution for log rotation.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING