MCPcopy Create free account
hub / github.com/cloudflare/computer / createFileLogger

Function createFileLogger

packages/computerd/src/cli/logger.ts:42–64  ·  view source on GitHub ↗
(filePath: string)

Source from the content-addressed store, hash-verified

40// we don't pay an open/close per line. Throws if the path's directory
41// can't be created.
42export function createFileLogger(filePath: string): FileLogger {
43 mkdirSync(dirname(filePath), { recursive: true });
44 // O_APPEND | O_CREAT | O_WRONLY = 'a' in node's flag shorthand.
45 const fd = openSync(filePath, "a");
46 let closed = false;
47 return {
48 write(level, args) {
49 if (closed) return;
50 const line = `${formatLogEntry(level, args)}\n`;
51 writeSync(fd, line);
52 },
53 close() {
54 if (closed) return;
55 closed = true;
56 try {
57 closeSync(fd);
58 } catch {
59 // Already closed or filesystem went away. Either way,
60 // nothing useful to do; the process is likely exiting.
61 }
62 },
63 };
64}
65
66// Patch console.{log, error} so each call also lands in LOG_FILE,
67// then install handlers for uncaughtException and unhandledRejection

Callers 2

installLoggingFunction · 0.85
logger.test.tsFile · 0.85

Calls 1

dirnameFunction · 0.50

Tested by

no test coverage detected