All files / postcardotp-backend/src/utils logger.js

90.9% Statements 10/11
50% Branches 1/2
100% Functions 0/0
90.9% Lines 10/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 28 29 30 31 32 331x 1x 1x 1x     1x 1x       1x 1x         1x                           1x  
const winston = require("winston");
const fs = require("fs");
const path = require("path");
const moment = require("moment");
 
// Ensure the logs directory exists
const logDirectory = path.join(__dirname, "..", "logs");
Iif (!fs.existsSync(logDirectory)) {
  fs.mkdirSync(logDirectory);
}
 
const logFileName = `app-${moment().format("YYYY-MM-DD")}.log`;
const logFilePath = path.join(logDirectory, logFileName);
 
/**
 * Configure Winston logger
 */
const logger = winston.createLogger({
  level: "info",
  format: winston.format.combine(
    winston.format.timestamp(),
    winston.format.json(),
  ),
  transports: [
    new winston.transports.Console({ format: winston.format.simple() }),
    new winston.transports.File({
      filename: logFilePath,
    }),
  ],
});
 
module.exports = logger;