createTransport
Creates a custom transport that defines where and how logs are output.Signature
Parameters
Configuration options for the transport
Function called for each log entry. This is where you define how to handle the log.Signature:The context object contains timestamp, level, message, data, file information, and store for maintaining state.
Optional function called when the logger flushes. Use this to batch process logs or ensure all logs are written.Signature:The context object contains store for transport-specific storage and logs array of all processed logs since the last flush.
Returns
ATransport object that can be used with createLogger.
Example: Simple Console Transport
Example: File Transport with Batching
Example: Remote API Transport
Transport Interface
The transport object returned bycreateTransport has the following structure:
Store
Each transport has access to aStore object for maintaining state between log calls. This is useful for batching, rate limiting, or tracking transport-specific metadata.