Skip to content

Application Logs (`log_file`)

inputs.log_file tails local application log files in real time, retaining raw single lines in chronological order inside a bounded local memory buffer with zero steady-state disk writes. When an incident triggers, it extracts pre/post log context (with grep -B/-A style slicing in noisy logs) and correlates with APM traces via trace_id.

[!TIP] Why raw single lines instead of multiline regex merging? Inside a chronological ring buffer, stack traces naturally follow the error line. Skipping fragile multiline parsers eliminates flush delays, matches grep -B/-A operator intuition, and avoids OOM spikes from huge merged entries.

inputs:
log_file:
- id: order_app
path: /var/log/order/app.log
from_beginning: false # Default false (tail from end of file)
poll_interval: 500ms # File polling cadence (default 500ms)
interval: 5s # Operational metrics flush interval (inherits global.interval)
max_line_bytes: 4096 # Per-line truncation ceiling (default 4 KiB)
max_lines_per_sec: 5000 # Log storm rate limit (default 5000 lines/s)
max_read_bytes_per_poll: 1048576 # Max bytes read per poll cycle (default 1 MiB)
trace_id_regex: "" # Optional: custom trace_id regex (1 capture group); "none" disables
  • Rotation & truncation aware: Automatically handles rename-and-recreate log rotation as well as in-place truncation.
  • Self-ingestion loop guard: Automatically blocks log paths pointing inside storage.dir at config load time.
  • Automatic trace_id correlation: Extracts trace_id best-effort with near-zero overhead when absent, and unlocks two-way correlation with inputs.apm whenever present.
Metric Description
log_file.<id>.up Whether the log file is currently open and tracked (1 / 0)
log_file.<id>.lines_read Lines ingested into memory buffer in the last interval
log_file.<id>.lines_dropped Lines dropped due to max_lines_per_sec rate limiting
log_file.<id>.bytes_read Bytes consumed from the file in the last interval
alerts:
# Trigger full-context capture on 3+ ERROR or panic lines within 60s
- id: order_log_error_burst
severity: critical
expr: 'log_count("log_file.order_app", "ERROR|panic", 60) >= 3'
attach: ["host/default"]
# Cross-pillar rule: sustained high CPU combined with timeout logs
- id: cpu_and_timeout_log
severity: critical
expr: 'avg("cpu.usage_pct", 60) > 85 && log_exists("log_file.order_app", "timeout", 60)'

[!NOTE] Ingestion Limits: Per-poll reads are capped by max_read_bytes_per_poll (default 1 MiB) and per-line length by max_line_bytes (default 4 KiB). Incomplete lines and rotation boundaries are handled safely. See Security & Resource Limits for full details.