mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-02 09:40:22 +00:00
Browser/Logging: share default openclaw tmp dir resolver
This commit is contained in:
20
src/logging/logger.import-side-effects.test.ts
Normal file
20
src/logging/logger.import-side-effects.test.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import fs from "node:fs";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
describe("logger import side effects", () => {
|
||||
beforeEach(() => {
|
||||
vi.resetModules();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it("does not mkdir at import time", async () => {
|
||||
const mkdirSpy = vi.spyOn(fs, "mkdirSync");
|
||||
|
||||
await import("./logger.js");
|
||||
|
||||
expect(mkdirSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
@@ -1,26 +1,15 @@
|
||||
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";
|
||||
import type { ConsoleStyle } from "./console.js";
|
||||
import { resolvePreferredOpenClawTmpDir } from "../infra/tmp-openclaw-dir.js";
|
||||
import { readLoggingConfig } from "./config.js";
|
||||
import { type LogLevel, levelToMinLevel, normalizeLogLevel } from "./levels.js";
|
||||
import { loggingState } from "./state.js";
|
||||
|
||||
// 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_DIR = resolvePreferredOpenClawTmpDir();
|
||||
export const DEFAULT_LOG_FILE = path.join(DEFAULT_LOG_DIR, "openclaw.log"); // legacy single-file path
|
||||
|
||||
const LOG_PREFIX = "openclaw";
|
||||
|
||||
Reference in New Issue
Block a user