Dagemark-Webapp/lib/logging/logger.ts
Hannah dagemark 6b5deae129 Fix logging
2026-09-15 22:42:08 +02:00

39 lines
1 KiB
TypeScript

import winston from "winston";
const logger = winston.createLogger({
level: "info",
format: winston.format.json(),
defaultMeta: { service: "user-service" },
transports: [
//
// - Write all logs with importance level of `error` or higher to `error.log`
// (i.e., error, fatal, but not other levels)
//
new winston.transports.File({
filename: "/lib/logging/error.log",
level: "error",
}),
//
// - Write all logs with importance level of `info` or higher to `combined.log`
// (i.e., fatal, error, warn, and info, but not trace)
//
new winston.transports.File({ filename: "/lib/logging/combined.log" }),
],
});
//
// If we're not in production then log to the `console` with the format:
// `${info.level}: ${info.message} JSON.stringify({ ...rest }) `
//
if (process.env.NODE_ENV !== "production") {
logger.add(
new winston.transports.Console({
format: winston.format.simple(),
}),
);
logger.configure({
level: "debug",
});
}
export default logger;