fix: use os.tmpdir fallback paths for temp files (#14985)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 347c689407
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Reviewed-by: @gumadeiras
This commit is contained in:
Gustavo Madeira Santana
2026-02-12 16:08:41 -05:00
committed by GitHub
parent 282fb9ad52
commit afbce73570
5 changed files with 19 additions and 6 deletions

View File

@@ -1,5 +1,6 @@
import fs from "node:fs";
import { createRequire } from "node:module";
import os from "node:os";
import path from "node:path";
import { Logger as TsLogger } from "tslog";
import type { OpenClawConfig } from "../config/types.js";
@@ -8,9 +9,18 @@ import { readLoggingConfig } from "./config.js";
import { type LogLevel, levelToMinLevel, normalizeLogLevel } from "./levels.js";
import { loggingState } from "./state.js";
// Pin to /tmp so mac Debug UI and docs match; os.tmpdir() can be a per-user
// randomized path on macOS which made the “Open log” button a no-op.
export const DEFAULT_LOG_DIR = "/tmp/openclaw";
// Prefer /tmp/openclaw so macOS Debug UI and docs match, but fall back to
// os.tmpdir() on platforms where /tmp is read-only (e.g. Termux/Android).
function resolveDefaultLogDir(): string {
try {
fs.mkdirSync("/tmp/openclaw", { recursive: true });
return "/tmp/openclaw";
} catch {
return path.join(os.tmpdir(), "openclaw");
}
}
export const DEFAULT_LOG_DIR = resolveDefaultLogDir();
export const DEFAULT_LOG_FILE = path.join(DEFAULT_LOG_DIR, "openclaw.log"); // legacy single-file path
const LOG_PREFIX = "openclaw";