public MethodExecutionTrace(Properties log4jProperties) { MemoryAppender.initialize(); if (log4jProperties != null) { PropertyConfigurator.configure(log4jProperties); } }
@Override public void succeeded(Description description) { System.out.println(getFullMethodName(description) + " success" + getDuration()); MemoryAppender.initialize(); }
/** * Use this constructor to set up a particular log4j configuration using a properties file * available on the classpath, or null if you do not want to load any log4j configuration * properties. * @param log4jPropertiesResourceName */ public MethodExecutionTrace(String log4jPropertiesResourceName) { healthCheck(); MemoryAppender.initialize(); if (log4jPropertiesResourceName != null) { // Initialize log4j using a properties file available on the class path Properties log4j = new Properties(); try ( InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(log4jPropertiesResourceName) ) { if (in == null) { throw new RuntimeException(String.format("Could not load resource %s", log4jPropertiesResourceName)); } log4j.load(in); PropertyConfigurator.configure(log4j); } catch (IOException e) { throw new RuntimeException(String.format("Could not load resource %s", log4jPropertiesResourceName), e); } } }
@Override public void failed(Throwable e, Description description) { if (e instanceof AssumptionViolatedException) { System.out.println(format("%s skipped programmatically with reason: %s", getFullMethodName(description) , e.getMessage())); } else { System.out.println(getFullMethodName(description) + " FAILED with exception " + e + getDuration()); e.printStackTrace(System.out); System.out.println("=================== BEGIN STORED LOG MESSAGES ==========================="); MemoryAppender.printAllMessages(); System.out.println("=================== END STORED LOG MESSAGES ==========================="); } MemoryAppender.initialize(); }