Release v3.9.9
Published from npm package build Source: https://github.com/thedotmack/claude-mem-source
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import { appendFileSync, existsSync, mkdirSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
import { PathDiscovery } from '../services/path-discovery.js';
|
||||
|
||||
let logPath: string | null = null;
|
||||
|
||||
function ensureLogPath(): string {
|
||||
if (logPath) {
|
||||
return logPath;
|
||||
}
|
||||
|
||||
const discovery = PathDiscovery.getInstance();
|
||||
const logsDir = discovery.getLogsDirectory();
|
||||
|
||||
if (!existsSync(logsDir)) {
|
||||
mkdirSync(logsDir, { recursive: true });
|
||||
}
|
||||
|
||||
logPath = join(logsDir, 'rolling-memory.log');
|
||||
return logPath;
|
||||
}
|
||||
|
||||
export type RollingLogLevel = 'debug' | 'info' | 'warn' | 'error';
|
||||
|
||||
export function rollingLog(
|
||||
level: RollingLogLevel,
|
||||
message: string,
|
||||
payload: Record<string, unknown> = {}
|
||||
): void {
|
||||
try {
|
||||
const file = ensureLogPath();
|
||||
const entry = {
|
||||
timestamp: new Date().toISOString(),
|
||||
level,
|
||||
message,
|
||||
...payload
|
||||
};
|
||||
appendFileSync(file, `${JSON.stringify(entry)}\n`, 'utf8');
|
||||
} catch {
|
||||
// Logging should never throw user-facing errors
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user