NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Studying Duplicate Logging Statements and Their Relationships with Code Clones

Zhenhao Li, Tse-Hsun Chen, Jinqiu Yang, Weiyi Shang · DOI

Abstract

In this paper, we focus on studying duplicate logging statements, which are logging statements that have the same static text message. We manually studied over 4K duplicate logging statements and their surrounding code in five large-scale open source systems. We uncovered five patterns of duplicate logging code smells. For each instance of the duplicate logging code smell, we further manually identify the potentially problematic and justifiable cases. Then, we contact developers to verify our manual study result. We integrated our manual study result and the feedback of developers into our automated static analysis tool, DLFinder, which automatically detects problematic duplicate logging code smells. We evaluated DLFinder on the five manually studied systems and three additional systems. In total, combining the results of DLFinder and our manual analysis, we reported 91 problematic duplicate logging code smell instances to developers and all of them have been fixed. We further study the relationship between duplicate logging statements, including the problematic instances of duplicate logging code smells, and code clones. We find that 83% of the duplicate logging code smell instances reside in cloned code, but 17% of them reside in micro-clones that are difficult to detect using automated clone detection tools. Our study shows that, in addition to general source code that implements the business logic, code clones may also result in bad logging practices that could increase maintenance difficulties.

Introduction

Software logs are the "black box" of system execution, essential for debugging and performance analysis. However, there is no industry standard for writing them. A common but overlooked issue is the duplicate logging statement: two or more lines of code that produce the identical static message (e.g., two different catch blocks both logging "Connection lost"). When an error occurs, these identical messages make it impossible for developers to distinguish which specific failure path was taken without looking at a stack trace—which isn't always logged. This paper argues that these duplicates are often "surface indications" of deeper code smells, frequently caused by hasty copy-pasting (code cloning) without updating the log metadata.

Methodology

The researchers employed a multi-phase approach to study this phenomenon. They first conducted a manual study of over 4,000 duplicate logging statements across five large-scale Java systems (Cassandra, CloudStack, Elasticsearch, Flink, and Hadoop). Based on this, they categorized duplicates into five distinct "code smell" patterns and distinguished between problematic and justifiable cases.

Overview of the study workflow, from manual analysis to tool development and evaluation.

Following the manual study, the team developed DLFinder, an automated static analysis tool that uses Abstract Syntax Tree (AST) analysis and data flow analysis to detect these patterns. Finally, they used the NiCad clone detection tool to investigate the relationship between these logging issues and code clones.

Taxonomy of Duplicate Logging Code Smells

The study identified five specific patterns of bad duplicate logging:

  • IC (Inadequate Information in Catch blocks): Identical logs in different catch blocks of the same try block, providing no way to tell which exception occurred.
  • IE (Inconsistent Error-diagnostic Info): Similar catch blocks where one logs a stack trace and the other doesn't.
  • LM (Log Message Mismatch): A copy-paste error where the log message contains the name of the old method it was copied from.
  • IL (Inconsistent Log Level): Identical messages logged at different levels (e.g., one INFO, one ERROR) in similar code structures without a clear reason.
  • DP (Duplicate Logs in Polymorphism): Subclasses implementing an interface but using the exact same log message as the parent, making it hard to tell which subclass is executing.
Examples of the five duplicate logging code smell patterns: IC, IE, LM, IL, and DP.

Key Results and Insights

Real-World Impact

The study evaluated eight high-profile open-source Java systems, including Camel, Kafka, and Wicket in addition to the initial five. The authors reported 91 problematic instances to developers, and 100% of them were accepted and fixed, demonstrating the practical relevance of this research.

The "Micro-Clone" Problem

While 83% of problematic logs reside in cloned code, 17% are found in "micro-clones" (very short code blocks). Standard clone detection tools often miss these because they are tuned for larger blocks of logic, yet these tiny snippets are exactly where logging bugs hide. Furthermore, the study found that removing duplicate logs actually makes it harder for standard tools to detect code clones, suggesting that identical logs often act as the "glue" that helps tools identify copied code.

Logging as Technical Debt

Developers often view duplicate logs in polymorphic classes (DP) as technical debt. They acknowledge the issue but are reluctant to fix it because current logging frameworks (like SLF4J) do not easily support "log templates" that could be reused across subclasses. This suggests a need for improved framework support to reduce manual duplication.

Conclusion

Duplicate logging statements are a significant form of technical debt that complicates system maintenance and debugging. By correlating these smells with code clones, this study highlights how bad practices in business logic replication can propagate into logging. Future work should focus on improving logging frameworks to support "DRY" (Don't Repeat Yourself) principles and dynamic analysis to identify runtime duplications.

Summary updated

BibTeX
@article{li2021studying,
  author = {Zhenhao Li and Tse-Hsun Chen and Jinqiu Yang and Weiyi Shang},
  title = {{Studying Duplicate Logging Statements and Their Relationships with Code Clones}},
  journal = {IEEE Transactions on Software Engineering},
  year = {2021},
  doi = {10.1109/tse.2021.3060918},
}
Figure