一句话:利用日志级别的序数特性与神经网络,从代码语法上下文和日志消息中为日志语句推荐合适的日志级别。
日志级别决定运行时生成哪些日志信息,但级别选高会干扰用户并增加维护开销,选低又可能遗漏关键执行信息,因此选择合适的级别十分困难。本文先手工研究日志级别的特征,发现日志语句的语法上下文与待记录消息同级别选择相关,且在序上相距较远的级别(如 trace 与 error)其特征差异更大。基于此,作者提出 DeepLV:一种利用日志级别序数性质的深度学习方法,从源码中提取日志语句的语法上下文与消息特征来给出级别建议。在九个大型开源项目上的评估表明:该方法优于当前最优基线;扩充来自其他系统的训练数据可进一步提升性能;跨系统推荐的结果甚至优于基线在系统内推荐的结果。该研究展示了自动推荐日志级别、辅助开发者做出明智日志决策的潜力。
Developers write logging statements to generate logs that provide valuable runtime information for debugging and maintenance of software systems. Log level is an important component of a logging statement, which enables developers to control the information to be generated at system runtime. However, due to the complexity of software systems and their runtime behaviors, deciding a proper log level for a logging statement is a challenging task. For example, choosing a higher level (e.g., error) for a trivial event may confuse end users and increase system maintenance overhead, while choosing a lower level (e.g., trace) for a critical event may prevent the important execution information to be conveyed opportunely. In this paper, we tackle the challenge by first conducting a preliminary manual study on the characteristics of log levels. We find that the syntactic context of the logging statement and the message to be logged might be related to the decision of log levels, and log levels that are further apart in order (e.g., trace and error) tend to have more differences in their characteristics. Based on this, we then propose a deep-learning based approach that can leverage the ordinal nature of log levels to make suggestions on choosing log levels, by using the syntactic context and message features of the logging statements extracted from the source code. Through an evaluation on nine large-scale open source projects, we find that: 1) our approach outperforms the state-of-the-art baseline approaches; 2) we can further improve the performance of our approach by enlarging the training data obtained from other systems; 3) our approach also achieves promising results on cross-system suggestions that are even better than the baseline approaches on within-system suggestions. Our study highlights the potentials in suggesting log levels to help developers make informed logging decisions.