[Paper Review] Exploring the Effectiveness of LLMs in Automated Logging Generation: An Empirical Study
This paper presents the first comprehensive empirical study on using large language models (LLMs) for automated logging statement generation. It introduces LogBench, a dataset of 3,870 methods and 6,849 logging statements, and evaluates eight SOTA LLMs across effectiveness and generalization. The study reveals that current LLMs fall short in generating accurate, context-aware logging statements and struggle with unseen code, highlighting limitations in both model capabilities and generalization.
Automated logging statement generation supports developers in documenting critical software runtime behavior. Given the great success in natural language generation and programming language comprehension, large language models (LLMs) might help developers generate logging statements, but this has not yet been investigated. To fill the gap, this paper performs the first study on exploring LLMs for logging statement generation.We first build a logging statement generation dataset, LogBench, with two parts: (1) LogBench-O: logging statements collected from GitHub repositories, and (2) LogBench-T: the transformed unseen code from LogBench-O. Then, we leverage LogBench to evaluate the effectiveness and generalization capabilities (using LogBench-T) of eleven top-performing LLMs. In addition, we examine the performance of these LLMs against classical retrieval-based and machine learning-based logging methods from the era preceding LLMs. We further evaluate LLM's logging generalization capabilities using unseen data (LogBench-T) derived from code transformation techniques. While existing LLMs deliver decent predictions on logging levels and logging variables, our study indicates that they only achieve a maximum BLEU score of 0.249, thus calling for improvements. The paper also highlights the importance of prompt constructions and external factors (e.g., programming contexts and code comments) for LLMs' logging performance. Based on these findings, we identify five implications and provide practical advice for future logging research. Our empirical analysis discloses the limitations of current logging approaches while showcasing the potential of LLM-based logging tools, and provides actionable guidance for building more practical models.
Motivation & Objective
- To investigate the effectiveness of state-of-the-art LLMs in generating complete, contextually appropriate logging statements with multiple ingredients (level, variables, text).
- To analyze the impact of internal LLM characteristics—such as model size and pre-training on code—on logging performance.
- To evaluate the influence of external factors, including code context and comments, on LLM-generated logging quality.
- To assess the generalization capability of LLMs using transformed code not seen during training, to detect potential data leakage or memorization.
- To provide actionable insights for improving future LLM-based logging tools through unified metrics, shared code knowledge, and optimized prompting.
Proposed method
- Constructed LogBench, a new benchmark dataset containing 3,870 Java methods and 6,849 manually curated logging statements, with diverse logging ingredients.
- Evaluated eight SOTA LLMs—ranging from 60M to 175B parameters—on their ability to generate complete logging statements from code snippets.
- Designed a code transformation pipeline to create LogBench-O, a test set of unseen code with structural and syntactic variations to assess generalization.
- Measured logging effectiveness using automatic metrics (e.g., BLEU, ROUGE) and human evaluation for quality and relevance.
- Analyzed the impact of model-specific features (e.g., code pre-training) and external context (e.g., surrounding code, comments) on output quality.
- Conducted ablation studies to isolate the contribution of each factor to logging performance.
Experimental results
Research questions
- RQ1To what extent can current LLMs generate accurate and contextually appropriate logging statements with all three ingredients (level, variables, text)?
- RQ2How do internal LLM characteristics—such as model size and code pre-training—impact logging effectiveness?
- RQ3How do external factors like code context and comments influence the quality of LLM-generated logging statements?
- RQ4Can LLMs generalize to unseen code structures after training on public code repositories, or do they rely on memorization?
- RQ5What are the key limitations and opportunities for improving LLM-based logging generation in practice?
Key findings
- Existing LLMs fail to meet practical requirements for logging statement generation, producing inaccurate or semantically inappropriate logs despite strong natural language generation capabilities.
- Model size and pre-training on code significantly improve logging effectiveness, with code-specific models outperforming general-purpose LLMs.
- External context, especially surrounding code and comments, substantially enhances the relevance and correctness of generated logging statements.
- LLMs show poor generalization to transformed code, indicating limited robustness and potential memorization of training data rather than true understanding.
- The performance gap between seen and unseen code highlights the risk of data leakage and the need for more rigorous evaluation protocols.
- The study identifies three key implications: developing unified logging quality metrics, integrating shared code knowledge into LLMs, and designing effective prompting strategies for logging tasks.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.