Design log messages to be clear, concise, and properly structured to maximize their utility for debugging and monitoring. When using structured logging, configure reasonable limits for data complexity to prevent resource exhaustion and ensure logs remain usable.
Design log messages to be clear, concise, and properly structured to maximize their utility for debugging and monitoring. When using structured logging, configure reasonable limits for data complexity to prevent resource exhaustion and ensure logs remain usable.
Key practices:
Example of consolidated logging (preferred):
if (dataSourceList.size() == 1) {
logger.info("H2 console available at '{}'. Database '{}' available at '{}'",
path, dataSourceList.get(0).getName(), connectionUrl);
} else {
logger.info("H2 console available at '{}'", path);
dataSourceList.forEach(ds ->
logger.info("Database '{}' available at '{}'", ds.getName(), ds.getUrl()));
}
Instead of separate log messages:
logger.info("H2 console available at '" + path + "'.");
dataSource.orderedStream().forEachOrdered((available) -> {
try (Connection connection = available.getConnection()) {
logger.info("Database available at '" + connection.getMetaData().getURL() + "'");
}
// ...
});
Enter the URL of a public GitHub repository