1 package atg.nucleus.logging; 2 3 import static java.lang.System.out; 4 5 /*** 6 * Simple class to get logging in unit testing working. Will print messages and 7 * {@link Throwable}'s to {@link System#out}. 8 * 9 * @author robert 10 * 11 */ 12 public class ConsoleLogListener implements LogListener { 13 14 /*** 15 * 16 */ 17 public void logEvent(final LogEvent logEvent) { 18 if (logEvent != null) { 19 20 String level = "unknown"; 21 22 if (logEvent instanceof DebugLogEvent) { 23 level = "debug"; 24 } 25 else if (logEvent instanceof ErrorLogEvent) { 26 level = "error"; 27 } 28 else if (logEvent instanceof InfoLogEvent) { 29 level = "info"; 30 } 31 else if (logEvent instanceof WarningLogEvent) { 32 level = "warning"; 33 } 34 35 out.println(String.format("**** %s\t%s\t%s\t%s\t%s", level, logEvent 36 .getDateTimeStamp(), logEvent.getTimeStamp(), logEvent 37 .getOriginator(), logEvent.getMessage())); 38 39 if (logEvent.getThrowable() != null) { 40 logEvent.getThrowable().printStackTrace(); 41 } 42 43 } 44 } 45 }