syntropylog
Version:
An instance manager with observability for Node.js applications
47 lines • 1.76 kB
JavaScript
/**
* @file src/logger/transports/Transport.ts
* @description Defines the abstract base class for all log transports.
*/
import { LOG_LEVEL_WEIGHTS } from '../levels';
/**
* @class Transport
* @description The abstract base class for all log transports. A transport is
* responsible for the final output of a log entry, whether it's to the console,
* a file, or a remote service.
*/
export class Transport {
level;
name;
/** The formatter instance to transform log entries. */
formatter;
/** The engine used to sanitize sensitive data. */
sanitizationEngine;
/**
* @constructor
* @param {TransportOptions} [options] - The configuration options for this transport.
*/
constructor(options = {}) {
this.level = options.level ?? 'info';
this.name = options.name ?? this.constructor.name;
this.formatter = options?.formatter;
this.sanitizationEngine = options?.sanitizationEngine;
}
/**
* Determines if the transport should process a log entry based on its log level.
* @param level - The level of the log entry to check.
* @returns {boolean} - True if the transport is enabled for this level, false otherwise.
*/
isLevelEnabled(level) {
return LOG_LEVEL_WEIGHTS[level] >= LOG_LEVEL_WEIGHTS[this.level];
}
/**
* A method to ensure all buffered logs are written before the application exits.
* Subclasses should override this if they perform I/O buffering.
* @returns {Promise<void>} A promise that resolves when flushing is complete.
*/
async flush() {
// Default implementation does nothing, assuming no buffering.
return Promise.resolve();
}
}
//# sourceMappingURL=Transport.js.map