The logging module replaces fragile console output with a controlled way to route useful records toward persistent, aggregated, or monitored destinations. It supports filtering, formatting, destinations, and severity levels, making diagnostic information more useful across development and production environments. section 7.2.3
Good logging communicates what happened and where. Messages such as “An error occurred” or “Execution failed” add little investigative value; include the relevant operation, input, and exception instead. section 7.2.3
try {
int parsedNumber = Integer.parseInt(data);
} catch (NumberFormatException exception) {
exception.printStackTrace(); #1
System.out.println("Big problem!"); #2
System.err.println("Big problem!"); #3
}
Console printing and stack traces expose failures only at the terminal, limiting persistence, aggregation, and monitoring. section 7.2.3
logger.error("Error while parsing date '{}'", rawDate, exception);
A useful error message names the failed operation, preserves the relevant value, and records the exception for investigation. section 7.2.3



