Println In Production
ID |
kotlin.println_in_production |
Severity |
low |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Best Practice |
Language |
Kotlin |
Tags |
best-practice, leftover-debug, logging |
Description
Reports println(…) / print(…) calls left in production code. Two
shapes are flagged:
-
The top-level
kotlin.iostdlib functions (println("x"),print("x")). -
The
System.out.println(…)/System.err.println(…)family — calls whose receiver resolves tojava.io.PrintStream.
Rationale
println and print are diagnostic-only helpers. They write to standard
output/error bypassing the application’s structured logging pipeline. In a
deployed service the output cannot be filtered by log level, lacks the usual
metadata (timestamp, thread, MDC), and may be silently truncated by the
container runtime.
// Bad
fun load() {
println("loaded")
System.err.println("oops")
}
// Good
private val log = LoggerFactory.getLogger(MyService::class.java)
fun load() {
log.info("loaded")
log.error("oops")
}
Exceptions
Member-style println on a caller-supplied PrintWriter or other appender
is not flagged: passing the sink in is a deliberate routing decision.
Remediation
Use a logging facade — slf4j-api, kotlin-logging, or Android Log — and
ship structured logs through the application’s existing pipeline.