Audit Logging and Monitoring Your Openclaw Deployment

Openclaw (formerly Clawdbot) is an autonomous AI agent that acts on your behalf: sending messages, calling APIs, executing skills, and managing workflows without waiting for approval at every step. That autonomy is what makes it powerful, but it also means you need a clear, reliable record of everything the agent did, when it did it, and why. Without audit logging, you are flying blind.

Audit logging serves two purposes that are equally important. First, it is your security backbone. If something goes wrong, whether a compromised credential, an unexpected action, or anomalous API usage, logs are how you detect it, investigate it, and prove what happened. Second, it is your debugging tool. When the agent produces an unexpected response or a skill fails silently, structured logs let you trace the exact sequence of events that led to the problem. This article is part of our complete Openclaw deployment security guide, which covers all five pillars of a hardened installation.

What to Log

An Openclaw deployment generates several categories of events. Logging all of them creates a complete audit trail. Logging only some leaves gaps that make incident investigation difficult or impossible. Here is what a comprehensive logging configuration covers:

Event Type Key Fields Retention
API Calls Model, input/output tokens, cost, latency, status code 90 days
Messaging Interactions Channel (Slack, Telegram, etc.), direction (inbound/outbound), timestamp, user ID 90 days
Skill Invocations Skill name, input parameters, result status, execution duration 90 days
Auth Events Event type (login, token refresh, failure), source IP, user agent 180 days
Errors and Exceptions Error code, stack trace, triggering request, severity 90 days
Config Changes Changed field, previous value, new value, changed by, timestamp 365 days

The retention periods above are starting recommendations. Your compliance requirements may dictate longer retention for auth events and config changes. The key principle is: if the agent can do it, it should be logged.

Structured Logging Format

Plain-text logs are human-readable but nearly impossible to search, filter, or analyze at scale. Structured JSON logging solves this by giving every log entry a consistent schema that can be parsed programmatically. Each entry should include a core set of fields: a UTC timestamp, an event type, the acting user or system component, the action taken, the resource affected, the outcome, and a metadata object for event-specific details.

Here is a sample JSON log entry for an Anthropic API call:

{
  "timestamp": "2026-02-12T14:32:08.441Z",
  "event_type": "api_call",
  "user": "openclaw-agent",
  "action": "chat_completion",
  "resource": "anthropic/claude-sonnet-4-20250514",
  "outcome": "success",
  "metadata": {
    "input_tokens": 1847,
    "output_tokens": 532,
    "cost_usd": 0.0143,
    "latency_ms": 2340,
    "status_code": 200,
    "request_id": "req_a7f3b2c1d4e5"
  }
}

And here is a log entry for a skill invocation:

{
  "timestamp": "2026-02-12T14:32:11.087Z",
  "event_type": "skill_invocation",
  "user": "openclaw-agent",
  "action": "execute_skill",
  "resource": "calendar/create_event",
  "outcome": "success",
  "metadata": {
    "parameters": {
      "title": "Team standup",
      "start": "2026-02-13T09:00:00Z",
      "duration_minutes": 15
    },
    "execution_ms": 870,
    "result": "event_created",
    "trigger": "slack_message:U04ABCDEF"
  }
}

With this structure, you can query all failed API calls in the last hour, calculate daily token spend by model, or trace every action triggered by a specific user message. Store these entries one per line (JSONL format) for easy ingestion by log analysis tools.

Docker Logging Configuration

Openclaw runs inside a Docker container, and Docker provides logging drivers that capture everything written to stdout and stderr. The default json-file driver works well for most deployments, but you must configure log rotation to prevent unbounded disk growth. Without rotation, an active Openclaw agent can generate gigabytes of logs within weeks.

Add the following logging configuration to your docker-compose.yml:

version: "3.8"

services:
  openclaw:
    image: clawdbot/clawdbot:latest
    container_name: openclaw
    restart: unless-stopped
    env_file:
      - .env
    ports:
      - "3000:3000"
    volumes:
      - openclaw_data:/app/data
      - openclaw_logs:/app/logs
    logging:
      driver: json-file
      options:
        max-size: "50m"
        max-file: "10"
        tag: "openclaw/{{.Name}}"
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:3000/health"]
      interval: 60s
      timeout: 10s
      retries: 3
      start_period: 30s

volumes:
  openclaw_data:
  openclaw_logs:

This configuration caps each log file at 50 MB and keeps 10 rotated files, giving you approximately 500 MB of log history through Docker's built-in rotation. The tag option adds the container name to each entry, which helps if you run multiple containers on the same host. The health check endpoint lets Docker automatically restart the container if the agent becomes unresponsive.

Monitoring included in every setup.

Every Openclaw Setup Pro plan ships with structured logging, log rotation, and health checks pre-configured. You get visibility from day one.

View Plans

Log Rotation and Retention

Docker's built-in rotation handles container stdout, but your application-level logs written to the /app/logs volume also need rotation. An active Openclaw agent processing dozens of messages per day can produce 20-50 MB of structured log data daily. Left unmanaged, this fills disks and eventually crashes the container.

Configure logrotate on the host to manage application logs:

# /etc/logrotate.d/openclaw
/var/lib/docker/volumes/openclaw_logs/_data/*.log {
    daily
    missingok
    rotate 30
    compress
    delaycompress
    notifempty
    create 0640 root root
    dateext
    dateformat -%Y%m%d
    postrotate
        docker kill --signal=HUP openclaw 2>/dev/null || true
    endscript
}

# Archive older logs to cold storage
# Run via cron: 0 2 * * 0 /usr/local/bin/archive-openclaw-logs.sh
# Moves compressed logs older than 30 days to /mnt/archive
# Deletes archived logs older than 90 days

The recommended retention policy is two tiers: keep 30 days of logs on the active server for quick access and investigation, then archive compressed logs to a separate storage location for up to 90 days. Auth events and configuration changes should be retained for longer, ideally 180 to 365 days, as these are the most relevant for security audits and compliance reviews.

Real-Time Monitoring and Alerting

Logging is only useful if someone, or something, reads the logs. Real-time monitoring turns passive log data into active alerts that tell you when something requires attention. You do not need a complex observability stack to get started. A simple monitoring script running on cron can cover the most critical scenarios.

Key alert patterns to watch for:

  • Consecutive errors: Three or more API failures in a row indicates a service disruption or revoked key.
  • Cost spikes: Hourly token spend exceeding 3x the trailing 7-day average suggests a runaway loop.
  • Agent unresponsive: The health check endpoint returning non-200 for more than 5 minutes.
  • Auth failures: Multiple failed authentication attempts from unknown IPs.

Here is a basic health check and alert script:

#!/bin/bash
# /usr/local/bin/openclaw-monitor.sh
# Run via cron every 5 minutes: */5 * * * * /usr/local/bin/openclaw-monitor.sh

HEALTH_URL="http://localhost:3000/health"
LOG_DIR="/var/lib/docker/volumes/openclaw_logs/_data"
ALERT_EMAIL="ops@yourdomain.com"
STATE_FILE="/tmp/openclaw-monitor-state"

# Check 1: Health endpoint
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" --max-time 10 "$HEALTH_URL")
if [ "$HTTP_STATUS" != "200" ]; then
    FAIL_COUNT=$(cat "$STATE_FILE" 2>/dev/null || echo 0)
    FAIL_COUNT=$((FAIL_COUNT + 1))
    echo "$FAIL_COUNT" > "$STATE_FILE"

    if [ "$FAIL_COUNT" -ge 3 ]; then
        echo "Openclaw health check failed $FAIL_COUNT consecutive times (HTTP $HTTP_STATUS)" | \
            mail -s "ALERT: Openclaw agent unresponsive" "$ALERT_EMAIL"
    fi
else
    echo 0 > "$STATE_FILE"
fi

# Check 2: Recent error rate
ERROR_COUNT=$(grep -c '"outcome":"error"' "$LOG_DIR/openclaw.log" 2>/dev/null | tail -1)
if [ "$ERROR_COUNT" -gt 50 ]; then
    echo "High error count in current log: $ERROR_COUNT errors" | \
        mail -s "ALERT: Openclaw elevated error rate" "$ALERT_EMAIL"
fi

# Check 3: Disk usage for log volume
USAGE=$(df "$LOG_DIR" 2>/dev/null | tail -1 | awk '{print $5}' | tr -d '%')
if [ -n "$USAGE" ] && [ "$USAGE" -gt 85 ]; then
    echo "Log volume disk usage at ${USAGE}%" | \
        mail -s "WARNING: Openclaw log disk usage high" "$ALERT_EMAIL"
fi

This script runs every five minutes, checks the health endpoint, counts recent errors, and monitors disk usage on the log volume. When any threshold is breached, it sends an email alert. For production deployments, you can extend this to post alerts to Slack or PagerDuty using their webhook APIs.

Anomaly Detection

Alerts based on fixed thresholds catch the obvious failures, but anomaly detection catches the subtle ones. The idea is to establish a baseline of normal behavior and then flag significant deviations. For an Openclaw deployment, the key metrics to baseline are: daily API token consumption, messages processed per hour, skill invocations per day, and unique source IPs.

Deviations worth investigating include token usage exceeding 3x the 7-day rolling average, API calls from IP addresses not in your known list, skill invocations at unusual hours (for example, calendar management at 3 AM when the user is in a US time zone), and sudden changes in the ratio of input to output tokens, which can indicate prompt injection attempts.

Anomaly detection is most powerful when tied to automated responses. A cost spike should trigger the budget guardrails covered in our budget guardrails guide, pausing the agent before spend escalates. An unexpected IP should trigger an auth event review. A skills pattern anomaly should generate a detailed audit report for manual review.

Compliance Considerations

Audit logs frequently contain personally identifiable information (PII): user names, email addresses, message content, and IP addresses. How you handle this data depends on the jurisdictions you operate in and the regulations that apply to your organization.

The first principle is log redaction. Sensitive fields like full message content, email bodies, and authentication tokens should be either excluded from logs entirely or replaced with hashed or truncated values. For example, log that a message was sent to a Slack channel, but do not log the full message body. Log that an API key was used, but store only the last four characters of the key.

The second principle is retention limits. GDPR requires that personal data be retained only as long as necessary for its stated purpose. If your logs contain PII, you need a defensible retention policy and an automated process to enforce it. The 30/90-day tiered approach described above provides a reasonable starting point, but consult with legal counsel if you operate in the EU, process health data, or handle financial records.

The third principle is access control. Audit logs themselves must be protected. Restrict read access to operations personnel who need it for incident response, and write access to the Openclaw agent process only. Log tampering should be detectable, which is another reason to ship logs to a separate storage system rather than relying solely on the host filesystem.

Skip the Security Guesswork

Get Openclaw professionally installed and hardened on your infrastructure in under 24 hours. Structured logging, monitoring, and alerting included. Plans from $2,449 (one-time).

View Plans Book a Call

Related articles: