Skip to content

/admin/user_logs

Path: /admin/user_logs
Namespace: admin
Resource: user_logs

Overview

The UserLog resource represents user activity logs and system logs for audit trails and monitoring. User logs track user actions, system events, and access patterns.

Relationships

UserLog connects to:

  • User (user_id) - User associated with the log (optional, for guest logs)
  • Domain (host_id) - Tenant domain

Key Features

  • User Activity Tracking: Logs track user actions and system interactions
  • Audit Trail: Maintains audit records for compliance and security
  • System Monitoring: Tracks system events and access patterns
  • User Association: Logs are associated with users (or marked as guest)

Available Operations

List User Logs (GET)

Endpoint: GET /admin/user_logs.json

Query Parameters:

  • q[field_predicate]=value - Ransack query filters for advanced filtering
  • scope=name - Apply named scope (e.g., yours, others, user, guest, success, exception)
  • page=N - Page number for pagination
  • per_page=N - Items per page (default: 25)

Request Examples:

bash
curl -X GET "https://your-company.erpax.com/admin/user_logs.json" \
  -H "Accept: application/json" \
  -H "Cookie: session_cookie"
bash
curl -X GET "https://your-company.erpax.com/admin/user_logs.json?scope=yours" \
  -H "Accept: application/json"
bash
curl -X GET "https://your-company.erpax.com/admin/user_logs.json?q[user_email_contains]=admin" \
  -H "Accept: application/json"

JavaScript Example:

javascript
const response = await fetch('/admin/user_logs.json', {
  credentials: 'include',
  headers: { 'Accept': 'application/json' }
});
const data = await response.json();

Response (200 OK):

json
{
  "user_logs": [
    {
      "id": 1,
      "user_id": 1,
      "remote_ip": "192.168.1.1",
      "request_method": "GET",
      "url": "/admin/invoices",
      "namespace": "admin",
      "controller": "invoices",
      "action": "index",
      "content_length": 1024,
      "created_at": "2024-01-15T10:00:00Z"
    }
  ],
  "meta": {
    "current_page": 1,
    "per_page": 25,
    "total_pages": 10,
    "total_count": 250
  }
}

Show User Log (GET /:id)

Endpoint: GET /admin/user_logs/:id.json

Request Example:

bash
curl -X GET "https://your-company.erpax.com/admin/user_logs/1.json" \
  -H "Accept: application/json" \
  -H "Cookie: session_cookie"

Response (200 OK):

json
{
  "user_log": {
    "id": 1,
    "user_id": 1,
    "remote_ip": "192.168.1.1",
    "uuid": "550e8400-e29b-41d4-a716-446655440000",
    "request_method": "GET",
    "url": "/admin/invoices",
    "namespace": "admin",
    "controller": "invoices",
    "action": "index",
    "content_length": 1024,
    "ssl": true,
    "xhr": false,
    "exception": null,
    "headers": "...",
    "created_at": "2024-01-15T10:00:00Z"
  }
}

Note: User logs are typically read-only and created automatically by the system. Create, update, and delete operations are typically not available.

Scopes

  • all (default) - All user logs
  • yours - Logs for current user
  • others - Logs for other users (excluding current user)
  • user - User logs (authenticated users)
  • guest - Guest logs (unauthenticated users)
  • success - Successful requests
  • exception - Requests with exceptions
  • flashes - Requests with flash messages

Usage Example:

bash
GET /admin/user_logs.json?scope=yours
GET /admin/user_logs.json?scope=exception
GET /admin/user_logs.json?scope=guest

Filters

Available filters for searching and filtering user logs:

  • headers_or_uuid_or_remote_ip_contains (autofocus) - Text filter - Search by headers, UUID, or remote IP (contains)
  • alert_or_notice_cont - Text filter - Search by alert or notice (contains)
  • user_email_contains - Text filter - Search by user email (contains)
  • remote_ip - Text filter - Filter by remote IP address
  • uuid - Text filter - Filter by UUID
  • namespace - Text filter - Filter by namespace
  • controller - Text filter - Filter by controller
  • action - Text filter - Filter by action
  • request_method - Text filter - Filter by HTTP request method
  • content_length - Numeric filter - Filter by content length
  • ssl - Boolean filter - Filter by SSL
  • xhr - Boolean filter - Filter by XHR requests
  • exception - Text filter - Filter by exception
  • created_at - Date filter - Filter by creation date

Filtering Examples:

bash
# Filter by user email
GET /admin/user_logs.json?q[user_email_contains]=admin

# Filter by IP address
GET /admin/user_logs.json?q[remote_ip_eq]=192.168.1.1

# Filter by namespace and controller
GET /admin/user_logs.json?q[namespace_eq]=admin&q[controller_eq]=invoices

Business Rules

  • Automatic Creation: User logs are automatically created by the system
  • Read-Only: User logs are typically read-only (no create, update, delete operations)
  • User Association: Logs can be associated with users or marked as guest
  • Audit Trail: Logs provide complete audit trail for compliance and security

Nested Resources

User logs can be nested under users:

  • Users - Users associated with logs
  • Domains - Domain-scoped logs

Released under an open source license.