Creates a new synchronous file transport instance.
Transport configuration
Protected
closingFlag to track if transport is currently closing.
Whether this transport is currently active and processing logs. Can be toggled at runtime to enable/disable specific transports.
Protected
Optional
Readonly
excludeTags that exclude logs from being processed.
Protected
Optional
Readonly
filterCustom filter function for advanced filtering.
Protected
Readonly
formatOutput format for this transport.
Protected
Optional
Readonly
formatterCustom formatter function.
Protected
initializedFlag to track if transport has been initialized.
Protected
Readonly
levelMinimum log level for this transport.
Protected
Optional
Readonly
levelsSpecific levels this transport handles (if specified).
Readonly
nameUnique identifier for this transport instance. Used for managing multiple transports and debugging.
Protected
Readonly
optionsConfiguration options.
Protected
Readonly
silentWhether to suppress errors from this transport.
Protected
statsStatistics tracking for this transport.
Protected
Optional
Readonly
tagsTags that must be present for logs to be processed.
Protected
Readonly
timeoutOperation timeout in milliseconds.
Public close method that calls the base class close.
Resolves when closed
Disable the transport.
Protected
doProtected
Handles cleanup when closing. Required by Transport base class.
Resolves when closed
Protected
doProtected
Initializes the transport. Required by Transport base class.
Resolves when initialized
Protected
Abstract
doProtected
Abstract method for transport-specific logging. Subclasses must implement this method.
The log entry to process
Resolves when the log has been processed
Protected
Optional
doProtected
Optional method for transport-specific batch logging. Subclasses can implement this for efficient batch processing.
Array of log entries to process
Resolves when all logs have been processed
Synchronously calls each of the listeners registered for the event namedeventName
, in the order they were registered, passing the supplied arguments
to each.
Returns true
if the event had listeners, false
otherwise.
import EventEmitter from 'node:events';
const myEmitter = new EventEmitter();
// First listener
myEmitter.on('event', function firstListener() {
console.log('Helloooo! first listener');
});
// Second listener
myEmitter.on('event', function secondListener(arg1, arg2) {
console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
});
// Third listener
myEmitter.on('event', function thirdListener(...args) {
const parameters = args.join(', ');
console.log(`event with parameters ${parameters} in third listener`);
});
console.log(myEmitter.listeners('event'));
myEmitter.emit('event', 1, 2, 3, 4, 5);
// Prints:
// [
// [Function: firstListener],
// [Function: secondListener],
// [Function: thirdListener]
// ]
// Helloooo! first listener
// event with parameters 1, 2 in second listener
// event with parameters 1, 2, 3, 4, 5 in third listener
Enable the transport.
Flushes buffered entries to disk. Implements write coalescing for optimal performance.
Resolves when flush completes
Protected
formatProtected
Format a log entry according to the configured format.
The log entry to format
Formatted log entry
Protected
formatProtected
Format a log entry as plain text.
The log entry to format
Plain text formatted log entry
Protected
generateProtected
Generate a unique ID for tracking purposes.
A unique identifier
Get the transport name.
Gets current transport statistics.
Returns enhanced statistics including file-specific metrics. Overrides the base method to provide comprehensive monitoring data.
Transport statistics with file metrics
Protected
handleProtected
Handle errors according to the transport's configuration.
The error that occurred
Optional
entry: LogEntryThe log entry that caused the error (if applicable)
Check if the transport is currently enabled.
True if transport is enabled
Check if transport is healthy.
True if transport is healthy
Protected
isProtected
Check if a log level is enabled based on minimum level.
The level to check
True if the level is enabled
Log a single entry.
The log entry to process
Resolves when the log has been processed
Log multiple entries at once.
Array of log entries to process
Resolves when all logs have been processed
High-performance synchronous log method. Bypasses async overhead for maximum speed.
The log entry
Alias for emitter.removeListener()
.
Implement EventEmitter methods explicitly for ITransport interface.
Reset transport statistics.
Check if this transport should handle a given log entry.
The log entry to check
True if the entry should be logged by this transport
Protected
shouldProtected
Whether this transport should rethrow errors encountered during log operations. Network-based transports typically want propagation so callers/tests can assert failures. Base transports default to swallowing errors after emitting events and updating stats.
Check if transport supports batching.
True if batching is supported
Protected
with
High-performance synchronous file transport with advanced buffering.
Designed for maximum throughput while maintaining data integrity. Uses write coalescing and large buffers to minimize system call overhead.
SyncFileTransport
Since
1.0.0
Example: Basic usage
Example: With rotation