Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/wapython
Path: blob/main/core/posix-node/src/logging.ts
1067 views
1
/*
2
Initialize debug logging.
3
4
We use the standard debug logger with name "posix-node": https://www.npmjs.com/package/debug
5
6
DEBUG_FILE option:
7
8
To log to a file instead *also* set the env variable DEBUG_FILE to that
9
filename. You need to log to a file in case you're debugging something that
10
forks and doesn't have stdout/stderr anymore. Also, we do NOT reset the
11
contents of the file and instead always append, because forking would be a
12
problem, where the forked process might delete the file in the middle of the
13
run.
14
*/
15
16
import debug from "debug";
17
import { format } from "util";
18
import { appendFileSync } from "fs";
19
20
if (process.env.DEBUG_FILE) {
21
const debugFilename = process.env.DEBUG_FILE;
22
debug.log = (...args) => {
23
const s = format(...args);
24
appendFileSync(debugFilename, s + "\n");
25
};
26
}
27
28
export const log = debug("posix-node");
29
30