Skip to content

Commit 4429329

Browse files
committed
chore: simplify logging in production no stracktrace
1 parent e2a9e49 commit 4429329

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

src/components/utils/log.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
import log from "npmlog";
2-
import fs from "fs";
3-
import path from "path";
2+
3+
if (process.env.DEBUG === "false") {
4+
const methodsToPatch = ["error", "warn"];
5+
6+
for (const method of methodsToPatch) {
7+
const original = log[method].bind(log);
8+
9+
log[method] = function (prefix: string, ...args: any[]) {
10+
const formattedArgs = args.map((arg) => {
11+
if (arg instanceof Error) {
12+
return `${arg.name}: ${arg.message}`;
13+
}
14+
return arg;
15+
});
16+
17+
return original(prefix, ...formattedArgs);
18+
};
19+
}
20+
}
421

522
export default log;

0 commit comments

Comments
 (0)