-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlogger.ts
27 lines (24 loc) · 931 Bytes
/
logger.ts
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
import pino from "pino";
const isServer = typeof window === "undefined";
const isNextEdgeRuntime = process.env.NEXT_RUNTIME === "edge";
const logger = pino({
level: process.env.NODE_ENV === "production" ? "info" : "debug",
timestamp: pino.stdTimeFunctions.isoTime,
...(isServer &&
isNextEdgeRuntime && {
browser: {
write: {
critical: (o: Object) => console.error(JSON.stringify(o)),
debug: (o: Object) => console.log(JSON.stringify(o)),
error: (o: Object) =>
console.error(JSON.stringify({ ...o, level: "error" })),
fatal: (o: Object) => console.error(JSON.stringify(o)),
info: (o: Object) => console.log(JSON.stringify(o)),
trace: (o: Object) => console.log(JSON.stringify(o)),
warn: (o: Object) =>
console.warn(JSON.stringify({ ...o, level: "warn" })),
},
},
}),
});
export default logger;