| Title: | Log Application Events to PocketBase from R |
|---|---|
| Description: | A unified operational monitoring system that logs application events (data jobs, website monitoring, email checks, database checks, etc.) to a PocketBase instance. Flows carry owner, description, schedule, and arbitrary JSON metadata. Supports DAG-based flow dependencies with cascade health checks and two authentication modes (regular user and superuser). |
| Authors: | Quinten Goens [aut, cre] |
| Maintainer: | Quinten Goens <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-12-05 20:32:04 UTC |
| Source: | https://github.com/euctrl-pru/pocketlogR |
Adds one or more upstream flows as dependencies of the target flow. Validates that all named flows exist and that no cycle would be created.
pl_add_dependency(conn, flow, depends_on)pl_add_dependency(conn, flow, depends_on)
conn |
A connection object from |
flow |
Name of the flow to update. |
depends_on |
Character vector of upstream flow names to add. |
Invisibly returns the updated flow record.
## Not run: conn <- pl_connect() pl_add_dependency(conn, "ans_data_freshness", "another_upstream_flow") ## End(Not run)## Not run: conn <- pl_connect() pl_add_dependency(conn, "ans_data_freshness", "another_upstream_flow") ## End(Not run)
Authenticates against a PocketBase users auth collection and returns a
connection object for use with all daily pocketlogR functions.
pl_connect(url = NULL, email = NULL, password = NULL)pl_connect(url = NULL, email = NULL, password = NULL)
url |
PocketBase instance URL. Defaults to |
email |
Service account email. Defaults to |
password |
Service account password. Defaults to |
A named list with elements url (character) and token (character JWT).
## Not run: conn <- pl_connect() conn <- pl_connect( url = "https://myapp.pockethost.io", email = "[email protected]", password = "secret" ) ## End(Not run)## Not run: conn <- pl_connect() conn <- pl_connect( url = "https://myapp.pockethost.io", email = "[email protected]", password = "secret" ) ## End(Not run)
Authenticates against the _superusers collection. Use this only for
pl_setup(). Regular operations should use pl_connect().
pl_connect_admin(url = NULL, email = NULL, password = NULL)pl_connect_admin(url = NULL, email = NULL, password = NULL)
url |
PocketBase instance URL. Defaults to |
email |
Superuser email. Defaults to |
password |
Superuser password. Defaults to |
A named list with elements url (character) and token (character JWT).
## Not run: conn_admin <- pl_connect_admin() ## End(Not run)## Not run: conn_admin <- pl_connect_admin() ## End(Not run)
Registers a new flow in PocketBase. Errors if a flow with the same name
already exists. Validates that depends_on flows exist and that adding
them would not create a cycle in the DAG.
pl_create_flow( conn, name, type, owner, description = NULL, schedule = NULL, metadata = NULL, depends_on = NULL )pl_create_flow( conn, name, type, owner, description = NULL, schedule = NULL, metadata = NULL, depends_on = NULL )
conn |
A connection object from |
name |
Unique flow identifier (e.g. |
type |
Flow type string. See pl_flow_types for defaults, but any string is accepted. |
owner |
Free-text owner or responsible party (e.g. |
description |
Optional human-readable description. |
schedule |
Optional cron expression or human-readable schedule string. |
metadata |
Optional named list of arbitrary data, serialised to JSON (e.g. |
depends_on |
Optional character vector of upstream flow names. |
Invisibly returns the created flow record as a list.
## Not run: conn <- pl_connect() pl_create_flow(conn, "ectrl_data_load", type = "data_job", owner = "quinten", description = "Daily EUROCONTROL data import", schedule = "0 6 * * *") ## End(Not run)## Not run: conn <- pl_connect() pl_create_flow(conn, "ectrl_data_load", type = "data_job", owner = "quinten", description = "Daily EUROCONTROL data import", schedule = "0 6 * * *") ## End(Not run)
Deletes a flow by name. Requires a superuser connection. Because PocketBase
enforces referential integrity, any log entries referencing the flow must be
deleted first. Use force = TRUE to do this automatically.
pl_delete_flow(conn, flow, force = FALSE)pl_delete_flow(conn, flow, force = FALSE)
conn |
A superuser connection object from |
flow |
Flow name (character). |
force |
If |
Invisibly returns NULL.
## Not run: conn_admin <- pl_connect_admin() pl_delete_flow(conn_admin, "old_flow", force = TRUE) ## End(Not run)## Not run: conn_admin <- pl_connect_admin() pl_delete_flow(conn_admin, "old_flow", force = TRUE) ## End(Not run)
Deletes log entries. Requires a superuser connection. All filter arguments are optional and combined with AND logic. Called with no filters, deletes all log entries.
pl_delete_logs(conn, flow = NULL, before = NULL, status = NULL)pl_delete_logs(conn, flow = NULL, before = NULL, status = NULL)
conn |
A superuser connection object from |
flow |
Optional flow name. If provided, only logs for that flow are deleted. |
before |
Optional |
status |
Optional status string ( |
Invisibly returns the number of deleted records.
## Not run: conn_admin <- pl_connect_admin() # Delete all logs older than 30 days pl_delete_logs(conn_admin, before = Sys.time() - 30 * 86400) # Delete all error logs for a specific flow pl_delete_logs(conn_admin, flow = "ectrl_data_load", status = "ERROR") # Delete all logs for a flow (used internally by pl_delete_flow(force=TRUE)) pl_delete_logs(conn_admin, flow = "old_flow") ## End(Not run)## Not run: conn_admin <- pl_connect_admin() # Delete all logs older than 30 days pl_delete_logs(conn_admin, before = Sys.time() - 30 * 86400) # Delete all error logs for a specific flow pl_delete_logs(conn_admin, flow = "ectrl_data_load", status = "ERROR") # Delete all logs for a flow (used internally by pl_delete_flow(force=TRUE)) pl_delete_logs(conn_admin, flow = "old_flow") ## End(Not run)
Convenience wrapper around pl_log() for recoverable errors.
pl_error( conn, flow, log_type, message = NULL, metadata = NULL, logged_by = NULL, logged_from = NULL, source_file = NULL, source_repo = NULL )pl_error( conn, flow, log_type, message = NULL, metadata = NULL, logged_by = NULL, logged_from = NULL, source_file = NULL, source_repo = NULL )
conn |
A connection object from |
flow |
Flow name (character). |
log_type |
Free-text log type (e.g. |
message |
Optional human-readable log message. |
metadata |
Optional named list, serialized to JSON. |
logged_by |
Optional username of who created this log. If |
logged_from |
Optional named list with machine context (e.g.
|
source_file |
Optional filename of the script creating this log. If
|
source_repo |
Optional git repository name where the calling script
lives. If |
Invisibly returns the created log record, or NULL on failure.
## Not run: pl_error(conn, "ans_website_online", log_type = "website_online", message = "HTTP 503 returned", metadata = list(http_status = 503)) ## End(Not run)## Not run: pl_error(conn, "ans_website_online", log_type = "website_online", message = "HTTP 503 returned", metadata = list(http_status = 503)) ## End(Not run)
Convenience wrapper around pl_log() for unrecoverable failures.
pl_fatal( conn, flow, log_type, message = NULL, metadata = NULL, logged_by = NULL, logged_from = NULL, source_file = NULL, source_repo = NULL )pl_fatal( conn, flow, log_type, message = NULL, metadata = NULL, logged_by = NULL, logged_from = NULL, source_file = NULL, source_repo = NULL )
conn |
A connection object from |
flow |
Flow name (character). |
log_type |
Free-text log type (e.g. |
message |
Optional human-readable log message. |
metadata |
Optional named list, serialized to JSON. |
logged_by |
Optional username of who created this log. If |
logged_from |
Optional named list with machine context (e.g.
|
source_file |
Optional filename of the script creating this log. If
|
source_repo |
Optional git repository name where the calling script
lives. If |
Invisibly returns the created log record, or NULL on failure.
## Not run: pl_fatal(conn, "ectrl_data_load", log_type = "data_job", message = "Unrecoverable database error") ## End(Not run)## Not run: pl_fatal(conn, "ectrl_data_load", log_type = "data_job", message = "Unrecoverable database error") ## End(Not run)
A character vector of the default flow type identifiers used by pocketlogR. These are not enforced — any string is accepted as a type. They exist for documentation, consistency, and convenience.
pl_flow_typespl_flow_types
Returns a tibble (data.frame) of ALL flows with both their raw (most recent log) status and effective (cascade-aware) status. A flow is considered "poisoned" if any upstream dependency has a more recent ERROR/FATAL log than the flow's own last SUCCESS log — meaning the flow ran successfully before the upstream broke.
pl_get_dag(conn, since = NULL)pl_get_dag(conn, since = NULL)
conn |
A connection object from |
since |
Optional |
Poisoning rule: A downstream flow is poisoned if:
It has at least one upstream flow with an ERROR or FATAL log.
The downstream's last SUCCESS log is MORE RECENT than that upstream failure. (i.e., the downstream ran successfully after the upstream had already broken.)
The downstream itself is not already ERROR or FATAL.
If the downstream has never logged, effective_status is NA (unknown),
regardless of upstream status.
A data.frame with columns:
flow (character): flow name
type (character): flow type
schedule (character): schedule string
raw_status (character): most recent log status (NA if never logged)
raw_status_time (character): timestamp of most recent log
effective_status (character): "SUCCESS", "ERROR", "FATAL",
"POISONED", or NA if never logged
poisoned_by (list-column): character vector of upstream flow names
that caused poisoning
depends_on (list-column): character vector of direct upstream flow names
is_root (logical): TRUE if the flow has no upstream dependencies
## Not run: conn <- pl_connect() dag <- pl_get_dag(conn) dag ## End(Not run)## Not run: conn <- pl_connect() dag <- pl_get_dag(conn) dag ## End(Not run)
Returns a data.frame of upstream flows for the named flow.
pl_get_dependencies(conn, flow, recursive = FALSE)pl_get_dependencies(conn, flow, recursive = FALSE)
conn |
A connection object from |
flow |
Flow name. |
recursive |
If |
A data.frame with columns: name, type, description, schedule, depth.
## Not run: conn <- pl_connect() pl_get_dependencies(conn, "ans_monthly_update") pl_get_dependencies(conn, "ans_monthly_update", recursive = TRUE) ## End(Not run)## Not run: conn <- pl_connect() pl_get_dependencies(conn, "ans_monthly_update") pl_get_dependencies(conn, "ans_monthly_update", recursive = TRUE) ## End(Not run)
Returns a data.frame of flows, optionally filtered by type or name.
pl_get_flows(conn, type = NULL, name = NULL)pl_get_flows(conn, type = NULL, name = NULL)
conn |
A connection object from |
type |
Optional flow type to filter by. |
name |
Optional flow name to filter by. |
A data.frame with columns: id, name, type, description,
schedule, owner, metadata (list-column), depends_on (list-column of upstream flow names),
created, updated.
## Not run: conn <- pl_connect() pl_get_flows(conn) pl_get_flows(conn, type = "data_job") pl_get_flows(conn, name = "ectrl_data_load") ## End(Not run)## Not run: conn <- pl_connect() pl_get_flows(conn) pl_get_flows(conn, type = "data_job") pl_get_flows(conn, name = "ectrl_data_load") ## End(Not run)
Returns a data.frame of log entries, optionally filtered. All filter arguments are optional and combined with AND logic.
pl_get_logs( conn, flow = NULL, status = NULL, from = NULL, to = NULL, limit = 50 )pl_get_logs( conn, flow = NULL, status = NULL, from = NULL, to = NULL, limit = 50 )
conn |
A connection object from |
flow |
Optional flow name to filter by. |
status |
Optional status to filter by ( |
from |
Optional start timestamp ( |
to |
Optional end timestamp ( |
limit |
Maximum number of records to return. Default 50. |
A data.frame with columns: id, flow (flow name), log_type,
status, message, metadata, logged_by, logged_from (list-column),
source_file, source_repo, created.
## Not run: conn <- pl_connect() pl_get_logs(conn) pl_get_logs(conn, flow = "ectrl_data_load", status = "ERROR") pl_get_logs(conn, from = Sys.time() - 86400, limit = 100) ## End(Not run)## Not run: conn <- pl_connect() pl_get_logs(conn) pl_get_logs(conn, flow = "ectrl_data_load", status = "ERROR") pl_get_logs(conn, from = Sys.time() - 86400, limit = 100) ## End(Not run)
Walks the DAG upward (recursively through all upstream dependencies) and collects the most recent log entry for each flow in the chain, including the flow itself.
pl_get_status(conn, flow, since = NULL)pl_get_status(conn, flow, since = NULL)
conn |
A connection object from |
flow |
Flow name. |
since |
Optional |
A data.frame sorted by depth then flow, with columns: flow,
type, status, message, created, depth.
## Not run: conn <- pl_connect() pl_get_status(conn, "ans_monthly_update") pl_get_status(conn, "ans_monthly_update", since = Sys.time() - 86400) ## End(Not run)## Not run: conn <- pl_connect() pl_get_status(conn, "ans_monthly_update") pl_get_status(conn, "ans_monthly_update", since = Sys.time() - 86400) ## End(Not run)
Records a log entry for the named flow. On HTTP failure, retries up to
3 times with 2-second intervals. If all retries fail, emits a warning
and returns NULL invisibly — the calling script is never stopped.
pl_log( conn, flow, status, log_type, message = NULL, metadata = NULL, logged_by = NULL, logged_from = NULL, source_file = NULL, source_repo = NULL )pl_log( conn, flow, status, log_type, message = NULL, metadata = NULL, logged_by = NULL, logged_from = NULL, source_file = NULL, source_repo = NULL )
conn |
A connection object from |
flow |
Flow name (character). |
status |
One of |
log_type |
Free-text log type (e.g. |
message |
Optional human-readable log message. |
metadata |
Optional named list, serialized to JSON. |
logged_by |
Optional username of who created this log. If |
logged_from |
Optional named list with machine context (e.g.
|
source_file |
Optional filename of the script creating this log. If
|
source_repo |
Optional git repository name where the calling script
lives. If |
Invisibly returns the created log record, or NULL on failure.
## Not run: conn <- pl_connect() pl_log(conn, "ectrl_data_load", "SUCCESS", log_type = "data_job", message = "Loaded 14230 rows", metadata = list(rows = 14230, duration_s = 45.2)) # Override auto-detected user pl_log(conn, "ectrl_data_load", "SUCCESS", log_type = "data_job", logged_by = "scheduled-task") ## End(Not run)## Not run: conn <- pl_connect() pl_log(conn, "ectrl_data_load", "SUCCESS", log_type = "data_job", message = "Loaded 14230 rows", metadata = list(rows = 14230, duration_s = 45.2)) # Override auto-detected user pl_log(conn, "ectrl_data_load", "SUCCESS", log_type = "data_job", logged_by = "scheduled-task") ## End(Not run)
A character vector of the default log type identifiers used by pocketlogR. These are not enforced — any string is accepted as a log type. They exist for documentation, consistency, and convenience.
pl_log_typespl_log_types
Removes one or more upstream flows from the dependency list of the target flow.
pl_remove_dependency(conn, flow, depends_on)pl_remove_dependency(conn, flow, depends_on)
conn |
A connection object from |
flow |
Name of the flow to update. |
depends_on |
Character vector of upstream flow names to remove. |
Invisibly returns the updated flow record.
## Not run: conn <- pl_connect() pl_remove_dependency(conn, "ans_data_freshness", "another_upstream_flow") ## End(Not run)## Not run: conn <- pl_connect() pl_remove_dependency(conn, "ans_data_freshness", "another_upstream_flow") ## End(Not run)
Creates the pl_flows and pl_logs collections with the correct schema and
API rules. Requires a superuser connection from pl_connect_admin().
This function is idempotent — safe to call multiple times.
pl_setup(conn)pl_setup(conn)
conn |
A superuser connection object from |
Invisibly returns NULL.
## Not run: conn_admin <- pl_connect_admin() pl_setup(conn_admin) ## End(Not run)## Not run: conn_admin <- pl_connect_admin() pl_setup(conn_admin) ## End(Not run)
Convenience wrapper around pl_log() for successful outcomes.
pl_success( conn, flow, log_type, message = NULL, metadata = NULL, logged_by = NULL, logged_from = NULL, source_file = NULL, source_repo = NULL )pl_success( conn, flow, log_type, message = NULL, metadata = NULL, logged_by = NULL, logged_from = NULL, source_file = NULL, source_repo = NULL )
conn |
A connection object from |
flow |
Flow name (character). |
log_type |
Free-text log type (e.g. |
message |
Optional human-readable log message. |
metadata |
Optional named list, serialized to JSON. |
logged_by |
Optional username of who created this log. If |
logged_from |
Optional named list with machine context (e.g.
|
source_file |
Optional filename of the script creating this log. If
|
source_repo |
Optional git repository name where the calling script
lives. If |
Invisibly returns the created log record, or NULL on failure.
## Not run: pl_success(conn, "ectrl_data_load", log_type = "data_job", message = "Loaded 14230 rows", metadata = list(rows = 14230)) ## End(Not run)## Not run: pl_success(conn, "ectrl_data_load", log_type = "data_job", message = "Loaded 14230 rows", metadata = list(rows = 14230)) ## End(Not run)