@Test(dataProvider = "allCombinationShouldWeCapture") public void checkForCorrectLogging(Level givenMinimumLevel, Level logThisLevel, Boolean shouldCapture) { Log4JLoggingHook hook = new Log4JLoggingHook(platformManager, givenMinimumLevel.toString()); long methodId = 1l; long sensorTypeId = 3l; long platformId = 9l; when(platformManager.getPlatformId()).thenReturn(platformId); String loggingMessage = "a logging message"; Object[] params = new Object[4]; params[0] = "fqcn"; params[1] = logThisLevel; params[2] = loggingMessage; params[3] = null; hook.secondAfterBody(coreService, methodId, sensorTypeId, null, params, null, false, rsc); LoggingData loggingData = new LoggingData(logThisLevel.toString(), loggingMessage); loggingData.setMethodIdent(methodId); loggingData.setSensorTypeIdent(sensorTypeId); loggingData.setPlatformIdent(platformId); if (shouldCapture) { verify(coreService).addDefaultData(argThat(new LoggingDataVerifier(loggingData))); } else { verify(coreService, never()).addDefaultData(Mockito.<DefaultData> any()); } }
@Override public void secondAfterBody(ICoreService coreService, long methodId, long sensorTypeId, Object object, Object[] parameters, Object result, boolean exception, RegisteredSensorConfig rsc) { if (checker.isValid()) { String level = String.valueOf(parameters[1]); if (!checker.shouldCapture(level)) { return; } long platformId = platformManager.getPlatformId(); LoggingData data = new LoggingData(); data.setLevel(level); data.setMessage(String.valueOf(parameters[2])); data.setPlatformIdent(platformId); data.setSensorTypeIdent(sensorTypeId); data.setMethodIdent(methodId); data.setTimeStamp(new Timestamp(System.currentTimeMillis())); coreService.addDefaultData(data); } }
Log4JLoggingHook implements IMethodHook { @Override public void secondAfterBody(ICoreService coreService, long methodId, long sensorTypeId, Object object, Object[] parameters, Object result, boolean exception, RegisteredSensorConfig rsc) { if (checker.isValid()) { String level = String.valueOf(parameters[1]); if (!checker.shouldCapture(level)) { return; } long platformId = platformManager.getPlatformId(); LoggingData data = new LoggingData(); data.setLevel(level); data.setMessage(String.valueOf(parameters[2])); data.setPlatformIdent(platformId); data.setSensorTypeIdent(sensorTypeId); data.setMethodIdent(methodId); data.setTimeStamp(new Timestamp(System.currentTimeMillis())); coreService.addDefaultData(data); } } }
Log4JLoggingHook implements IMethodHook { @Override public void secondAfterBody(ICoreService coreService, long methodId, long sensorTypeId, Object object, Object[] parameters, Object result, boolean exception, RegisteredSensorConfig rsc) { if (checker.isValid()) { String level = String.valueOf(parameters[1]); if (!checker.shouldCapture(level)) { return; } long platformId = platformManager.getPlatformId(); LoggingData data = new LoggingData(); data.setLevel(level); data.setMessage(String.valueOf(parameters[2])); data.setPlatformIdent(platformId); data.setSensorTypeIdent(sensorTypeId); data.setMethodIdent(methodId); data.setTimeStamp(new Timestamp(System.currentTimeMillis())); coreService.addDefaultData(data); } } Log4JLoggingHook(IPlatformManager platformManager, String minimumLevelToCapture); }
Log4JLoggingHook implements IMethodHook { @Override public void secondAfterBody(ICoreService coreService, long methodId, long sensorTypeId, Object object, Object[] parameters, Object result, boolean exception, RegisteredSensorConfig rsc) { if (checker.isValid()) { String level = String.valueOf(parameters[1]); if (!checker.shouldCapture(level)) { return; } long platformId = platformManager.getPlatformId(); LoggingData data = new LoggingData(); data.setLevel(level); data.setMessage(String.valueOf(parameters[2])); data.setPlatformIdent(platformId); data.setSensorTypeIdent(sensorTypeId); data.setMethodIdent(methodId); data.setTimeStamp(new Timestamp(System.currentTimeMillis())); coreService.addDefaultData(data); } } Log4JLoggingHook(IPlatformManager platformManager, String minimumLevelToCapture); @Override void beforeBody(long methodId, long sensorTypeId, Object object, Object[] parameters, RegisteredSensorConfig rsc); @Override void firstAfterBody(long methodId, long sensorTypeId, Object object, Object[] parameters, Object result, boolean exception, RegisteredSensorConfig rsc); @Override void secondAfterBody(ICoreService coreService, long methodId, long sensorTypeId, Object object, Object[] parameters, Object result, boolean exception, RegisteredSensorConfig rsc); }
Log4JLoggingHook implements IMethodHook { @Override public void secondAfterBody(ICoreService coreService, long methodId, long sensorTypeId, Object object, Object[] parameters, Object result, boolean exception, RegisteredSensorConfig rsc) { if (checker.isValid()) { String level = String.valueOf(parameters[1]); if (!checker.shouldCapture(level)) { return; } long platformId = platformManager.getPlatformId(); LoggingData data = new LoggingData(); data.setLevel(level); data.setMessage(String.valueOf(parameters[2])); data.setPlatformIdent(platformId); data.setSensorTypeIdent(sensorTypeId); data.setMethodIdent(methodId); data.setTimeStamp(new Timestamp(System.currentTimeMillis())); coreService.addDefaultData(data); } } Log4JLoggingHook(IPlatformManager platformManager, String minimumLevelToCapture); @Override void beforeBody(long methodId, long sensorTypeId, Object object, Object[] parameters, RegisteredSensorConfig rsc); @Override void firstAfterBody(long methodId, long sensorTypeId, Object object, Object[] parameters, Object result, boolean exception, RegisteredSensorConfig rsc); @Override void secondAfterBody(ICoreService coreService, long methodId, long sensorTypeId, Object object, Object[] parameters, Object result, boolean exception, RegisteredSensorConfig rsc);  }