openclaw - ✅(Solved) Fix [Bug]: Subsystem logger caches file path on first call, logs written to wrong date file after midnight [3 pull requests, 3 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

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#54381Fetched 2026-04-08 01:28:20
View on GitHub
Comments
3
Participants
3
Timeline
10
Reactions
0
Timeline (top)
commented ×3cross-referenced ×3labeled ×2referenced ×2

Description

When OpenClaw Gateway runs as a long-running service, the subsystem logger ( createSubsystemLogger ) caches the file logger on first call. After midnight, new logs continue to be written to the previous day's log file instead of creating/using a new dated file.

Steps to Reproduce

  1. Start OpenClaw Gateway on Day 1 (e.g., March 21)
  2. Keep Gateway running past midnight into Day 2 (e.g., March 24)
  3. Send new requests to Gateway
  4. Check log files - logs from March 24 are written to openclaw-2026-03-21.log instead of openclaw-2026-03-24.log

Root Cause Analysis

In subsystem-D46iuydz.js , the createSubsystemLogger function:

function createSubsystemLogger(subsystem) { let fileLogger = null; const getFileLogger = () => { if (!fileLogger) fileLogger = getChildLogger({ subsystem }); return fileLogger; }; // ... }

The fileLogger is lazily initialized once and cached forever. Even though getLogger() properly detects date changes via settingsChanged() and rebuilds the logger with a new file path, the subsystem logger never re-checks this - it just returns the cached fileLogger .

Expected Behavior

Logs should be written to the correct dated log file based on the current local date. When the date changes, the subsystem logger should detect this and use a new file.

Actual Behavior

Logs continue to be written to the log file from when the Gateway process started.

Workaround

Restart Gateway daily (e.g., via cron):

0 0 * * * openclaw gateway restart

Suggested Fix

  1. Add date checking in getFileLogger() to detect when the date has changed
  2. Or periodically check settingsChanged() in createSubsystemLogger
  3. Or use a similar pattern to getLogger() which properly detects and handles settings changes

Environment

  • OpenClaw version: 2026.3.23-2
  • OS: Linux
  • Runtime: Gateway (long-running service)

Root Cause

Root Cause Analysis

Fix Action

Fix / Workaround

Workaround

PR fix notes

PR #54403: fix: rebuild subsystem file logger on date rollover

Description (problem / solution / changelog)

Summary

  • Problem: createSubsystemLogger caches the file logger on first use and never rebuilds it. When the gateway runs past midnight, logs continue writing to the previous day's file instead of the new dated file.
  • Why it matters: Long-running gateway processes (the common deployment) silently write all logs to a stale file, breaking log rotation and making daily log analysis unreliable.
  • What changed: getFileLogger() now compares the current base logger reference (from getLogger()) against the cached one. When the base logger changes (due to date rollover or any settings change), the child logger is rebuilt. getLogger() is already cheaply cached internally, so this adds only a reference equality check on the hot path.
  • What did NOT change: No changes to log format, file naming, or any other logging behavior.

Change Type (select all)

  • Bug fix

Scope (select all touched areas)

  • Gateway / orchestration

Test plan

  • Added test in subsystem.test.ts that simulates date rollover via resetLogger() and verifies the base logger instance changes

Closes #54381

Changed files

  • src/logging/subsystem.test.ts (modified, +22/-1)
  • src/logging/subsystem.ts (modified, +9/-2)

PR #54527: fix(logging): rebuild subsystem file logger on date rollover

Description (problem / solution / changelog)

Summary

  • Fix: Subsystem loggers cached their tslog file logger child on first use and never rebuilt it. Long-running gateways writing logs past midnight continued using the previous day's file, breaking log rotation.
  • Approach: Replace the forever-cache with a midnight-aware cache — compare Date.now() against the next local midnight timestamp on each file log call. After midnight, rebuild the child logger from the current root logger.
  • Hot-path cost: Essentially zero — just Date.now() (no allocation) + integer comparison. The child logger is only rebuilt once per day.

Why this approach

This bug has attracted 19+ prior PRs (all closed or review-blocked). The two recurring problems:

  1. Hot-path cost — PR #54403 and others called getLogger()resolveSettings() on every log emit, which can reach readLoggingConfig() and dynamic require() on each call.
  2. Weak tests — Tests only verified getLogger() returns a new instance after resetLogger(), which is a tautology. None verified the subsystem child was actually rebuilt.

This PR avoids both:

  • Hot path is Date.now() + integer comparison (~free)
  • Tests spy on getChildLogger and verify it's called exactly twice (initial + post-rollover), and only once for same-day repeated logging

Test plan

  • pnpm test -- src/logging/subsystem.test.ts — 13/13 passed (2 new tests)
  • pnpm check — clean
  • pnpm tsgo — clean
  • pnpm build — clean

Closes #54381

🤖 Generated with Claude Code

Changed files

  • src/logging/subsystem.test.ts (modified, +43/-0)
  • src/logging/subsystem.ts (modified, +13/-2)

PR #54589: fix(logger): re-create file logger after midnight to use correct dated log file

Description (problem / solution / changelog)

Summary

Fixes #54381

The subsystem logger cached the file logger on first call, so after midnight new log entries continued to be written to the previous day's file.

Root Cause

In createSubsystemLogger, getFileLogger stored the logger in a closure variable (fileLogger) and only created it once (if (!fileLogger)). Since the underlying logger uses a date-stamped filename, the cached logger kept pointing to yesterday's file.

Fix

Added a fileLoggerDate string that records the date (Date.toDateString()) when the logger was last created. On every call, getFileLogger compares the current date to the cached date and re-creates the logger when they differ.

// Before
if (!fileLogger) {
  fileLogger = getChildLogger({ subsystem });
}

// After
const today = new Date().toDateString();
if (!fileLogger || fileLoggerDate !== today) {
  fileLogger = getChildLogger({ subsystem });
  fileLoggerDate = today;
}

Test

Added a test in src/logging/subsystem.test.ts using vi.useFakeTimers() that simulates a midnight crossing and verifies the logger is re-created exactly once after the date changes.

Changed files

  • src/logging/subsystem.test.ts (modified, +40/-0)
  • src/logging/subsystem.ts (modified, +4/-1)
RAW_BUFFERClick to expand / collapse

Bug type

Regression (worked before, now fails)

Summary

Description

When OpenClaw Gateway runs as a long-running service, the subsystem logger ( createSubsystemLogger ) caches the file logger on first call. After midnight, new logs continue to be written to the previous day's log file instead of creating/using a new dated file.

Steps to Reproduce

  1. Start OpenClaw Gateway on Day 1 (e.g., March 21)
  2. Keep Gateway running past midnight into Day 2 (e.g., March 24)
  3. Send new requests to Gateway
  4. Check log files - logs from March 24 are written to openclaw-2026-03-21.log instead of openclaw-2026-03-24.log

Root Cause Analysis

In subsystem-D46iuydz.js , the createSubsystemLogger function:

function createSubsystemLogger(subsystem) { let fileLogger = null; const getFileLogger = () => { if (!fileLogger) fileLogger = getChildLogger({ subsystem }); return fileLogger; }; // ... }

The fileLogger is lazily initialized once and cached forever. Even though getLogger() properly detects date changes via settingsChanged() and rebuilds the logger with a new file path, the subsystem logger never re-checks this - it just returns the cached fileLogger .

Expected Behavior

Logs should be written to the correct dated log file based on the current local date. When the date changes, the subsystem logger should detect this and use a new file.

Actual Behavior

Logs continue to be written to the log file from when the Gateway process started.

Workaround

Restart Gateway daily (e.g., via cron):

0 0 * * * openclaw gateway restart

Suggested Fix

  1. Add date checking in getFileLogger() to detect when the date has changed
  2. Or periodically check settingsChanged() in createSubsystemLogger
  3. Or use a similar pattern to getLogger() which properly detects and handles settings changes

Environment

  • OpenClaw version: 2026.3.23-2
  • OS: Linux
  • Runtime: Gateway (long-running service)

Steps to reproduce

  1. Start OpenClaw Gateway

    openclaw gateway start

Note the current date (e.g., March 21, 2026).

  1. Verify log file location

    ls -la /tmp/openclaw/

    Should see: openclaw-2026-03-21.log

  2. Send a test request

    curl http://localhost:3000/status

Confirm the log entry is written to the correct file:

tail /tmp/openclaw/openclaw-2026-03-21.log

  1. Wait for date change (or simulate by modifying system date)Option A: Wait until after midnight (next day)Option B: Simulate by changing system date:

    sudo date -s "2026-03-24 10:00:00"

  2. Send another test request

    curl http://localhost:3000/status

  3. Check log files

    ls -la /tmp/openclaw/

    Expected: openclaw-2026-03-24.log should exist

    Actual: No new file created, logs still go to openclaw-2026-03-21.log

    tail /tmp/openclaw/openclaw-2026-03-21.log

    Shows: New log entries with timestamp "2026-03-24" but in wrong file

Observed Result

  • Log entries from March 24 are written to openclaw-2026-03-21.log
  • No openclaw-2026-03-24.log file is created
  • The subsystem logger continues using the cached file path from process startup

Expected behavior

1

Actual behavior

1

OpenClaw version

3.2

Operating system

Linux

Install method

No response

Model

glm-5

Provider / routing chain

openclaw

Additional provider/model setup details

No response

Logs, screenshots, and evidence

Impact and severity

No response

Additional information

No response

extent analysis

Fix Plan

To fix the issue, we need to modify the createSubsystemLogger function to detect date changes and update the fileLogger accordingly. Here are the steps:

  • Modify the getFileLogger function to check the current date and update the fileLogger if the date has changed.
  • Use a similar pattern to getLogger() which properly detects and handles settings changes.

Example code:

function createSubsystemLogger(subsystem) {
    let fileLogger = null;
    let lastDate = null;
    const getFileLogger = () => {
        const currentDate = new Date();
        const currentDateStr = `${currentDate.getFullYear()}-${padZero(currentDate.getMonth() + 1)}-${padZero(currentDate.getDate())}`;
        if (!lastDate || lastDate !== currentDateStr) {
            fileLogger = getChildLogger({ subsystem });
            lastDate = currentDateStr;
        }
        return fileLogger;
    };

    // ...
}

function padZero(num) {
    return (num < 10 ? '0' : '') + num;
}

Alternatively, you can use a periodic check using settingsChanged() to update the fileLogger:

function createSubsystemLogger(subsystem) {
    let fileLogger = null;
    setInterval(() => {
        if (settingsChanged()) {
            fileLogger = getChildLogger({ subsystem });
        }
    },

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…

FAQ

Expected behavior

1

Still need to ship something?

×6

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

Back to top recommendations

TRENDING

openclaw - ✅(Solved) Fix [Bug]: Subsystem logger caches file path on first call, logs written to wrong date file after midnight [3 pull requests, 3 comments, 3 participants]