NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Exploring the Effectiveness of LLMs in Automated Logging Generation: An Empirical Study

Yichen Li, Yintong Huo, Zhihan Jiang, Renyi Zhong, Pinjia He, Yuxin Su, Michael R. LyuarXiv 2023 · DOI

Abstract

Logging is a critical yet labor-intensive task in software engineering, essential for debugging and system monitoring. This paper presents a comprehensive empirical study on the capabilities of Large Language Models (LLMs) to automate the generation of logging statements. By evaluating 11 state-of-the-art models on a novel benchmark, LogBench, we analyze their performance across three key components: logging levels, variables, and descriptive text. Our findings reveal that while LLMs significantly outperform traditional methods, they face challenges with generalization and generating human-like descriptive text.

1. Introduction

Logging statements are indispensable for maintaining software health, yet determining the appropriate severity level, identifying relevant variables, and crafting informative log messages remains a manual and error-prone process. Previous automation attempts have largely relied on retrieval-based methods or specialized learning models that predict components in isolation.

This study investigates whether the advanced reasoning and generation capabilities of modern LLMs can bridge this gap by generating complete logging statements (level, variables, and text) in a single pass. We evaluate 11 models, including general-purpose LLMs (GPT-3.5, Llama2), code-specific models (StarCoder, CodeLlama), and specialized tools (GitHub Copilot, Amazon CodeWhisperer).

2. The LogBench Benchmark

To rigorously evaluate these models, we introduced LogBench, a dataset comprising two distinct components:

  • LogBench-O (Original): Contains 3,870 methods with 6,849 logging statements extracted from high-quality Java repositories on GitHub.
  • LogBench-T (Transformed): Designed to detect data leakage and evaluate generalization. This version applies eight semantics-preserving transformations (e.g., renaming local variables or swapping condition elements) to create code that is functionally identical to the original but textually unique.

3. Methodology

Our evaluation focused on four primary research questions: the overall effectiveness of LLMs in predicting log components, their performance relative to pre-LLM state-of-the-art tools, the impact of prompt engineering (specifically the number of few-shot examples), and the influence of contextual scope (method-level vs. file-level context).

4. Key Results and Analysis

4.1 Component Performance

LLMs demonstrate varying degrees of proficiency across the three ingredients of a log statement:

  • Logging Levels: Models excel at predicting severity. GitHub Copilot, for instance, achieved an accuracy of 74.3% in identifying the correct level (e.g., INFO, WARN, ERROR).
  • Logging Variables: Identifying the correct variables to include is more complex. While models can identify relevant state information, they often deviate from developer choices, with F1 scores ranging between 0.6 and 0.7.
  • Logging Text: Generating descriptive, human-like log messages remains the most significant challenge. The highest-performing model in this category, Amazon CodeWhisperer, achieved a BLEU-4 score of only 0.249, indicating a substantial gap between model output and ground-truth developer messages.

4.2 The Role of Context and Prompting

Our study highlights the critical importance of context. Providing the entire file as context rather than just the target method resulted in performance gains of up to 49% in BLEU scores. This suggests that LLMs leverage file-level information to learn project-specific logging conventions and variable definitions.

Regarding In-Context Learning (ICL), we observed a "distraction threshold." While providing examples improves performance, the benefit typically peaks at 5–7 examples. Beyond this point, models suffer from "model distraction," where the excessive input length hinders the model's ability to focus on the target code's logic.

4.3 Generalization and Data Leakage

A significant finding is the performance drop on LogBench-T. Models experienced a decline of 8.2% to 16.2% when faced with transformed code. This suggests that current LLMs rely heavily on pattern matching and memorization of training data rather than a deep logical understanding of logging requirements.

5. Discussion and Future Work

While LLMs have established a new baseline for automated logging, several limitations remain. Standard NLP metrics like BLEU and ROUGE may not fully capture the utility of a log statement, as a semantically useful log might differ textually from the ground truth.

Future research should focus on:

  • Unified Metrics: Developing evaluation frameworks that prioritize the semantic and diagnostic value of logs.
  • Reasoning Enhancements: Utilizing Chain-of-Thought (CoT) prompting to encourage models to analyze code logic before generating logs.
  • Example Selection: Moving beyond random few-shot selection toward strategies that identify the most structurally similar and informative examples for a given code snippet.

6. Conclusion

LLMs represent a significant leap forward in automated logging, outperforming previous specialized models even without fine-tuning. However, the "generalization gap" and the difficulty of generating high-quality descriptive text indicate that further refinement in context handling and reasoning is required before these models can fully automate the logging process.

Summary updated

BibTeX
@misc{li2023exploring,
  author = {Yichen Li and Yintong Huo and Zhihan Jiang and Renyi Zhong and Pinjia He and Yuxin Su and Michael R. Lyu},
  title = {{Exploring the Effectiveness of LLMs in Automated Logging Generation: An Empirical Study}},
  year = {2023},
  eprint = {2307.05950},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2307.05950},
}
Figure