I have a project which should print the result on the screen in the console and also to the file. I use spring boot with logback. I can print the result as a table on screen but not as a good format in the log file with logback. Any ideas and suggestions are welcome.
see the output result below.
+------------------+---------------+---------------+--------------+---------------+---------------+--------------+--------------+
| %-16s | %-13s | %-13s | %-12s | %-13s | %-13s | %-12s | %-12s |%n
+------------------+---------------+---------------+--------------+---------------+---------------+--------------+--------------+
| %-16s | %-13s | %-13s | %-12s | %-13s | %-13s | %-12s | %-12s |%n
| %-16s | %-13s | %-13s | %-12s | %-13s | %-13s | %-12s | %-12s |%n
| %-16s | %-13s | %-13s | %-12s | %-13s | %-13s | %-12s | %-12s |%n
| %-16s | %-13s | %-13s | %-12s | %-13s | %-13s | %-12s | %-12s |%n
| %-16s | %-13s | %-13s | %-12s | %-13s | %-13s | %-12s | %-12s |%n
| %-16s | %-13s | %-13s | %-12s | %-13s | %-13s | %-12s | %-12s |%n
+------------------+---------------+---------------+--------------+---------------+---------------+--------------+--------------+
Method for printing:
public static void printListAsTable(List<ResultControl> resultcontrolList) {
String format = "| %-16s | %-13s | %-13s | %-12s | %-13s | %-13s | %-12s | %-12s |%n";
log("+------------------+---------------+---------------+--------------+---------------+---------------+--------------+--------------+");
log(format,"Id", "Net", "Mat", "Dat", "Apo", "Nato", "Nano", "Pico");
log("+------------------+---------------+---------------+--------------+---------------+---------------+--------------+--------------+");
for (ResultControl result :resultcontrolList ) {
log(format, result.getId(), result.getNet , result.getMat , result.getDat , result.getApo , result.getNato , result.getNano , result.getPico );
}
log("+------------------+---------------+---------------+--------------+---------------+---------------+--------------+--------------+");
}
public static void log(String format, Object... args) {
System.out.printf(format, args);
logger.info( format, args);
}