diff --git a/pom.xml b/pom.xml index 1fa126c..5516d5f 100644 --- a/pom.xml +++ b/pom.xml @@ -24,7 +24,7 @@ - 1.1.3 + 1.1.4 UTF-8 1.8 5.0.0-M4 @@ -103,6 +103,13 @@ test + + + log4j + log4j + 1.2.17 + + diff --git a/src/main/java/com/wildbit/java/postmark/Postmark.java b/src/main/java/com/wildbit/java/postmark/Postmark.java index 5035fc6..78ef9e7 100644 --- a/src/main/java/com/wildbit/java/postmark/Postmark.java +++ b/src/main/java/com/wildbit/java/postmark/Postmark.java @@ -2,9 +2,9 @@ import com.wildbit.java.postmark.client.AccountApiClient; import com.wildbit.java.postmark.client.ApiClient; +import org.apache.log4j.Logger; import javax.ws.rs.core.MultivaluedHashMap; -import java.io.IOException; import java.io.InputStream; import java.util.Properties; @@ -47,8 +47,10 @@ public static String libraryVersion() { Properties prop = new Properties(); InputStream in = Postmark.class.getClassLoader().getResourceAsStream(".properties"); - try { prop.load(in); } catch (IOException e) { - e.printStackTrace(); + try { + prop.load(in); + } catch (Exception e) { + log.warn(e.toString()); } return prop.getProperty("Version"); } @@ -75,6 +77,8 @@ public static AccountApiClient getAccountApiClient(String apiToken, Boolean secu private Postmark() {} + private static Logger log = Logger.getLogger(Postmark.class); + private static MultivaluedHashMap getHeadersWithAuth(DEFAULTS authType, String apiToken) { MultivaluedHashMap headers = DefaultHeaders.headers(); headers.add(authType.value, apiToken); diff --git a/src/main/java/com/wildbit/java/postmark/client/HttpClientHandler.java b/src/main/java/com/wildbit/java/postmark/client/HttpClientHandler.java index 7ddb1be..ca10eb8 100644 --- a/src/main/java/com/wildbit/java/postmark/client/HttpClientHandler.java +++ b/src/main/java/com/wildbit/java/postmark/client/HttpClientHandler.java @@ -2,6 +2,8 @@ import com.wildbit.java.postmark.client.data.DataHandler; import com.wildbit.java.postmark.client.exception.*; +import org.apache.log4j.Level; +import org.apache.log4j.spi.RootLogger; import javax.ws.rs.core.MultivaluedHashMap; import java.io.IOException; @@ -64,12 +66,22 @@ protected String execute(HttpClient.REQUEST_TYPES request_type, String url, Obje /** * Main source of issues can be the Object serialization process. To debug it, this method will set strict mapping, which - * will fail on any issues. + * will fail on any issues. Also by choosing debug mode, logging will be set to DEBUG level */ public void setDebugMode() { + setLoggingLevel(Level.DEBUG); this.dataHandler.setStrictMapper(); } + /** + * Custom level of logging can be set. + * + * @param level - debugging level - OFF, DEBUG, ERROR etc. + */ + public void setLoggingLevel(Level level) { + RootLogger.getRootLogger().setLevel(level); + } + public void setSecureConnection(boolean secureConnection) { this.secureConnection = secureConnection; } diff --git a/src/main/resources/log4j.properties b/src/main/resources/log4j.properties index e4fcb01..014e782 100644 --- a/src/main/resources/log4j.properties +++ b/src/main/resources/log4j.properties @@ -1,5 +1,5 @@ # Set root logger level to DEBUG and its only appender to A1. -log4j.rootLogger=DEBUG, A1 +log4j.rootLogger=OFF, A1 # A1 is set to be a ConsoleAppender. log4j.appender.A1=org.apache.log4j.ConsoleAppender