Context module for server log persistence and querying. Provides functions for inserting, listing, counting, pruning logs, and managing monthly partitions.
Summary
Functions
Counts logs matching the given filters (ignores limit/offset).
Drops a partition for the given year/month.
Creates a partition for the given year/month. Idempotent.
Bulk inserts log entries into the server_logs table.
Uses log: false to prevent Ecto query logs from causing recursion.
Lists logs with filtering, sorting, and pagination.
Lists all child partitions of the server_logs table. Returns a list of maps with :name, :from, and :to keys.
Conditionally logs a message with the [ServerLogger] prefix,
based on the :logging_enabled config setting.
Checks if a partition exists for the given year/month.
Deletes logs of the specified level older than the given number of days. Deletes in batches of 10,000 to avoid long locks.
Returns the total disk usage of the server_logs table (including all partitions and indexes) in bytes.
Truncates a message if it exceeds the configured max_message_size_mb. Appends " [truncated]" to truncated messages.
Functions
Counts logs matching the given filters (ignores limit/offset).
Drops a partition for the given year/month.
Creates a partition for the given year/month. Idempotent.
Bulk inserts log entries into the server_logs table.
Uses log: false to prevent Ecto query logs from causing recursion.
Lists logs with filtering, sorting, and pagination.
Options
:levels— list of level strings to include:search— keyword search via ILIKE on message, module, request_id:from/:to— datetime range filter on logged_at:sort_by— column atom (default: :logged_at):sort_dir— :asc or :desc (default: :desc):limit— max results (default: 100):offset— offset for pagination (default: 0)
Lists all child partitions of the server_logs table. Returns a list of maps with :name, :from, and :to keys.
Conditionally logs a message with the [ServerLogger] prefix,
based on the :logging_enabled config setting.
Checks if a partition exists for the given year/month.
Deletes logs of the specified level older than the given number of days. Deletes in batches of 10,000 to avoid long locks.
Returns the total disk usage of the server_logs table (including all partitions and indexes) in bytes.
Truncates a message if it exceeds the configured max_message_size_mb. Appends " [truncated]" to truncated messages.