PrintStream out2= new PrintStream(out1); PrintStream err2= new PrintStream(err1); testInitialize(props, out2, err2); Logger strLogger= Logger.getLogger(String.class); strLogger.trace("trace should not appear"); Assert.assertEquals(out1.toString(), ""); Assert.assertEquals(err1.toString(), ""); strLogger.debug("debug should not appear"); Assert.assertEquals(out1.toString(), ""); Assert.assertEquals(err1.toString(), ""); strLogger.info("info should not appear"); Assert.assertEquals(out1.toString(), ""); Assert.assertEquals(err1.toString(), ""); strLogger.warn("warn should appear"); int outlength= out1.toString().length(); Assert.assertTrue(out1.toString().startsWith("[java.lang.String] [WARN] warn should appear")); Assert.assertEquals(err1.toString(), ""); strLogger.error("error should appear"); Assert.assertEquals(out1.toString().length(), outlength); Assert.assertTrue(err1.toString().startsWith("[java.lang.String] [ERROR] error should appear")); strLogger.fatal("fatal should appear"); Assert.assertEquals(out1.toString().length(), outlength); Assert.assertTrue(err1.toString().contains("[java.lang.String] [FATAL] fatal should appear"));
/** * Retrieve a logger named according to the value of the pClass.getName() * parameter. If the named logger already exists, then the existing instance * will be returned. Otherwise, a new instance is created. By default, loggers * do not have a set level but inherit it from their nearest ancestor with * a set level. * * @param pClass The class' logger to retrieve. * @return a logger named according to the value of the pClass.getName(). */ public static synchronized Logger getLogger(Class pClass) { initialize(); Logger logger= loggers.get(pClass); if(logger != null) { return logger; } int level= getLevel(pClass); logger= new Logger(pClass, level); loggers.put(pClass, logger); return logger; }
/** * This method is for debugging purpose only. * * @param pProperties a properties bundle initialised as log4testng * property file would be. * @param pOut the standard output stream to be used for logging. * @param pErr the standard error stream to be used for logging. */ private static synchronized void testInitialize(Properties pProperties, PrintStream pOut, PrintStream pErr) { initialized= true; loggers.clear(); rootLoggerLevel= WARN; debug= false; out= pOut; err= pErr; checkProperties(pProperties); }
/** * Class.getEnclosingClass() only exists on JDK5, so reimplementing it * here. */ private static Class<?> getEnclosingClass(Class<?> declaringClass) { Class<?> result = null; String className = declaringClass.getName(); int index = className.indexOf('$'); if (index != -1) { String ecn = className.substring(0, index); try { result = Class.forName(ecn); } catch (ClassNotFoundException e) { Logger.getLogger(ClassHelper.class).error(e.getMessage(),e); } } return result; }
/** * Test setting the root logger level */ private static void testRootLoggerSet() { Properties props= new Properties(); ByteArrayOutputStream out1= new ByteArrayOutputStream(); ByteArrayOutputStream err1= new ByteArrayOutputStream(); PrintStream out2= new PrintStream(out1); PrintStream err2= new PrintStream(err1); props.put("log4testng.rootLogger", "DEBUG"); testInitialize(props, out2, err2); Logger strLogger= Logger.getLogger(String.class); strLogger.trace("trace should appear"); Assert.assertEquals(out1.toString(), ""); Assert.assertEquals(err1.toString(), ""); strLogger.debug("debug should appear"); Assert.assertTrue(out1.toString().startsWith("[java.lang.String] [DEBUG] debug should appear")); Assert.assertEquals(err1.toString(), ""); }
private static void p(String s) { if (VERBOSE) { LOGGER.info("[FileStringBuffer] " + s); } }
public static void error(String errorMessage) { LOG.error("[Error] " + errorMessage); }
private void setConfigurable(IConfigurable c) { // compare by reference! if (m_configurable != null && m_configurable != c) { LOGGER.warn("Configurable already set"); } m_configurable = c; }
public static void handleTimout(Queue<String> failures, ExecutorService es, TimeoutException e) { for (StackTraceElement[] trace : Thread.getAllStackTraces().values()) { for (StackTraceElement element : trace) { logger.info("\tat " + element); } if (trace.length > 0) { logger.info("------"); } } MoreExecutors.shutdownAndAwaitTermination(es, 10, TimeUnit.SECONDS); for (String failure : failures) { logger.debug(failure); } fail("Spun forever", e); }
public static void executeWithTimeOut(Queue<String> failures, Callable<Long> task) { ExecutorService es = Executors.newSingleThreadExecutor( new ThreadFactoryBuilder().setDaemon(true).build()); Future<Long> future = es.submit(task); try { long timeNS = future.get(TIMEOUT, TimeUnit.SECONDS); logger.debug("\nExecuted in " + TimeUnit.NANOSECONDS.toSeconds(timeNS) + " second(s)"); } catch (ExecutionException e) { fail("Exception during test: " + e.toString(), e); } catch (TimeoutException e) { handleTimout(failures, es, e); } catch (InterruptedException e) { fail("", e); } }
private void parseSuite(String suitePath) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("suiteXmlPath: \"" + suitePath + "\"");
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { if (!m_validate && !m_hasWarn) { Logger.getLogger(TestNGContentHandler.class).warn("It is strongly recommended to add " + "\"<!DOCTYPE suite SYSTEM \"http://testng.org/testng-1.0.dtd\" >\" at the top of your file, " + "otherwise TestNG may fail or not work as expected.");
/** * Tests setting a partial logger name (a hierarchy scope) */ private static void testUserLoggerSetHierarchy() { Properties props= new Properties(); ByteArrayOutputStream out1= new ByteArrayOutputStream(); ByteArrayOutputStream err1= new ByteArrayOutputStream(); PrintStream out2= new PrintStream(out1); PrintStream err2= new PrintStream(err1); props.put("log4testng.logger.java.lang", "DEBUG"); testInitialize(props, out2, err2); Logger strLogger= Logger.getLogger(String.class); strLogger.trace("trace should not appear"); Assert.assertEquals(out1.toString(), ""); Assert.assertEquals(err1.toString(), ""); strLogger.debug("debug should appear"); Assert.assertTrue(out1.toString().startsWith("[java.lang.String] [DEBUG] debug should appear")); Assert.assertEquals(err1.toString(), ""); }
protected void dump() { LOG.info("===== Test class\n" + m_testClass.getName()); for (ITestNGMethod m : m_beforeClassMethods) { LOG.info(" @BeforeClass " + m); } for (ITestNGMethod m : m_beforeTestMethods) { LOG.info(" @BeforeMethod " + m); } for (ITestNGMethod m : m_testMethods) { LOG.info(" @Test " + m); } for (ITestNGMethod m : m_afterTestMethods) { LOG.info(" @AfterMethod " + m); } for (ITestNGMethod m : m_afterClassMethods) { LOG.info(" @AfterClass " + m); } LOG.info("======"); }
private Object invokeMethod(Annotation test, String methodName) { Object result = null; try { // Note: we should cache methods already looked up Method m = test.getClass().getMethod(methodName); result = m.invoke(test); } catch (Exception e) { Logger.getLogger(JDK15TagFactory.class).error(e.getMessage(), e); } return result; } }
private static void error(String s) { LOGGER.error(s); }
private void setHookable(IHookable h) { // compare by reference! if (m_hookable != null && m_hookable != h) { LOGGER.warn("Hookable already set"); } m_hookable = h; }
/** * Prepare browserConf and IProperty for the test method */ public void prepareData() { if (isEnabled) { switch (dataSource) { case XmlData: updateXml(System.getProperty("env-type")); break; case GoogleData: updateGoogleSheet(System.getProperty("env-type")); break; case NoSource: // ignore no need to set data break; default: break; } }else{ LOGGER.debug("As the method:"+methodName+" is not enabled no need to set data"); } }
private void parseSuite(String suitePath) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("suiteXmlPath: \"" + suitePath + "\"");