feat: observability — Winston logging, pagination admin, N+1 playlists
All checks were successful
CI/CD — Build & Deploy / Build & Deploy (push) Successful in 27s
All checks were successful
CI/CD — Build & Deploy / Build & Deploy (push) Successful in 27s
This commit is contained in:
25
backend/src/utils/logger.ts
Normal file
25
backend/src/utils/logger.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import winston from "winston";
|
||||
|
||||
const { combine, timestamp, json, colorize, printf } = winston.format;
|
||||
|
||||
const devFormat = combine(
|
||||
colorize(),
|
||||
timestamp({ format: "HH:mm:ss" }),
|
||||
printf(({ level, message, timestamp: ts, ...meta }) => {
|
||||
const metaStr = Object.keys(meta).length ? ` ${JSON.stringify(meta)}` : "";
|
||||
return `${ts} [${level}] ${message}${metaStr}`;
|
||||
})
|
||||
);
|
||||
|
||||
const prodFormat = combine(
|
||||
timestamp(),
|
||||
json()
|
||||
);
|
||||
|
||||
const logger = winston.createLogger({
|
||||
level: process.env.LOG_LEVEL ?? "info",
|
||||
format: process.env.NODE_ENV === "production" ? prodFormat : devFormat,
|
||||
transports: [new winston.transports.Console()],
|
||||
});
|
||||
|
||||
export default logger;
|
||||
Reference in New Issue
Block a user