Turso.AuditLogs (turso v0.1.1)
View SourceAudit log retrieval for Turso Cloud Platform.
This module provides functions for accessing audit logs that track all activities and changes within your Turso organization. Audit logs are useful for compliance, security monitoring, and troubleshooting.
Summary
Functions
Lists audit logs for the organization.
Retrieves a specific audit log entry by ID.
Streams all audit logs for the organization.
Types
@type api_result(success_type) :: Turso.api_result(success_type)
Functions
@spec list( Turso.t(), keyword() ) :: api_result(map())
Lists audit logs for the organization.
Returns a paginated list of audit log entries showing all activities within the organization.
Options
:organization(String.t/0) - Organization slug. Overrides client default.:page_size(pos_integer/0) - Number of logs to return per page (max 1000). The default value is100.:page_token(String.t/0) - Token for pagination to get the next page of results.:order(String.t/0) - Sort order: 'asc' for ascending, 'desc' for descending (default).:start_time(String.t/0) - Start time for log filtering (ISO 8601 format).:end_time(String.t/0) - End time for log filtering (ISO 8601 format).:action(String.t/0) - Filter by specific action type (e.g., 'database.create').:actor_id(String.t/0) - Filter by actor (user) ID who performed the action.
Examples
# Basic audit log listing
{:ok, response} = Turso.AuditLogs.list(client)
# With pagination and filtering
{:ok, response} = Turso.AuditLogs.list(client,
page_size: 50,
action: "database.create",
start_time: "2024-01-01T00:00:00Z"
)Returns
{:ok, map()}- Audit logs response with logs and pagination info{:error, map()}- Error details
Response Format
The response typically contains:
audit_logs- Array of audit log entriespage_token- Token for next page (if more results available)has_more- Boolean indicating if more results are available
Audit Log Entry
Each audit log entry contains:
id- Unique log entry IDtimestamp- When the action occurred (ISO 8601)action- The action that was performedactor_id- ID of the user who performed the actionactor_email- Email of the user who performed the actionresource_type- Type of resource affected (e.g., "database", "group")resource_id- ID of the affected resourcedetails- Additional details about the actionip_address- IP address of the actoruser_agent- User agent string of the request
@spec retrieve(Turso.t(), String.t(), keyword()) :: api_result(audit_log())
Retrieves a specific audit log entry by ID.
Examples
{:ok, log_entry} = Turso.AuditLogs.retrieve(client, "log-123", organization: "my-org")Parameters
client- The Turso clientlog_id- The audit log entry IDopts- Options including organization override
Returns
{:ok, audit_log()}- The audit log entry{:error, map()}- Error details
@spec stream( Turso.t(), keyword() ) :: Enumerable.t()
Streams all audit logs for the organization.
This is a convenience function that automatically handles pagination to retrieve all audit logs. It returns a stream that yields individual audit log entries.
Examples
# Stream all audit logs
client
|> Turso.AuditLogs.stream()
|> Enum.take(100)
# Stream with filtering
client
|> Turso.AuditLogs.stream(action: "database.create")
|> Stream.filter(&filter_function/1)
|> Enum.to_list()Parameters
client- The Turso clientopts- Same options aslist/2, except page_token which is managed automatically
Returns
A Stream that yields individual audit log entries.
Note
This function makes multiple API calls as needed to fetch all pages. Use with care for large audit log datasets to avoid rate limiting.