🤖 AI Summary
Existing log generation approaches suffer from insufficient accuracy in determining log placement, severity level, and message content. This work proposes an end-to-end log generation method based on large language models (LLMs), introducing a reasoning mechanism into this task for the first time. By injecting structured reasoning logic and few-shot examples into the prompt, the approach guides the model to jointly decide the insertion point, severity level, and content of logs. Experimental results on 9,619 Java methods demonstrate that the proposed method achieves an accuracy of 20.55%, representing a 15.4% improvement over the current state-of-the-art, while reducing inference cost by approximately 50%.
📝 Abstract
Runtime logs are an important source of information that supports software maintenance. To obtain useful logs, developers spend significant effort identifying appropriate log locations, assigning correct severity levels, and writing concise yet informative messages. Therefore, end-to-end automated log statement generation can help reduce this burden, and prior work has proposed many methods for this task. However, existing methods still exhibit limited accuracy. To address this problem, we propose ThinkLog, an LLM-based end-to-end log statement generation method. The core idea of ThinkLog is to incorporate reasoning that helps LLMs make decisions about log insertion, severity level assignment, and message generation, thereby improving log statement generation accuracy. ThinkLog injects reasoning into prompts as few-shot examples and guides LLMs to generate appropriate log statements. Evaluated on 9,619 Java methods extracted from public GitHub repositories, ThinkLog achieves 20.55% log statement generation accuracy, representing a 15.4% improvement over the best existing method. Moreover, these improvements were achieved at approximately 50% of the inference cost (USD) compared to the best existing method. These results show that leveraging reasoning is an effective and cost-efficient way to improve the accuracy of end-to-end log statement generation.