UNPKG

logs-interceptor

Version:

High-performance, production-ready log interceptor for Node.js applications with Loki integration. Built with Clean Architecture principles. Supports Node.js, Browser, and Node-RED.

52 lines 1.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LogFilterService = void 0; class LogFilterService { constructor(config, sanitizationService, samplingService) { this.config = config; this.sanitizationService = sanitizationService; this.samplingService = samplingService; } shouldProcess(level, message, context) { // Check if level is enabled if (!this.config.levels.includes(level)) { return false; } // Check message patterns if (this.config.patterns && this.config.patterns.length > 0) { const shouldInclude = this.config.patterns.some((pattern) => pattern.test(message)); if (!shouldInclude) { return false; } } // Apply sampling if (this.config.samplingRate !== undefined) { if (!this.samplingService.shouldSample(this.config.samplingRate)) { return false; } } return true; } sanitize(entry) { var _a; if (!this.config.sanitize) { return entry; } // Truncate message if too long const maxLength = (_a = this.config.maxMessageLength) !== null && _a !== void 0 ? _a : 8192; const truncatedMessage = entry.message.length > maxLength ? entry.message.substring(0, maxLength) + '...[truncated]' : entry.message; // Sanitize context const sanitizedContext = entry.context ? this.sanitizationService.sanitize(entry.context) : undefined; return { ...entry, message: truncatedMessage, context: sanitizedContext, }; } } exports.LogFilterService = LogFilterService; //# sourceMappingURL=LogFilterService.js.map