Something went wrong. Try again.
A reusable desktop shell: your sidecar, your index, safe APIs, installers for every platform
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829// One log per concern under the app's user data directory: `mollusc.log` for// the shell, `sidecar.log` for the sidecar's stdout and stderr. The previous// run's file is kept as `.1`. In dev everything also goes to the terminal.import { createWriteStream, existsSync, mkdirSync, renameSync } from 'node:fs';import { join } from 'node:path';
export function createLogger ({ dir, name, toConsole = false }) { mkdirSync(dir, { recursive: true }); const file = join(dir, `${name}.log`); if (existsSync(file)) renameSync(file, `${file}.1`); const stream = createWriteStream(file, { flags: 'a' }); const line = (level, msg) => { stream.write(`${new Date().toISOString()} ${level} ${msg}\n`); if (toConsole) (level === 'error' ? process.stderr : process.stdout).write(`${name}: ${msg}\n`); }; return { file, info: (msg) => line('info', msg), warn: (msg) => line('warn', msg), error: (msg) => line('error', msg), // Output from a child process, written as is. raw (chunk, isError = false) { stream.write(chunk); if (toConsole) (isError ? process.stderr : process.stdout).write(chunk); }, close: () => stream.end(), };}