Does it work with Graylog?
Hi folks,
Thanks for your great work =D
Is there any way to setup it to send the logs to a graylog server?
Thnak you.
Thanks for the positive feedback!
If you are a Graylog Cloud, Graylog Security or Graylog Operations customer you can setup a custom forwarder which will automatically read logs from a file to your graylog environment. See https://go2docs.graylog.org/5-1/getting_in_log_data/forwarder.html for more detail. This is the best setup in those environments as it separates the concern of log forwarding from log capture. This would allow you to use a FileStream to capture the logs locally, letting the forwarder to forward them to Graylog.
I've never used Graylog myself, but you can also easily create custom streams in Optic which allow you to send log messages to any destination you like. For example, your Optic stream could send an http POST request of the log message (n.b. I have no idea if Graylog accepts http requests), something like this:
import { Logger, LogRecord, Stream } from "https://deno.land/x/optic/mod.ts";
class GraylogRemoteStream implements Stream {
handle(logRecord: LogRecord): boolean {
const body = `{"msg": logRecord.msg}`;
const resp = await fetch("https://my.graylog.endpoint.com", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-Key": Deno.env.get("GRAYLOG_API_KEY"),
},
body,
});
// handle response, error handling, etc.
return true;
}
}
const logger = new Logger().addStream(new GraylogRemoteStream());
Hope this helps.