@@ -25,28 +25,13 @@ import {
|
25 | 25 | import { readLoggingConfig, shouldSkipMutatingLoggingConfigRead } from "./config.js"; |
26 | 26 | import { resolveEnvLogLevelOverride } from "./env-log-level.js"; |
27 | 27 | import { type LogLevel, levelToMinLevel, normalizeLogLevel } from "./levels.js"; |
| 28 | +import { canUseNodeFs, formatLocalDate, LOG_PREFIX, LOG_SUFFIX } from "./log-file-shared.js"; |
28 | 29 | import { redactSecrets, redactSensitiveText } from "./redact.js"; |
29 | 30 | import { loggingState } from "./state.js"; |
30 | 31 | import { formatTimestamp } from "./timestamps.js"; |
31 | 32 | import type { LoggerSettings } from "./types.js"; |
32 | 33 | export type { LoggerSettings } from "./types.js"; |
33 | 34 | |
34 | | -type ProcessWithBuiltinModule = NodeJS.Process & { |
35 | | -getBuiltinModule?: (id: string) => unknown; |
36 | | -}; |
37 | | - |
38 | | -function canUseNodeFs(): boolean { |
39 | | -const getBuiltinModule = (process as ProcessWithBuiltinModule).getBuiltinModule; |
40 | | -if (typeof getBuiltinModule !== "function") { |
41 | | -return false; |
42 | | -} |
43 | | -try { |
44 | | -return getBuiltinModule("fs") !== undefined; |
45 | | -} catch { |
46 | | -return false; |
47 | | -} |
48 | | -} |
49 | | - |
50 | 35 | function resolveDefaultLogDir(): string { |
51 | 36 | return canUseNodeFs() ? resolvePreferredOpenClawTmpDir() : POSIX_OPENCLAW_TMP_DIR; |
52 | 37 | } |
@@ -60,8 +45,6 @@ function resolveDefaultLogFile(defaultLogDir: string): string {
|
60 | 45 | export const DEFAULT_LOG_DIR = resolveDefaultLogDir(); |
61 | 46 | export const DEFAULT_LOG_FILE = resolveDefaultLogFile(DEFAULT_LOG_DIR); // legacy single-file path |
62 | 47 | |
63 | | -const LOG_PREFIX = "openclaw"; |
64 | | -const LOG_SUFFIX = ".log"; |
65 | 48 | const MAX_LOG_AGE_MS = 24 * 60 * 60 * 1000; // 24h |
66 | 49 | const DEFAULT_MAX_LOG_FILE_BYTES = 100 * 1024 * 1024; // 100 MB |
67 | 50 | const MAX_ROTATED_LOG_FILES = 5; |
@@ -770,13 +753,6 @@ export const testApi = {
|
770 | 753 | }; |
771 | 754 | export { testApi as __test__ }; |
772 | 755 | |
773 | | -function formatLocalDate(date: Date): string { |
774 | | -const year = date.getFullYear(); |
775 | | -const month = String(date.getMonth() + 1).padStart(2, "0"); |
776 | | -const day = String(date.getDate()).padStart(2, "0"); |
777 | | -return `${year}-${month}-${day}`; |
778 | | -} |
779 | | - |
780 | 756 | function defaultRollingPathForToday(): string { |
781 | 757 | return rollingPathForDate(DEFAULT_LOG_DIR, new Date()); |
782 | 758 | } |
|