Add an error logger
For developers who connect a client to OpenBot or extend its server. The examples need the access stated on this page. Start with the developer manual.
For project contributors who change or publish OpenBot.
Send errors to your own service
Section titled “Send errors to your own service”When you run OpenBot from your own code, add a logger with Logger.layer. Use
mergeWithExisting: true to keep the other loggers. Provide it outside the
server, so that it stays open until the server has closed.
import { NodeRuntime, NodeServices } from "@effect/platform-node"import { EnvironmentConfiguration, Server } from "@openbot-build/openbot"import { Effect, Layer, Logger, References } from "effect"import { FetchHttpClient } from "effect/http"
const alerts = Logger.layer( [ Logger.make((log) => { if (log.logLevel !== "Error" && log.logLevel !== "Fatal") return const annotations = log.fiber.getRef(References.CurrentLogAnnotations) // Send only the values that you need, for example to a chat bot. console.log("alert", annotations["source"], annotations["operation"]) }), ], { mergeWithExisting: true },)
NodeRuntime.runMain( Effect.gen(function* () { const settings = yield* EnvironmentConfiguration.load return yield* Layer.launch( Server.layerLive(settings).pipe( Layer.provide(Layer.merge(NodeServices.layer, FetchHttpClient.layer)), ), ) }).pipe(Effect.provide(alerts)),)A logger must not block. To call a slow service, put each event in a queue and send it from a background fiber. A fiber is a light thread that Effect runs.