@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
$3
The fluent daemon should be listening in forward mode.
A simple starting configuration for Fluentd is the following: ``aconf @type forward port 24224
A similar starting configuration for Fluent Bit is the following: `ini [INPUT] Name forward Listen 0.0.0.0 Port 24224 Buffer_Chunk_Size 1M Buffer_Max_Size 6M
`typescript emit(data: Record): Promise; emit(data: Record, timestamp: number | Date | EventTime): Promise; emit(label: string, data: Record): Promise; emit(label: string, data: Record, timestamp: number | Date | EventTime): Promise; `
The returned Promise is resolved once the event is written to the socket, or rejected if an error occurs.
$3
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. `js const FluentClient = require("@fluent-org/logger").FluentClient; const logger = new FluentClient("tag_prefix", { ack: {} }); `
$3
The Fluent forward protocol provides multiple message modes, Message, Forward, PackedForward(default), CompressedPackedForward. The Fluent client supports all of them.
`js 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`js const FluentClient = require("@fluent-org/logger").FluentClient; const logger = new FluentClient("tag_prefix", { onSocketError: (err: Error) => { console.error("error!", err) } }); `
$3
Sometimes it makes sense to resubmit events if their initial submission failed. You can do this by specifying eventRetry. `js const FluentClient = require("@fluent-org/logger").FluentClient; const logger = new FluentClient("tag_prefix", { eventRetry: {} }); `
Server
@fluent-org/logger includes a fully functional forward server which can be used as a downstream Fluent sink. `js const FluentServer = require("@fluent-org/logger").FluentServer;
const server = new FluentServer({ listenOptions: { port: 24224 }});