Prompt
We have messy app logs from VMs and containers. Can you recommend how to collect, parse, and search them?
Latest observation
Yes — a good approach is to separate log collection, parsing/normalization, and search/analysis. For messy logs from both VMs and containers, I’d recommend a pipeline like this:
1) Collect logs close to the source
On VMs
- Use a lightweight shipper such as:
- Fluent Bit
- Vector
- Filebeat
- Configure it to tail:
- app log files
- system logs (
journald, syslog) - web server logs
- container runtime logs if present
On containers / Kubernetes
- Prefer stdout/stderr logging from apps.
- Use a node-level log agent to collect container logs from:
/var/log/containers/var/log/pods
- In Kubernetes, common options:
- Fluent Bit DaemonSet
- Vector DaemonSet
- Promtail if using Grafana/Loki
2) Normalize logs into a common structure
Messy logs become much easier to search when they’re converted to structured fields.
Recommended fields
At minimum, standardize on:
timestamphostnameserviceenvironmentcontainer_idorpod_namelevelmessagerequest_id/trace_idif available
Parsing options
Use parsers for:
- JSON logs: easiest and best if you can change the app
- Multiline logs: stack traces, Java exceptions, Python tracebacks
- Regex/grok: for legacy text logs
- Key-value parsing: for logs like
k=v
Best practice
If you can influence applications, emit JSON logs directly. That reduces parsing errors and makes search and analytics much better.
3) Send logs to a searchable backend
Choose based on scale and how you want to query.
Good options
- Elasticsearch / OpenSearch
- Strong full-text search
- Good dashboards with Kibana / OpenSearch Dashboards
- Grafana Loki
- Great for Kubernetes/container logs
- Cheaper and simpler when you mostly search by labels and grep-like queries
- Splunk
- Enterprise option, powerful but can be expensive
Rule of thumb
- If you want fast full-text search and rich analytics: OpenSearch/Elasticsearch
- If you want simple ops and cost-efficient log aggregation: Loki
- If you need enterprise features and mature tooling: Splunk
4) Handle messy/legacy logs with enrichment
Add metadata at ingestion time:
- environment:
prod,staging - app/service name
- region/cluster/node
- container image/version
- cloud metadata (instance ID, auto-scaling group, etc.)
This makes queries much easier, even if the raw message is ugly.
5) Parse multiline logs correctly
A common issue is stack traces being split into separate events. Configure:
- line-start patterns
- time-based flush limits
- exception/stack-trace detection
Without this, searches become noisy and incomplete.
6) Search strategy
Make sure your search system supports:
- keyword search over raw message
- field-based filters
- time ranges
- pattern matching / regex
- aggregation by level, service, host, error code
Examples of useful searches:
- all
ERRORlogs for one service in the last hour - logs with a specific
trace_id - top exception types by count
- all logs from a bad deployment version
7) Recommended stack examples
Simple and strong for mixed VMs + containers
- Fluent Bit for collection
- OpenSearch for storage/search
- OpenSearch Dashboards for UI
Kubernetes-friendly and cost-conscious
- Fluent Bit or Vector
- Loki
- Grafana
Enterprise-heavy environment
- Filebeat / Fluent Bit
- Elasticsearch
- Kibana
8) Practical tips
- Avoid sending every debug log to long-term storage unless needed.
- Set retention policies by environment:
- prod longer retention
- dev/test shorter retention
- Use sampling for very high-volume debug logs.
- Protect sensitive data:
- redact passwords, tokens, PII before storage
- Standardize log format in new services:
- JSON with consistent field names
9) If you’re starting from scratch
A solid default architecture is:
Apps → stdout/log files → Fluent Bit/Vector → OpenSearch or Loki → Dashboard/search UI
If you want, I can also suggest:
- a specific stack for your size/use case,
- example configs for Fluent Bit/Vector,
- or a migration plan for messy legacy logs.