/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:
- req_url: Logs the url of the request.
- query_params: Logs query parameters sent to the query endpoint.
- query: Logs the sql to executed by calling the query endpoint.
- view-req-url: Logs the url of the requested view.
- cloudfront: Logs responses from requests made to cloudfront e.g. <staus_code> -
- mailer: Logs the response from email sending.
- mailer_body: Logs email from and two with the body.
- reqhost: Logs the host for the request.
- workspace: Logs responses for requests made to /workspace.
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
);
- Source
Requires
- module:/utils/processEnv
- module:crypto
Methods
(inner) log(log, keyopt)
Logs a message to the configured logger or console.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
log | string | | The message or object to log. | ||
key | string | <optional> | 'err' | The log level or key. |
- Source
(inner) logflare() → {function}
Configures the Logflare logger.
- Source
A function that logs messages to Logflare.
- Type:
- function
(inner) postgresql() → {function}
Configures the PostgreSQL logger.
- Source
A function that logs messages to a PostgreSQL database.
- Type:
- function