Skip to content

Commit

Permalink
Merge pull request #302 from lightblue-platform/logging
Browse files Browse the repository at this point in the history
Renaming inconsistency loggers
  • Loading branch information
bserdar committed Feb 5, 2016
2 parents 5e00bc1 + a8d1e94 commit cdd07b2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
public class ConsistencyChecker {

// using non-static slf4j loggers for easy unit testing
private Logger log = LoggerFactory.getLogger(this.getClass());
private Logger inconsistencyLog = LoggerFactory.getLogger("Inconsistency");
private Logger inconsistencyLog = LoggerFactory.getLogger(this.getClass());
private Logger hugeInconsistencyLog = LoggerFactory.getLogger(this.getClass()+"Huge");

private final String implementationName;
protected int maxInconsistencyLogLength = 65536; // 64KB
Expand Down Expand Up @@ -79,22 +79,22 @@ private void logInconsistency(String callToLogInCaseOfInconsistency, String lega
String logMessage = String.format("Inconsistency found in %s.%s - diff: %s - legacyJson: %s, lightblueJson: %s", implementationName, callToLogInCaseOfInconsistency, diff, legacyJson, lightblueJson);
if (logResponseDataEnabled) {
if (logMessage.length()<=maxInconsistencyLogLength) {
log.warn(logMessage);
inconsistencyLog.warn(logMessage);
} else if (diff!=null&&diff.length()<=maxInconsistencyLogLength) {
log.warn(String.format("Inconsistency found in %s.%s - diff: %s", implementationName, callToLogInCaseOfInconsistency, diff));
inconsistencyLog.debug(logMessage);
inconsistencyLog.warn(String.format("Inconsistency found in %s.%s - diff: %s", implementationName, callToLogInCaseOfInconsistency, diff));
hugeInconsistencyLog.debug(logMessage);
} else {
log.warn(String.format("Inconsistency found in %s.%s - payload and diff is greater than %d bytes!", implementationName, callToLogInCaseOfInconsistency, maxInconsistencyLogLength));
inconsistencyLog.debug(logMessage);
inconsistencyLog.warn(String.format("Inconsistency found in %s.%s - payload and diff is greater than %d bytes!", implementationName, callToLogInCaseOfInconsistency, maxInconsistencyLogLength));
hugeInconsistencyLog.debug(logMessage);
}
} else {
if (diff!=null&&diff.length()<=maxInconsistencyLogLength) {
log.warn(String.format("Inconsistency found in %s.%s - diff: %s", implementationName, callToLogInCaseOfInconsistency, diff));
inconsistencyLog.warn(String.format("Inconsistency found in %s.%s - diff: %s", implementationName, callToLogInCaseOfInconsistency, diff));
} else {
log.warn(String.format("Inconsistency found in %s.%s - diff is greater than %d bytes!", implementationName, callToLogInCaseOfInconsistency, maxInconsistencyLogLength));
inconsistencyLog.warn(String.format("Inconsistency found in %s.%s - diff is greater than %d bytes!", implementationName, callToLogInCaseOfInconsistency, maxInconsistencyLogLength));
}
// logData is turned off, log in inconsistency.log for debugging
inconsistencyLog.debug(logMessage);
hugeInconsistencyLog.debug(logMessage);
}
}

Expand Down Expand Up @@ -131,9 +131,9 @@ protected boolean checkConsistency(final Object legacyEntity, final Object light
JSONCompareResult result = JSONCompare.compareJSON(legacyJson, lightblueJson, JSONCompareMode.LENIENT);
long t2 = System.currentTimeMillis();

if (log.isDebugEnabled()) {
log.debug("Consistency check took: " + (t2-t1)+" ms");
log.debug("Consistency check passed: "+ result.passed());
if (inconsistencyLog.isDebugEnabled()) {
inconsistencyLog.debug("Consistency check took: " + (t2-t1)+" ms");
inconsistencyLog.debug("Consistency check passed: "+ result.passed());
}
if (!result.passed()) {
logInconsistency(callToLogInCaseOfInconsistency.toString(), legacyJson, lightblueJson, result.getMessage().replaceAll("\n", ","));
Expand All @@ -146,7 +146,7 @@ protected boolean checkConsistency(final Object legacyEntity, final Object light
logInconsistency(callToLogInCaseOfInconsistency.toString(), legacyJson, lightblueJson, null);
}
} catch (JsonProcessingException e) {
log.error("Consistency check failed in "+implementationName+"."+callToLogInCaseOfInconsistency+"! Invalid JSON: legacyJson="+legacyJson+", lightblueJson="+lightblueJson, e);
inconsistencyLog.error("Consistency check failed in "+implementationName+"."+callToLogInCaseOfInconsistency+"! Invalid JSON: legacyJson="+legacyJson+", lightblueJson="+lightblueJson, e);
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
public class ConsistencyLoggerTest {

@Mock
private Logger log;
private Logger inconsitencyLog;

@Mock
private Logger inconsistencyLog;
private Logger hugeInconsistencyLog;

@InjectMocks
private ConsistencyChecker consistencyChecker = new ConsistencyChecker(CountryDAO.class.getSimpleName());
Expand Down Expand Up @@ -72,9 +72,9 @@ public void logTest_logResponsesEnabled_logLessThanLogLimit() throws Exception {
List<String> lightblue = getDummyMessage("Test", 12);
boolean result = consistencyChecker.checkConsistency(legacy, lightblue, "testMethod", new LazyMethodCallStringifier("testMethod(param1, param2)"));
assertFalse(result);
verify(log).warn(logStmt.capture());
verify(inconsitencyLog).warn(logStmt.capture());
assertEquals("Inconsistency found in CountryDAO.testMethod(param1, param2) - diff: []: Expected 2 values but got 1 - legacyJson: [\"Test10000\",\"Test10001\"], lightblueJson: [\"Test10000\"]", logStmt.getValue());
verify(inconsistencyLog, never()).debug(anyString());
verify(hugeInconsistencyLog, never()).debug(anyString());
}

@Test
Expand All @@ -90,9 +90,9 @@ public void logTest_logResponsesEnabled_logGreaterThanLogLimit() throws Exceptio
List<String> lightblue = getDummyMessage("Test", 24);
boolean result = consistencyChecker.checkConsistency(legacy, lightblue, "testMethod", new LazyMethodCallStringifier("testMethod(param1, param2)"));
assertFalse(result);
verify(log).warn(logStmt.capture());
verify(inconsitencyLog).warn(logStmt.capture());
assertEquals("Inconsistency found in CountryDAO.testMethod(param1, param2) - diff: []: Expected 3 values but got 2", logStmt.getValue());
verify(inconsistencyLog).debug(inconsistencyLogStmt.capture());
verify(hugeInconsistencyLog).debug(inconsistencyLogStmt.capture());
assertEquals("Inconsistency found in CountryDAO.testMethod(param1, param2) - diff: []: Expected 3 values but got 2 - legacyJson: [\"Test10000\",\"Test10001\",\"Test10002\"], lightblueJson: [\"Test10000\",\"Test10001\"]", inconsistencyLogStmt.getValue());
}

Expand All @@ -109,9 +109,9 @@ public void logTest_logResponsesEnabled_diffGreaterThanLogLimit() throws Excepti
List<String> lightblue = getDummyMessage("Fooo", 40);
boolean result = consistencyChecker.checkConsistency(legacy, lightblue, "testMethod", new LazyMethodCallStringifier("testMethod(param1, param2)"));
assertFalse(result);
verify(log).warn(logStmt.capture());
verify(inconsitencyLog).warn(logStmt.capture());
assertEquals("Inconsistency found in CountryDAO.testMethod(param1, param2) - payload and diff is greater than 175 bytes!", logStmt.getValue());
verify(inconsistencyLog).debug(inconsistencyLogStmt.capture());
verify(hugeInconsistencyLog).debug(inconsistencyLogStmt.capture());
assertTrue(inconsistencyLogStmt.getValue().contains("diff"));
assertTrue(inconsistencyLogStmt.getValue().contains("legacyJson"));
assertTrue(inconsistencyLogStmt.getValue().contains("lightblueJson"));
Expand All @@ -130,9 +130,9 @@ public void logTest_logResponsesDisabled_logLessThanLogLimit() throws Exception
List<String> lightblue = getDummyMessage("Test", 12);
boolean result = consistencyChecker.checkConsistency(legacy, lightblue, "testMethod", new LazyMethodCallStringifier("testMethod(param1, param2)"));
assertFalse(result);
verify(log).warn(logStmt.capture());
verify(inconsitencyLog).warn(logStmt.capture());
assertEquals("Inconsistency found in CountryDAO.testMethod(param1, param2) - diff: []: Expected 2 values but got 1", logStmt.getValue());
verify(inconsistencyLog).debug(inconsistencyLogStmt.capture());
verify(hugeInconsistencyLog).debug(inconsistencyLogStmt.capture());
assertEquals("Inconsistency found in CountryDAO.testMethod(param1, param2) - diff: []: Expected 2 values but got 1 - legacyJson: [\"Test10000\",\"Test10001\"], lightblueJson: [\"Test10000\"]", inconsistencyLogStmt.getValue());
}

Expand All @@ -149,9 +149,9 @@ public void logTest_logResponsesDisabled_diffGreaterThanLogLimit() throws Except
List<String> lightblue = getDummyMessage("Fooo", 40);
boolean result = consistencyChecker.checkConsistency(legacy, lightblue, "testMethod", new LazyMethodCallStringifier("testMethod(param1, param2)"));
assertFalse(result);
verify(log).warn(logStmt.capture());
verify(inconsitencyLog).warn(logStmt.capture());
assertEquals("Inconsistency found in CountryDAO.testMethod(param1, param2) - diff is greater than 175 bytes!", logStmt.getValue());
verify(inconsistencyLog).debug(inconsistencyLogStmt.capture());
verify(hugeInconsistencyLog).debug(inconsistencyLogStmt.capture());
assertTrue(inconsistencyLogStmt.getValue().contains("diff"));
assertTrue(inconsistencyLogStmt.getValue().contains("legacyJson"));
assertTrue(inconsistencyLogStmt.getValue().contains("lightblueJson"));
Expand Down

0 comments on commit cdd07b2

Please sign in to comment.