UNPKG

@hotmeshio/hotmesh

Version:

Serverless Workflow

55 lines (54 loc) 1.93 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LoggerService = void 0; const winston_1 = require("winston"); class LoggerService { constructor(appId = 'appId', instanceId = 'instanceId', name = 'name', logLevel = 'info', customLogger) { this.appId = appId; this.instanceId = instanceId; this.name = name; this.logLevel = logLevel; this.logger = customLogger || this.createDefaultLogger(); } createDefaultLogger() { // Custom format to ensure error objects include message and stack const errorFormat = (0, winston_1.format)((info) => { if (info.error instanceof Error) { return { ...info, error: { message: info.error.message, stack: info.error.stack, }, }; } return info; }); return (0, winston_1.createLogger)({ level: this.logLevel, format: winston_1.format.combine(winston_1.format.timestamp(), winston_1.format.errors({ stack: true }), errorFormat(), (0, winston_1.format)((info) => { info.ts = info.timestamp; delete info.timestamp; return info; })(), winston_1.format.json()), transports: [new winston_1.transports.Console()], defaultMeta: { app: this.name || this.appId, id: this.instanceId, }, }); } info(message, ...meta) { this.logger.info(message, ...meta); } error(message, ...meta) { this.logger.error(message, ...meta); } warn(message, ...meta) { this.logger.warn(message, ...meta); } debug(message, ...meta) { this.logger.debug(message, ...meta); } } exports.LoggerService = LoggerService;