AI Log Analysis in 2026: What Works, What Hallucinates, What It Costs
Every few weeks someone shows me a demo where a chatbot reads a pile of logs and announces the root cause, and every time I ask the same two questions: how many tokens was that, and how often is it right? AI log analysis in 2026 is three different technologies wearing one marketing label. Log template mining is old, cheap and genuinely good. Anomaly detection on top of templates works when it counts things and gets shaky when it tries to be clever. LLM summarisation is useful for explaining what you already narrowed down, and expensive and unreliable when you point it at raw logs and ask "why". This post separates the three, puts real numbers on each (including a run I did on public Loghub data), and covers what Datadog, Elastic and Grafana actually ship and what you give away when logs leave your network.
What does AI log analysis actually mean in 2026?
Strip the branding and almost every product does some combination of three jobs.
- Templating (log parsing). Turn
PacketResponder 1 for block blk_388 terminatingand a million siblings into one template,PacketResponder <*> for block <*> terminating, plus a count. This is clustering, not language understanding, and it is where most of the value comes from. - Anomaly detection. Watch template counts over time and flag the new ones, the rare ones and the ones whose rate jumped. This is the same baseline-versus-now maths I covered in anomaly detection for DevOps metrics, applied to log-derived series.
- LLM explanation. Hand a model a small, selected bundle of evidence and ask it to say what it means in English and what to check next. Agentic variants let the model run queries itself.
Demos skip to job three and quietly rely on jobs one and two. If you want the wider picture of where this sits, my AIOps explainer covers the rest of the category.
Log template mining with Drain: the boring part that works
The algorithm underneath most of this is Drain, from the 2017 ICWS paper Drain: An Online Log Parsing Approach with Fixed Depth Tree by Pinjia He, Jieming Zhu, Zibin Zheng and Michael Lyu. It streams lines through a shallow parse tree keyed on token count and leading tokens, then merges a line into the most similar existing cluster or starts a new one. It never compares a line against every template, and it works on a live stream rather than a nightly batch.
You meet Drain whether you know it or not. The Elasticsearch categorize_text aggregation and Kibana's pattern analysis do the same job of collapsing messages into categories. Grafana Loki's pattern ingester runs a lightly adjusted fork of a Go Drain implementation, and Logs Drilldown shows the result as patterns with <_> placeholders, mined only from the previous three hours of logs. The reference Python implementation, Drain3, now lives under the logpai organisation; its last PyPI release, 0.9.11, is from July 2022, which tells you this layer is mature rather than abandoned.
How good is it? The Loghub-2.0 evaluation re-tested 15 parsers on 14 datasets averaging 3.6 million lines each and found that accurate parsing of logs for rare system events "remains a challenge". That caveat matters, because rare events are exactly what you are hunting during an incident.
I ran Drain3 0.9.11 on two public 2,000-line samples from Loghub, treating the first 1,500 lines as baseline and the last 500 as "now". The HDFS sample collapsed to 16 templates; the Linux syslog sample to 108. On the HDFS file, 100,000 lines (the sample repeated 50 times) took about 2 seconds on an M3 Pro laptop. No GPU, no API key, no data leaving the machine. The core loop is a dozen lines; the full pipeline is in the step-by-step Drain3 and local LLM guide.
# pip install drain3==0.9.11 (Python 3.12)
from collections import Counter
from drain3 import TemplateMiner
miner, counts = TemplateMiner(), Counter()
for line in open("HDFS_2k.log"): # Loghub sample
body = line.split(" ", 3)[-1].strip() # drop date, time, pid
counts[miner.add_log_message(body)["cluster_id"]] += 1
for c in sorted(miner.drain.clusters, key=lambda c: -counts[c.cluster_id])[:3]:
print(counts[c.cluster_id], c.get_template()) # count, then template
Two lessons from that run are worth knowing before you trust any vendor's pattern view:
- Masking order matters. My first config masked long hex strings before HDFS block IDs, and half of every block ID turned into
<HEX>. Pre-masking IPs, IDs and PIDs with regexes before Drain sees the line is what makes templates readable. - Drain groups by token count. HDFS "ask datanode to delete" lines carry a variable-length list of block IDs, so each list length became its own "new" template. A human sees one event; the algorithm sees three. Anything downstream that says "three new error types appeared" may be counting list lengths.
Log anomaly detection: counting beats cleverness
Once lines are templates, anomaly detection becomes a counting problem: which templates are new in this window, which are rare against the baseline, which jumped in rate. In my Linux sample, 83 of the 92 templates in the final window had never appeared in the baseline. That looks like a catastrophe until you read them: BIOS memory maps, kernel hash tables, syslog startup succeeded. The host rebooted on 27 July. A new-template spike is a very good reboot, deploy and config-change detector, and a poor severity signal on its own.
The research on fancier models is sobering. Log-based Anomaly Detection with Deep Learning: How Far Are We? evaluated five neural approaches on four public datasets and found results swing with how training data is chosen, how logs are grouped, class imbalance and label noise, concluding the problem "has not been solved yet". In practice that means a published F1 score on HDFS tells you little about your own logs.
The vendors mostly ship the counting version, with sensible guards. Datadog's Watchdog Insights for logs aggregates detected patterns by environment, service, source and status, looks for new or spiking warning and error logs, and only treats an anomaly as severe when it contains errors, lasts at least 10 minutes and shows a significant increase. Grafana's Sift error pattern logs check pulls error lines from Loki, groups them into patterns and flags the ones whose rate rose against the period before the investigation. Neither needs a language model for that.
Can an LLM find the root cause from logs?
Sometimes, and less often than the demos suggest. The cleanest public evidence is OpenRCA, an ICLR 2025 benchmark of 335 failures from three enterprise systems with over 68 GB of logs, metrics and traces. With a purpose-built RCA agent, the best model at the time, Claude 3.5, solved 11.34% of cases. The paper is from early 2025 and models have moved on, but the shape of the result is familiar to anyone who has tried this: the model is good at reading the evidence it is given and bad at knowing which evidence matters out of 68 GB.
The failure mode has a name on every on-call rotation: the hallucinated root cause. A model reads connection reset by peer next to a deploy event and writes a fluent paragraph blaming the deploy. It might be right. It is also exactly what a tired human would guess, delivered with more confidence. The defences are boring and effective:
- give the model templates and counts, not raw lines, so it reasons over the pattern rather than one vivid message;
- require it to cite template IDs for every claim, and drop claims that cite IDs you never sent;
- ask for the next check to run, not a verdict;
- treat log text as untrusted input. User agents, URLs and usernames end up in logs, which makes logs a prompt injection channel (see my prompt injection defence guide).
The commercial agents are improving quickly on cost and speed. Datadog reported on 2 November 2026 that an average Bits Investigation fell from about $25 and 11 minutes at its December 2025 launch to about $4 and 2 minutes by October 2026, with a quality score 44% higher than its March 2026 release on Datadog's own internal benchmark. That benchmark is not public, so read the accuracy number as directional. The broader record of AI incident tooling is in my AIOps incident response review.
What does it cost to send logs to an LLM?
Logs tokenise badly. They are full of numbers, hex, paths and punctuation, which break into many short tokens. I counted with tiktoken's o200k_base encoding: the HDFS sample came out at 2.97 bytes per token and the Linux syslog sample at 2.51, well below the four-characters-per-token rule of thumb for English prose. Claude's tokenizer is different, and Anthropic's pricing page notes that Claude 4.7 and later produce about 30% more tokens for the same text, so treat my counts as a floor.
| What you send | Size | Tokens (o200k_base) | Input cost at Sonnet 5.5 ($2/MTok) | Source |
|---|---|---|---|---|
| HDFS last 500 lines, raw | 76,250 bytes | 25,509 | $0.051 | my run, Loghub HDFS_2k |
| HDFS Drain3 summary JSON | 1,835 bytes | 629 | $0.0013 | my run |
| Linux last 500 lines, raw | 49,367 bytes | 19,603 | $0.039 | my run, Loghub Linux_2k |
| Linux Drain3 summary JSON | 3,688 bytes | 1,303 | $0.0026 | my run |
| 1 GiB of HDFS-like logs, raw | 1,073,741,824 bytes | about 362 million | about $723 | 2.97 bytes/token, Anthropic pricing |
| 1 GiB, Haiku 5.5 ($0.10/MTok under 100k-token prompts) | same | about 362 million | about $36 | Anthropic pricing |
The Haiku line looks cheap until you remember that 362 million tokens is about 3,620 separate 100k-token prompts, each one a fresh context with no memory of the others. Cheap models make raw-log analysis affordable; they do not make it coherent. Templating first cuts both the bill and the noise, which is the same argument I make in FinOps for AI: the cheapest token is the one you never send.
Datadog vs Elastic vs Grafana: AI log features compared
| Vendor | Templating | Anomaly detection | LLM layer | Notes | Source |
|---|---|---|---|---|---|
| Datadog | Log patterns at intake | Watchdog: new or spiking warn/error patterns; severe if errors, 10+ minutes, significant rise | Bits Investigation, about $4 each (Datadog's October 2026 average) | Accuracy measured on an internal benchmark | Watchdog docs, Datadog blog |
| Elastic | categorize_text, pattern analysis, ML categorisation jobs (results kept 120 days by default) | Categorisation anomaly jobs; Streams significant events | Streams Knowledge Indicators, LLM plus deterministic extraction, preview since 9.4 | Needs a Generative AI connector, which "can incur additional costs" | categorisation docs, Knowledge Indicators |
| Grafana | Loki pattern ingester (Drain fork), last 3 hours only | Sift error pattern logs: patterns whose rate rose | Sift investigations in Grafana Cloud | Pattern ingester must be enabled | Patterns docs, Sift docs |
| Self-built | Drain3 0.9.11 | Your own new/rare/rate rules | Local model via Ollama, or an API on summaries only | You own the masking and the bugs | Drain3, guide |
Elastic's Knowledge Indicators design is the one I find most honest about LLM limits: indicators found by deterministic code always score 100, LLM-found ones get a 0 to 100 confidence score and must cite evidence from the sampled logs. The newer Streams product, announced in October 2025, also uses AI for parsing new formats, which is where an LLM earns its keep: writing a parser once is cheaper than reading every line forever.
Is it safe to send logs to an LLM? Privacy and secrets
Logs are where secrets go to die. Bearer tokens in debug output, email addresses in auth failures, customer IDs in URLs, the occasional full request body. My secrets sprawl post covers how often those leak through code; logs are worse because nobody reviews them. Shipping raw logs to a third-party model means extending your data processing agreement, your retention story and your breach surface to that provider.
Templating is also a privacy control. Once IPs, emails, PIDs and IDs are masked into <IP> and <EMAIL> and lines are collapsed into templates, what remains is mostly the developer's format strings, which are far less sensitive than the values. Add a second regex redaction pass for secret-shaped strings, keep one masked example per template rather than raw samples, and you can reasonably send the summary to an API, or keep everything on a laptop with a local model. Neither replaces fixing the logging itself; structured logging with PII fields kept out of the message is still the real fix.
FAQ
Can ChatGPT or Claude analyse my log files?
Yes, for a few thousand lines pasted in, and they are good at explaining unfamiliar error messages. They are not a replacement for a log pipeline: raw logs tokenise at roughly 2.5 to 3 bytes per token, so a gigabyte is hundreds of millions of tokens, and models lose the thread across that many separate prompts.
What is the best algorithm for log anomaly detection?
For most teams, Drain-style templating followed by simple rules on template counts: new templates, rare templates and rate increases against a baseline. Deep learning models can score well on benchmark datasets, but research shows those scores are sensitive to data splitting and labelling choices and transfer poorly.
How accurate is AI root cause analysis from logs?
On the public OpenRCA benchmark, the best agent in the original paper solved 11.34% of 335 failures. Vendor numbers are higher but measured on private benchmarks. Treat an LLM's root cause as a hypothesis with citations, not a finding.
Is Drain3 still maintained?
The latest PyPI release is 0.9.11 from July 2022 and the repository moved to the logpai organisation. The algorithm is stable and small enough that this is less worrying than it sounds, but pin the version and test your masking rules.
This quarter I would turn on whatever pattern view my log backend already has (Loki's pattern ingester or Elastic's pattern analysis), add one alert on "new error template in the last 15 minutes", and only then let an LLM near it, fed with template summaries and required to cite IDs. The model is the last 5% of the pipeline. The first 95% is the same platform discipline it always was: consistent log formats, masking at the source, and knowing what normal looks like.
Related: Anomaly Detection for DevOps Metrics (2026): Thresholds vs Baselines vs ML, What Is AIOps? A Plain-English Explainer for 2026 and Structured Logging Best Practices in 2026: JSON, Trace IDs, PII, Cost.
Spot an error or something out of date? Email me and I will fix it and log it on the corrections page.
I'm Ajay Kumar — I build and operate PandaStack, an open-source Firecracker microVM cloud for AI agents, and write about the infrastructure and tooling around it.
Need this kind of infrastructure work? See what I do or email hello@ajayk.sh.
Related
How to Triage Logs With Drain3 and a Local LLM (Ollama, 2026)
Build a log triage pipeline in Python: mine templates with Drain3 0.9.11, flag new and rare templates against a baseline, redact, and send a 629-token summary (not 25,509 tokens of raw logs) to a local Ollama model. Tested on Loghub HDFS and Linux samples.
15 minOct 31, 2026Anomaly Detection for DevOps Metrics (2026): Thresholds vs Baselines vs ML
Static thresholds, seasonal PromQL baselines, Datadog Watchdog, Grafana ML and Prophet compared for DevOps metrics in 2026, with the false-positive arithmetic, history each method needs, and why SLO burn-rate alerts should still do the paging.
11 minOct 31, 2026Model Drift Explained (2026): Data vs Concept Drift, PSI, KS and LLMs
Model drift explained for 2026: data drift vs concept drift vs prediction drift, how PSI, KS and Wasserstein behave at scale, why LLM quality drifts when providers retire snapshots, which tools still exist after WhyLabs and SageMaker Model Monitor, and when to retrain.
12 min