Bier.ErrorLogger (bier v0.1.0)

Copy Markdown View Source

Structured JSON diagnostics for database-client and schema-cache failures.

PostgREST logs these conditions to stderr as a single JSON object with the keys of its error envelope — code, message, details, hint:

  • PGRST001 — "Database client error. Retrying the connection." when the database connection is lost;
  • PGRST002 — "Could not query the database for the schema cache. Retrying." when the schema-cache introspection fails on boot or reload.

Bier emits the same envelope as the message of a Logger.error/2 call, so the line lands in the host application's logging pipeline (level filtering, formatting, backends) instead of being written to a device the host cannot control. The message is built lazily — nothing is encoded when the :error level is disabled. Each entry also carries :bier_instance and :bier_error_code metadata for structured log pipelines.

For PostgREST's exact behavior (the JSON line on stderr), point the default logger handler at standard error in the host application:

config :logger, :default_handler, config: [type: :standard_error]

Summary

Functions

Log PGRST001 — the database client/connection error envelope.

Log PGRST002 — the schema-cache introspection failure envelope.

Functions

database_client_error(instance, reason)

@spec database_client_error(Bier.name(), term()) :: :ok

Log PGRST001 — the database client/connection error envelope.

reason (an exception or any term) becomes the envelope's details.

schema_cache_load_error(instance, reason)

@spec schema_cache_load_error(Bier.name(), term()) :: :ok

Log PGRST002 — the schema-cache introspection failure envelope.

reason (an exception or any term) becomes the envelope's details.