-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.js
32 lines (32 loc) · 965 Bytes
/
logger.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import fs from "fs";
import path from "path";
import { useProject } from "./project.js";
import { lazy } from "./util/lazy.js";
let previous = new Date();
const useFile = lazy(() => {
const project = useProject();
const filePath = path.join(project.paths.out, "debug.log");
const file = fs.createWriteStream(filePath);
return file;
});
export const Logger = {
debug(...parts) {
const now = new Date();
const diff = now.getTime() - previous.getTime();
previous = now;
const line = [
new Date().toISOString(),
`+${diff}ms`.padStart(8),
"[debug]",
...parts.map((x) => {
if (typeof x === "string")
return x;
return JSON.stringify(x);
}),
];
if (process.env.SST_VERBOSE)
console.log(...line);
const file = useFile();
file.write(line.join(" ") + "\n");
},
};