Skip to content

Commit 1ea498d

Browse files
authored
Updates: Removed Pino, Added Winston (#605)
* Updates: Removed logs + queuedAt indexed * Updates: Removed Pino, Added Winston * updates add stack trace to console
1 parent 25aa2cc commit 1ea498d

File tree

3 files changed

+202
-114
lines changed

3 files changed

+202
-114
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,12 @@
6464
"mnemonist": "^0.39.8",
6565
"node-cron": "^3.0.2",
6666
"pg": "^8.11.3",
67-
"pino": "^8.15.1",
68-
"pino-pretty": "^10.0.0",
6967
"prisma": "^5.14.0",
7068
"superjson": "^2.2.1",
7169
"thirdweb": "^5.45.1",
7270
"uuid": "^9.0.1",
7371
"viem": "^1.14.0",
72+
"winston": "^3.14.1",
7473
"zod": "^3.23.8"
7574
},
7675
"devDependencies": {

src/utils/logger.ts

Lines changed: 54 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,57 @@
1-
import Pino, { LoggerOptions } from "pino";
1+
import { createLogger, format, transports } from "winston";
22
import { env } from "./env";
33

4-
const defaultOptions: LoggerOptions = {
5-
redact: ["headers.authorization"],
6-
transport: {
7-
target: "pino-pretty",
8-
options: {
9-
translateTime: "HH:MM:ss Z",
10-
ignore: "pid,hostname,reqId",
11-
singleLine: true,
12-
},
13-
},
14-
level: env.LOG_LEVEL,
4+
// Custom filter for stdout transport
5+
const filterOnlyInfoAndWarn = format((info) => {
6+
if (info.level === "error") {
7+
return false; // Exclude 'error' level logs
8+
}
9+
return info;
10+
});
11+
12+
// Custom filter for stderr transport
13+
const filterOnlyErrors = format((info) => {
14+
if (info.level !== "error") {
15+
return false; // Exclude non-error level logs
16+
}
17+
return info;
18+
});
19+
20+
const colorizeFormat = () => {
21+
if (env.NODE_ENV === "development") {
22+
return format.colorize();
23+
} else {
24+
return format.uncolorize();
25+
}
1526
};
1627

17-
const pino = Pino(defaultOptions);
28+
const winstonLogger = createLogger({
29+
level: env.LOG_LEVEL,
30+
format: format.combine(
31+
format.timestamp(),
32+
format.errors({ stack: true }),
33+
format.splat(),
34+
colorizeFormat(),
35+
format.printf(({ level, message, timestamp, error }) => {
36+
if (error) {
37+
return `[${timestamp}] ${level}: ${message} - ${error.stack}`;
38+
}
39+
return `[${timestamp}] ${level}: ${message}`;
40+
}),
41+
),
42+
transports: [
43+
// Transport for stdout
44+
new transports.Console({
45+
format: format.combine(filterOnlyInfoAndWarn()),
46+
stderrLevels: [], // Don't log "error" to stdout
47+
}),
48+
// Transport for stderr
49+
new transports.Console({
50+
format: format.combine(filterOnlyErrors()),
51+
stderrLevels: ["error"], // Ensure errors go to stderr
52+
}),
53+
],
54+
});
1855

1956
interface LoggerParams {
2057
service: (typeof env)["LOG_SERVICES"][0];
@@ -46,9 +83,10 @@ export const logger = ({
4683
if (data) {
4784
suffix += ` - ${JSON.stringify(data)}`;
4885
}
86+
4987
if (error) {
50-
suffix += ` - ${error?.message || error}`;
88+
winstonLogger.error(`${prefix}${message}${suffix}`, { error });
89+
} else {
90+
winstonLogger.log(level, `${prefix}${message}${suffix}`);
5191
}
52-
53-
return pino[level](`${prefix}${message}${suffix}`);
5492
};

0 commit comments

Comments
 (0)