Abstract
Software systems often record important runtime information in logs to help with troubleshooting. Log-based anomaly detection has become a key research area that aims to identify system issues through log data, ultimately enhancing the reliability of software systems. Traditional deep learning methods often struggle to capture the semantic information embedded in log data, which is typically organized in natural language. In this paper, we propose LogLLM, a log-based anomaly detection framework that leverages large language models (LLMs). LogLLM employs BERT for extracting semantic vectors from log messages, while utilizing Llama, a transformer decoder-based model, for classifying log sequences. Additionally, we introduce a projector to align the vector representation spaces of BERT and Llama, ensuring a cohesive understanding of log semantics. Unlike conventional methods that require log parsers to extract templates, LogLLM preprocesses log messages with regular expressions, streamlining the entire process. Our framework is trained through a novel three-stage procedure designed to enhance performance and adaptability. Experimental results across four public datasets demonstrate that LogLLM outperforms state-of-the-art methods. Even when handling unstable logs, it effectively captures the semantic meaning of log messages and detects anomalies accurately.
Introduction
Modern software systems generate massive volumes of console logs. Detecting anomalies within these logs is critical for system health, but it remains a "needle in a haystack" problem. Current approaches face three major challenges:
- Semantic Blindness: Traditional models (like LSTMs or CNNs) often treat logs as simple sequences of IDs, missing the rich natural language context.
- The Memory Wall: Directly feeding long sequences of raw log text into Large Language Models (LLMs) like Llama leads to "Out-of-Memory" (OOM) errors and confuses the model with irrelevant details.
- Brittle Parsing: Most methods rely on log parsers (like Drain) to extract templates. When software updates and log formats change ("unstable logs"), these parsers fail, causing the entire detection pipeline to collapse.
Methodology
Data Preparation and Preprocessing
To address the limitations of traditional parsing, LogLLM utilizes simple regular expressions to replace variables (e.g., IPs, file paths) with a constant <*> token. This preserves the semantic structure of the log message without losing information to rigid templates. Individual log messages are then grouped into sequences to provide the temporal context necessary for anomaly detection.
The LogLLM Architecture
LogLLM introduces a hybrid architecture designed to be both semantically rich and computationally efficient. It consists of three main components:
- BERT (The Summarizer): Acts as a transformer encoder to turn individual log messages into dense semantic vectors.
- The Projector: A linear layer that "translates" BERT’s vector space into a format Llama can understand.
- Llama (The Classifier): A transformer decoder that analyzes the sequence of projected vectors to determine if the system behavior is "normal" or "anomalous."
Three-Stage Training Procedure
The framework is trained through a specialized three-stage procedure to ensure alignment and performance:
- Stage 1: Fine-tune Llama to follow the "answer template" (e.g., responding with "The sequence is normal/anomalous").
- Stage 2: Train the BERT embedder and Projector to map logs to the most suitable tokens in Llama’s vocabulary.
- Stage 3: Fine-tune the entire end-to-end model using QLoRA (4-bit quantization) to keep hardware requirements manageable.
Experimental Evaluation
The model was evaluated on four public log datasets: HDFS (11.1M messages), BGL (4.7M messages), Thunderbird (10M message subset), and Liberty (5M message subset). These datasets represent a mix of stable and unstable logs with varying anomaly ratios.
Key Results
- State-of-the-Art Performance: LogLLM achieved the highest F1-score across all four datasets, outperforming previous leaders like NeuralLog and LogBERT. On average, its F1-score was 6.6% higher than the next best method.
- Precision-Recall Balance: Unlike some models (like FastLogAD) that produce many false alarms, LogLLM maintained high precision and high recall simultaneously.
- Efficiency: By using BERT to compress log messages before they hit Llama, the framework avoided the OOM errors that crashed other LLM-based competitors when handling long sequences.
- Ablation Success: The three-stage training was proven vital; skipping Stage 1 (the answer template) caused the average F1-score to drop by nearly 30%.
Discussion
The "Projector" is the core innovation of LogLLM. By aligning the vector spaces of BERT and Llama, the model can "summarize" a log message into a single embedding. This allows Llama to process much longer sequences of events without hitting token limits or memory errors. Furthermore, because LogLLM understands the semantic meaning of log messages rather than just a template ID, it is far more robust to "unstable logs" where developers might slightly change a log message's wording during a software update.
Limitations
Despite its strengths, LogLLM has limitations. Training is computationally expensive, taking over 1,000 minutes. It is also a supervised method, requiring labeled data which can be scarce. Finally, extremely imbalanced scenarios (e.g., Thunderbird with 0.15% anomalies) still pose a challenge for model stability.
Conclusion
LogLLM successfully bridges the gap between semantic understanding and computational efficiency in log-based anomaly detection. By combining BERT and Llama through an alignment projector, it achieves superior performance and robustness against unstable logs, setting a new benchmark for the field.
Summary updated