Skip to content

Commit

Permalink
disable logging by default, allow users to customize it
Browse files Browse the repository at this point in the history
  • Loading branch information
ibalosh committed May 29, 2018
1 parent f336eff commit 571ce38
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
9 changes: 8 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</developers>

<properties>
<postmark.version>1.1.3</postmark.version>
<postmark.version>1.1.4</postmark.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<junit.jupiter.version>5.0.0-M4</junit.jupiter.version>
Expand Down Expand Up @@ -103,6 +103,13 @@
<scope>test</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/log4j/log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>

</dependencies>

<!-- all of the below is needed for releasing -->
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/com/wildbit/java/postmark/Postmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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");
}
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/log4j.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 571ce38

Please sign in to comment.