multibridge
Version:
A multi-database connection framework with centralized configuration
25 lines (24 loc) • 1.37 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const winston_1 = __importDefault(require("winston"));
const envConfig_1 = require("../config/envConfig");
// Custom format to handle structured logging with context
const customFormat = winston_1.default.format.printf(({ timestamp, level, message, ...meta }) => {
// Extract context from meta if present
const context = Object.keys(meta).length > 0 ? JSON.stringify(meta, null, 2) : "";
const contextStr = context ? `\nContext: ${context}` : "";
return `${timestamp} [${level.toUpperCase()}]: ${message}${contextStr}`;
});
const logger = winston_1.default.createLogger({
level: envConfig_1.envConfig.LOG_LEVEL,
format: winston_1.default.format.combine(winston_1.default.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }), winston_1.default.format.errors({ stack: true }), // Include stack traces
customFormat),
transports: [new winston_1.default.transports.Console()],
});
// Extend logger methods to accept context objects
// Note: Winston's log method signature is complex, so we'll use the existing methods
// and rely on the custom format to handle context objects passed as second parameter
exports.default = logger;