@Test public void logInfoDisabledShouldNotLog() throws IOException { Level previousLogLevel = setLogLevel(Slf4jSnitchLogger.class, Level.ERROR); logSnitch.log(); Mockito.verify(analyzerMock, Mockito.never()).analyzeSystem(); Mockito.verify(objectMapperMock, Mockito.never()).writeValueAsString(Mockito.any()); setLogLevel(Slf4jSnitchLogger.class, previousLogLevel); }
public void log() { if (LOGGER.isInfoEnabled()) { try { SystemFragment frag = analyzer.analyzeSystem(); String fragString = objectMapper.writeValueAsString(frag); LOGGER.info("System fragment : {}", fragString); } catch (IOException | RuntimeException e) { LOGGER.error("Error while logging system fragment", e); } } }
Slf4jSnitchLogger implements CommandLineRunner { public void log() { if (LOGGER.isInfoEnabled()) { try { SystemFragment frag = analyzer.analyzeSystem(); String fragString = objectMapper.writeValueAsString(frag); LOGGER.info("System fragment : {}", fragString); } catch (IOException | RuntimeException e) { LOGGER.error("Error while logging system fragment", e); } } } }
Slf4jSnitchLogger implements CommandLineRunner { public void log() { if (LOGGER.isInfoEnabled()) { try { SystemFragment frag = analyzer.analyzeSystem(); String fragString = objectMapper.writeValueAsString(frag); LOGGER.info("System fragment : {}", fragString); } catch (IOException | RuntimeException e) { LOGGER.error("Error while logging system fragment", e); } } } Slf4jSnitchLogger(ApplicationAnalyzer analyzer, ObjectMapper objectMapper); }
Slf4jSnitchLogger implements CommandLineRunner { public void log() { if (LOGGER.isInfoEnabled()) { try { SystemFragment frag = analyzer.analyzeSystem(); String fragString = objectMapper.writeValueAsString(frag); LOGGER.info("System fragment : {}", fragString); } catch (IOException | RuntimeException e) { LOGGER.error("Error while logging system fragment", e); } } } Slf4jSnitchLogger(ApplicationAnalyzer analyzer, ObjectMapper objectMapper); void log(); @Override void run(String... args); }
Slf4jSnitchLogger implements CommandLineRunner { public void log() { if (LOGGER.isInfoEnabled()) { try { SystemFragment frag = analyzer.analyzeSystem(); String fragString = objectMapper.writeValueAsString(frag); LOGGER.info("System fragment : {}", fragString); } catch (IOException | RuntimeException e) { LOGGER.error("Error while logging system fragment", e); } } } Slf4jSnitchLogger(ApplicationAnalyzer analyzer, ObjectMapper objectMapper); void log(); @Override void run(String... args);  }