Skip to main content
QUICK REVIEW

[论文解读] Exploring the Effectiveness of LLMs in Automated Logging Generation: An Empirical Study

Yichen Li, Yintong Huo|arXiv (Cornell University)|Jul 12, 2023
Advanced Manufacturing and Logistics Optimization被引用 7
一句话总结

本文首次对使用大语言模型(LLMs)进行自动化日志语句生成进行了全面的实证研究。研究提出了 LogBench 数据集,包含 3,870 个方法和 6,849 条手工标注的日志语句,并对八种当前最先进的 LLM 进行了有效性与泛化能力的评估。研究发现,当前 LLM 在生成准确、上下文感知的日志语句方面表现不足,且在面对未见过的代码时表现困难,揭示了模型能力与泛化能力的局限性。

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.

研究动机与目标

  • 调查当前最先进的 LLM 在生成完整、上下文恰当的日志语句(包含级别、变量、文本三个要素)方面的有效性。
  • 分析 LLM 内部特性(如模型规模和代码预训练)对日志生成性能的影响。
  • 评估外部因素(如代码上下文和注释)对 LLM 生成日志质量的影响。
  • 通过使用训练期间未见过的变换后代码,评估 LLM 的泛化能力,以检测潜在的数据泄露或记忆化现象。
  • 通过统一的评估指标、共享的代码知识和优化的提示工程,为改进未来基于 LLM 的日志生成工具提供可操作的见解。

提出的方法

  • 构建了 LogBench,一个全新的基准数据集,包含 3,870 个 Java 方法和 6,849 条手工精心标注的日志语句,涵盖多样的日志要素。
  • 评估了八种当前最先进的 LLM(参数规模从 60M 到 175B 不等)从代码片段生成完整日志语句的能力。
  • 设计了一套代码变换流水线,生成 LogBench-O,一个包含结构与语法变化的未见代码测试集,用于评估泛化能力。
  • 通过自动指标(如 BLEU、ROUGE)和人工评估相结合的方式,衡量日志的有效性。
  • 分析了模型特定特征(如代码预训练)和外部上下文(如周围代码、注释)对输出质量的影响。
  • 开展了消融研究,以分离各因素对日志生成性能的独立贡献。

实验结果

研究问题

  • RQ1当前 LLM 在生成包含全部三个要素(级别、变量、文本)的准确且上下文恰当的日志语句方面,能达到何种程度?
  • RQ2模型规模和代码预训练等内部 LLM 特性如何影响日志生成的有效性?
  • RQ3代码上下文和注释等外部因素如何影响 LLM 生成日志的质量?
  • RQ4LLM 在公开代码仓库上训练后,能否泛化到未见过的代码结构,还是依赖于记忆化而非真正理解?
  • RQ5在实际应用中,基于 LLM 的日志生成存在哪些关键局限与改进机会?

主要发现

  • 现有 LLM 尽管具备强大的自然语言生成能力,但在实际日志生成任务中仍无法满足需求,常生成不准确或语义不恰当的日志。
  • 模型规模和代码预训练显著提升了日志生成的有效性,专用代码模型的表现优于通用 LLM。
  • 外部上下文,尤其是周围代码和注释,显著提升了生成日志的相关性与正确性。
  • LLM 在处理变换后的代码时泛化能力极差,表明其鲁棒性有限,可能存在对训练数据的记忆化而非真正理解。
  • 在可见与不可见代码之间性能差距显著,凸显了数据泄露的风险,也凸显了需要更严格的评估协议。
  • 本研究识别出三个关键启示:开发统一的日志质量评估指标、将共享代码知识整合进 LLM、设计针对日志任务的有效提示策略。

更好的研究,从现在开始

从阅读论文到最终审阅,大幅缩短您的研究时间。

无需绑定信用卡

本解读由 AI 生成,并经人工编辑审核。