Developers insert logging statements in the source code to collect important runtime information about software systems. The textual descriptions in logging statements (i.e., logging texts) are printed during system executions and exposed to multiple stakeholders including developers, operators, users, and regulatory authorities. Writing proper logging texts is an important but often challenging task for developers. Prior studies find that developers spend significant efforts modifying their logging texts. However, despite extensive research on automated logging suggestions, research on suggesting logging texts rarely exists. To fill this knowledge gap, we first propose
LoGenText
, reported in our conference paper (Ding et al., 2022), an automated approach that uses neural machine translation models to generate logging texts by translating the related source code into short textual descriptions.
LoGenText
takes the preceding source code of a logging text as the input and considers other context information such as the location of the logging statement, to automatically generate the logging text. The
LoGenText
’s evaluation on 10 open-source projects indicates that the approach is promising for automatic logging text generation and significantly outperforms the state-of-the-art approach. Furthermore, we extend
LoGenText
to
LoGenText-Plus
by incorporating the syntactic templates of the logging texts. Different from
LoGenText
,
LoGenText-Plus
decomposes the logging text generation process into two stages.
LoGenText-Plus
first adopts a neural machine translation model to generate the syntactic template of the target logging text. Then
LoGenText-Plus
feeds the source code and the generated template as the input to another neural machine translation model for logging text generation. We also evaluate
LoGenText-Plus
on the same 10 projects and observe that it outperforms
LoGenText
on nine of them. According to a human evaluation from developers’ perspectives, the logging texts generated by
LoGenText-Plus
have a higher quality than those generated by
LoGenText
and the prior baseline approach. By manually examining the generated logging texts, we then identify five aspects that can serve as guidance for writing or generating good logging texts. Our work is an important step towards the automated generation of logging statements, which can potentially save developers’ efforts and improve the quality of software logging. Our findings shed light on research opportunities that leverage advances in neural machine translation techniques for automated generation and suggestion of logging statements.