com.ingenico.connect.gateway.sdk.java.logging.SysOutCommunicatorLogger Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of connect-sdk-java Show documentation
Show all versions of connect-sdk-java Show documentation
SDK to communicate with the Ingenico ePayments platform using the Ingenico Connect Server API
The newest version!
package com.ingenico.connect.gateway.sdk.java.logging;
import java.io.PrintStream;
import java.util.Date;
/**
* A communicator logger that prints its message to {@link System#out}.
* It includes a timestamp in yyyy-MM-ddTHH:mm:ss format in the system time zone.
*/
public final class SysOutCommunicatorLogger implements CommunicatorLogger {
public static final SysOutCommunicatorLogger INSTANCE = new SysOutCommunicatorLogger();
private SysOutCommunicatorLogger() {
}
@Override
public void log(String message) {
// System.out can be changed using System.setOut; make sure the same object is used for locking and printing
final PrintStream sysOut = System.out;
synchronized (sysOut) {
printMessage(sysOut, message);
}
}
@Override
public void log(String message, Throwable thrown) {
// System.out can be changed using System.setOut; make sure the same object is used for locking and printing
final PrintStream sysOut = System.out;
synchronized (sysOut) {
printMessage(sysOut, message);
if (thrown != null) {
thrown.printStackTrace(sysOut);
}
}
}
private static void printMessage(PrintStream sysOut, String message) {
sysOut.printf("%1$tY-%1$tm-%1$tdT%1$tH:%1$tM:%1$tS %2$s%n", new Date(), message);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy