Closed Travis-Taylor closed 1 year ago
Hey! it sounds like you are looking for the disableAutoconnect
option.
You can create your client with
this.logger = new FluentClient("teleop-frontend", {
socket: {
host: this.fluentHost,
port: this.fluentPort,
},
disableAutoconnect: true
});
Then, you can call this.logger.connect()
, which is a Promise that will reject if the connection fails. You can also listen to socket error events using this.logger.socketOn("error", err => { console.error("fluent socket error", err)})
I see - that's very helpful! I had seen that disableAutoconnect
option mentioned in your docs but didn't take advantage of the connect()
Promise. And the socketOn
callback is very useful! That might be worth highlighting in the docs.
Thanks for your quick assistance!
Hi, I've just started migrating an app from fluent-logger to this tool, and I'm trying to understand how to configure propagation of connection errors to my app. For context, we have a fluent-bit server with a configurable port setting, so we need to make sure the connection is reliably established (to avoid configuration problems). I have something like this in the app:
This check of
FluentClient.writable
is the only thing I found in this package which provides some feedback to the status of the connection. I see that there is an internalFluentSocket.onError
that serves to emit e.g. connection errors (viaFluentSocket.openSocket()
) but I can't find any configuration options to actually emit that event to anything. All the other functions I call return void Promises that don't raise on failure; is there some configuration option/step I'm missing?EDIT: I actually am getting
false
in all cases when checkingFluentClient.writable
, even when the host and port are correct (i.e. removing thatif (!this.logger.writable)
block successfully publishes the event). So I'm not sure what the right way to do this isI'm using @fluent-org/logger 1.0.10 in a NextJS app, for reference