Add logging with Winston
This commit is contained in:
parent
e40ed22746
commit
9293c92e58
8 changed files with 357 additions and 25 deletions
36
lib/logging/logger.ts
Normal file
36
lib/logging/logger.ts
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
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: "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: "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;
|
||||
Loading…
Reference in a new issue