System.out / System.err In Application Code

ID

java.system_out_err_in_app_code

Severity

info

Remediation Complexity

medium

Remediation Risk

low

Remediation Effort

medium

Resource

Code Smell

Language

Java

Tags

best-practice

Description

Reports calls to System.out and System.err methods (println, print, printf, write, format, append, flush, close). Standard output/error streams are intended for console applications and quick prototypes, not production application code.

Rationale

Logging through System.out or System.err lacks log levels, timestamps, structured formatting, and configurability. In a server-side or library context, these messages cannot be routed, filtered, or monitored by operations tooling. A logging framework (e.g., SLF4J, Log4j 2, java.util.logging) provides all of these features.

// Bad - output goes to stdout with no context
System.out.println("Processing order: " + orderId);
System.err.println("Something went wrong");

Remediation

Replace System.out / System.err calls with a proper logging framework.

// Good - structured, configurable logging
private static final Logger log = LoggerFactory.getLogger(OrderService.class);

log.info("Processing order: {}", orderId);
log.error("Something went wrong", exception);