UNPKG

nostr-deploy-server

Version:

Node.js server for hosting static websites under npub subdomains using Nostr protocol and Blossom servers

121 lines 3.99 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.logger = void 0; const winston_1 = __importDefault(require("winston")); const config_1 = require("./config"); class Logger { constructor() { const config = config_1.ConfigManager.getInstance().getConfig(); this.logger = winston_1.default.createLogger({ level: config.logLevel, 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 }), winston_1.default.format.colorize(), winston_1.default.format.printf(({ level, message, timestamp, stack }) => { return `${timestamp} [${level}]: ${stack || message}`; })), transports: [ new winston_1.default.transports.Console({ handleExceptions: true, handleRejections: true, }), ], }); // Add file transport in production if (config.logLevel === 'production') { this.logger.add(new winston_1.default.transports.File({ filename: 'logs/error.log', level: 'error', handleExceptions: true, handleRejections: true, maxsize: 5242880, // 5MB maxFiles: 5, })); this.logger.add(new winston_1.default.transports.File({ filename: 'logs/combined.log', handleExceptions: true, handleRejections: true, maxsize: 5242880, // 5MB maxFiles: 5, })); } } static getInstance() { if (!Logger.instance) { Logger.instance = new Logger(); } return Logger.instance; } error(message, meta) { this.logger.error(message, meta); } warn(message, meta) { this.logger.warn(message, meta); } info(message, meta) { this.logger.info(message, meta); } debug(message, meta) { this.logger.debug(message, meta); } verbose(message, meta) { this.logger.verbose(message, meta); } http(message, meta) { this.logger.http(message, meta); } // Method to log HTTP requests logRequest(method, url, statusCode, responseTime, userAgent) { const message = `${method} ${url} ${statusCode} ${responseTime}ms`; const meta = { method, url, statusCode, responseTime, userAgent, }; if (statusCode >= 400) { this.error(message, meta); } else { this.http(message, meta); } } // Method to log Nostr operations logNostr(operation, pubkey, success, details) { const message = `Nostr ${operation} for ${pubkey.substring(0, 8)}... ${success ? 'succeeded' : 'failed'}`; const meta = { operation, pubkey, success, ...details, }; if (success) { this.info(message, meta); } else { this.error(message, meta); } } // Method to log Blossom operations logBlossom(operation, sha256, server, success, details) { const message = `Blossom ${operation} for ${sha256.substring(0, 8)}... from ${server} ${success ? 'succeeded' : 'failed'}`; const meta = { operation, sha256, server, success, ...details, }; if (success) { this.info(message, meta); } else { this.error(message, meta); } } } exports.logger = Logger.getInstance(); //# sourceMappingURL=logger.js.map