Table of Contents
Fetching ...

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

Yichen Li, Yintong Huo, Zhihan Jiang, Renyi Zhong, Pinjia He, Yuxin Su, Lionel Briand, Michael R. Lyu

TL;DR

This paper presents the first large-scale empirical study of large language models for automated logging statement generation. It introduces LogBench-O and LogBench-T to evaluate both effectiveness and generalization of eleven top-performing LLMs across logging ingredients and logging texts, comparing them against conventional logging approaches. The study demonstrates that while LLMs often outperform traditional baselines, they struggle with generating high-quality logging texts and generalizing to unseen transformed code, with prompts and contextual information significantly shaping performance. The findings offer actionable guidance on prompt design, use of program context, and the potential of chain-of-thought and few-shot strategies to enhance practical logging tools, supported by publicly available datasets and code.

Abstract

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.

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

TL;DR

This paper presents the first large-scale empirical study of large language models for automated logging statement generation. It introduces LogBench-O and LogBench-T to evaluate both effectiveness and generalization of eleven top-performing LLMs across logging ingredients and logging texts, comparing them against conventional logging approaches. The study demonstrates that while LLMs often outperform traditional baselines, they struggle with generating high-quality logging texts and generalizing to unseen transformed code, with prompts and contextual information significantly shaping performance. The findings offer actionable guidance on prompt design, use of program context, and the potential of chain-of-thought and few-shot strategies to enhance practical logging tools, supported by publicly available datasets and code.

Abstract

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.
Paper Structure (32 sections, 11 figures, 9 tables)

This paper contains 32 sections, 11 figures, 9 tables.

Figures (11)

  • Figure 1: Task formulation: given a method and a specific logging point, the model is asked to predict the logging statement in the point.
  • Figure 2: The overall framework of this study involving five research questions.
  • Figure 3: An example of how the code (constant) transformer works. The constant checker firstly detects transformation points, then the Local variable transformer replaces the constant expression {inMb=1024*1024} by {const_1=1024*1024; inMb=const_1} involving a new variable const_1. The AST changes via transformation are highlighted in red area.
  • Figure 4: Comparison between traditional logging models and LLM-powered models.
  • Figure 5: Venn diagram for logging levels prediction.
  • ...and 6 more figures