@fluent-org/logger provides a fully functional client that implements the Forward protocol. It supports reconnection, acknowledgements, timeouts, event retries, and more, and exposes its functionality via a simple typed Promise interface.
For a full list of the client options and methods, see the FluentClient docs
Prerequisites
The fluent daemon should be listening in forward mode.
A simple starting configuration for Fluentd is the following:
emit(data: Record<string, any>): Promise<void>;
emit(data: Record<string, any>, timestamp: number | Date | EventTime): Promise<void>;
emit(label: string, data: Record<string, any>): Promise<void>;
emit(label: string, data: Record<string, any>, timestamp: number | Date | EventTime): Promise<void>;
The returned Promise is resolved once the event is written to the socket, or rejected if an error occurs.
Acknowledgements
The Fluent forward protocol provides explicit support for acknowledgements, which allow the client to be sure that the event reached its destination.
Enabling acknowledgements means that the promise returned by emit will be resolved once the client receives an explicit acknowledgement from the server.
The Fluent forward protocol provides multiple message modes, Message, Forward, PackedForward(default), CompressedPackedForward. The Fluent client supports all of them.
const logger = new FluentClient("tag_prefix", {
socket: {
host: "localhost",
port: 24224,
timeout: 3000, // 3 seconds
disableReconnect: true
}
});
// If you disable reconnections, the socket has to be manually connected,
// connect() returns a promise, which rejects on connection errors.
logger.connect();
The Fluent client will manage errors internally, and reject promises on errors. If you”d like to access the non-user facing internal errors, you can do so by passing errorHandler
@fluent-org/logger
Fluent Forward Protocol implementation for Node.js. Built upon fluent-logger-node.
Install
Client
@fluent-org/loggerprovides a fully functional client that implements the Forward protocol. It supports reconnection, acknowledgements, timeouts, event retries, and more, and exposes its functionality via a simple typed Promise interface.For a full list of the client options and methods, see the FluentClient docs
Prerequisites
The fluent daemon should be listening in forward mode.
A simple starting configuration for Fluentd is the following:
See the FluentD docs for more info.
A similar starting configuration for Fluent Bit is the following:
See the Fluent Bit docs for more info.
Sending an event record to an upstream Fluent server
The emit method has following signature
The returned Promise is resolved once the event is written to the socket, or rejected if an error occurs.
Acknowledgements
The Fluent forward protocol provides explicit support for acknowledgements, which allow the client to be sure that the event reached its destination.
Enabling acknowledgements means that the promise returned by
emitwill be resolved once the client receives an explicit acknowledgement from the server.Event modes
The Fluent forward protocol provides multiple message modes,
Message,Forward,PackedForward(default),CompressedPackedForward. The Fluent client supports all of them.Disable automatic reconnect
Shared key authentication
Logger configuration:
Fluentd configuration:
See also the Fluentd examples.
TLS/SSL encryption
Logger configuration:
Fluentd configuration:
FYI: You can generate certificates using the
fluent-ca-generatecommand since Fluentd 1.1.0.See also How to enable TLS/SSL encryption.
Mutual TLS Authentication
Logger configuration:
Fluentd configuration:
EventTime support
We can also specify an EventTime as a timestamp. See the EventTime docs
Handling errors
The Fluent client will manage errors internally, and reject promises on errors. If you”d like to access the non-user facing internal errors, you can do so by passing
errorHandlerRetrying events
Sometimes it makes sense to resubmit events if their initial submission failed. You can do this by specifying
eventRetry.Server
@fluent-org/loggerincludes a fully functional forward server which can be used as a downstream Fluent sink.Fluentd config:
See the FluentD docs for more info.
Alternatively, see the Fluent Bit docs for info on setting up Fluent Bit.
For a full list of the server options and methods, see the FluentServer docs
License
Apache License, Version 2.0.
About NodeJS versions
This package is compatible with NodeJS versions >= 12.