/utils/logger 🪵

This module provides a logging utility for the XYZ API. The LOG process environment variable will be split into an array to determine which logs should be written out.

Possible log values are:

  • query_params: Logs query parameters sent to the query endpoint.
  • query: Logs the sql to executed by calling the query endpoint.
  • cloudfront: Logs responses from requests made to cloudfront e.g. <staus_code> -
  • mailer: Logs the sent mail template.
  • reqhost: Logs the host for the request.
  • workspace: Logs responses for requests made to /workspace.
  • dbs_retry: Logs the reason and backoff delay when a query is retried by the dbs module, and when the retries are exhausted.

By default the logs are only written to the stdout console.

It is possible to set the LOGGER process env to write logs to the logflare api. A valid source and apikey must be provided in the LOGGER env value.

"LOGGER": "logflare:apikey=🤫&source=🤫"

Alternatively logs can be written into a table on any of the configured DBS_* connections. The dbs parameter value must match a DBS_* connection in the process env.

"LOGGER": "postgresql:dbs=NEON&table=public.dev_logs"

The schema for the log table should be like so:

CREATE TABLE public.dev_logs (
  process VARCHAR,
  datetime BIGINT,
  key VARCHAR,
  message VARCHAR,
  log TEXT
);

Requires

  • module:/utils/processEnv
  • module:crypto

Methods

(inner) log(log, key)

Logs a message to the configured logger or console.

Parameters:
NameTypeDescription
logstring | Object

The message or object to log.

keystring

The log level or key.

(inner) logflare() → {function}

Configures the Logflare logger.

Returns:

A function that logs messages to Logflare.

Type: 
function

(inner) postgresql() → {function}

Configures the PostgreSQL logger.

Returns:

A function that logs messages to a PostgreSQL database.

Type: 
function