Search in sources :

Example 1 with Category

use of org.apache.log4j.Category in project hadoop by apache.

the class TestTaskLogAppender method testTaskLogAppender.

/**
 * test TaskLogAppender 
 */
@SuppressWarnings("deprecation")
@Test(timeout = 5000)
public void testTaskLogAppender() {
    TaskLogAppender appender = new TaskLogAppender();
    System.setProperty(TaskLogAppender.TASKID_PROPERTY, "attempt_01_02_m03_04_001");
    System.setProperty(TaskLogAppender.LOGSIZE_PROPERTY, "1003");
    appender.activateOptions();
    assertEquals(appender.getTaskId(), "attempt_01_02_m03_04_001");
    assertEquals(appender.getTotalLogFileSize(), 1000);
    assertEquals(appender.getIsCleanup(), false);
    // test writer   
    Writer writer = new StringWriter();
    appender.setWriter(writer);
    Layout layout = new PatternLayout("%-5p [%t]: %m%n");
    appender.setLayout(layout);
    Category logger = Logger.getLogger(getClass().getName());
    LoggingEvent event = new LoggingEvent("fqnOfCategoryClass", logger, Priority.INFO, "message", new Throwable());
    appender.append(event);
    appender.flush();
    appender.close();
    assertTrue(writer.toString().length() > 0);
    // test cleanup should not changed 
    appender = new TaskLogAppender();
    appender.setIsCleanup(true);
    appender.activateOptions();
    assertEquals(appender.getIsCleanup(), true);
}
Also used : LoggingEvent(org.apache.log4j.spi.LoggingEvent) Category(org.apache.log4j.Category) StringWriter(java.io.StringWriter) Layout(org.apache.log4j.Layout) PatternLayout(org.apache.log4j.PatternLayout) PatternLayout(org.apache.log4j.PatternLayout) StringWriter(java.io.StringWriter) Writer(java.io.Writer) Test(org.junit.Test)

Example 2 with Category

use of org.apache.log4j.Category in project carina by qaprosoft.

the class AbstractTest method executeBeforeTestSuite.

@BeforeSuite(alwaysRun = true)
public void executeBeforeTestSuite(ITestContext context) {
    // Add shutdown hook
    Runtime.getRuntime().addShutdownHook(new ShutdownHook());
    // Set log4j properties
    PropertyConfigurator.configure(ClassLoader.getSystemResource("log4j.properties"));
    // Set SoapUI log4j properties
    System.setProperty("soapui.log4j.config", "./src/main/resources/soapui-log4j.xml");
    try {
        Logger root = Logger.getRootLogger();
        Enumeration<?> allLoggers = root.getLoggerRepository().getCurrentCategories();
        while (allLoggers.hasMoreElements()) {
            Category tmpLogger = (Category) allLoggers.nextElement();
            if (tmpLogger.getName().equals("com.qaprosoft.carina.core")) {
                tmpLogger.setLevel(Level.toLevel(Configuration.get(Parameter.CORE_LOG_LEVEL)));
            }
        }
    } catch (NoSuchMethodError e) {
        LOGGER.error("Unable to redefine logger level due to the conflicts between log4j and slf4j!");
    }
    startDate = new Date().getTime();
    LOGGER.info(Configuration.asString());
    // Configuration.validateConfiguration();
    LOGGER.debug("Default thread_count=" + context.getCurrentXmlTest().getSuite().getThreadCount());
    context.getCurrentXmlTest().getSuite().setThreadCount(Configuration.getInt(Parameter.THREAD_COUNT));
    LOGGER.debug("Updated thread_count=" + context.getCurrentXmlTest().getSuite().getThreadCount());
    // update DataProviderThreadCount if any property is provided otherwise sync with value from suite xml file
    int count = Configuration.getInt(Parameter.DATA_PROVIDER_THREAD_COUNT);
    if (count > 0) {
        LOGGER.debug("Updated 'data_provider_thread_count' from " + context.getCurrentXmlTest().getSuite().getDataProviderThreadCount() + " to " + count);
        context.getCurrentXmlTest().getSuite().setDataProviderThreadCount(count);
    } else {
        LOGGER.debug("Synching data_provider_thread_count with values from suite xml file...");
        R.CONFIG.put(Parameter.DATA_PROVIDER_THREAD_COUNT.getKey(), String.valueOf(context.getCurrentXmlTest().getSuite().getDataProviderThreadCount()));
        LOGGER.debug("Updated 'data_provider_thread_count': " + Configuration.getInt(Parameter.DATA_PROVIDER_THREAD_COUNT));
    }
    LOGGER.debug("Default data_provider_thread_count=" + context.getCurrentXmlTest().getSuite().getDataProviderThreadCount());
    LOGGER.debug("Updated data_provider_thread_count=" + context.getCurrentXmlTest().getSuite().getDataProviderThreadCount());
    if (!Configuration.isNull(Parameter.URL)) {
        if (!Configuration.get(Parameter.URL).isEmpty()) {
            RestAssured.baseURI = Configuration.get(Parameter.URL);
        }
    }
    try {
        L10N.init();
    } catch (Exception e) {
        LOGGER.error("L10N bundle is not initialized successfully!", e);
    }
    try {
        I18N.init();
    } catch (Exception e) {
        LOGGER.error("I18N bundle is not initialized successfully!", e);
    }
    try {
        L10Nparser.init();
    } catch (Exception e) {
        LOGGER.error("L10Nparser bundle is not initialized successfully!", e);
    }
    // TODO: move out from AbstractTest->executeBeforeTestSuite
    String customCapabilities = Configuration.get(Parameter.CUSTOM_CAPABILITIES);
    if (!customCapabilities.isEmpty()) {
        // redefine core CONFIG properties using custom capabilities file
        new CapabilitiesLoder().loadCapabilities(customCapabilities);
    }
    String extraCapabilities = Configuration.get(Parameter.EXTRA_CAPABILITIES);
    if (!extraCapabilities.isEmpty()) {
        // redefine core CONFIG properties using extra capabilities file
        new CapabilitiesLoder().loadCapabilities(extraCapabilities);
    }
    try {
        TestRail.updateBeforeSuite(context, this.getClass().getName(), getTitle(context));
    } catch (Exception e) {
        LOGGER.error("TestRail is not initialized successfully!", e);
    }
    updateAppPath();
}
Also used : Category(org.apache.log4j.Category) Logger(org.apache.log4j.Logger) CapabilitiesLoder(com.qaprosoft.carina.core.foundation.webdriver.core.capability.CapabilitiesLoder) FileNotFoundException(java.io.FileNotFoundException)

Example 3 with Category

use of org.apache.log4j.Category in project apex-core by apache.

the class LoggerUtilTest method testParentLevel.

@Test
public void testParentLevel() {
    org.apache.log4j.Logger log4jLogger = LogManager.getLogger("com.datatorrent.stram.util.Unknown");
    assertNull(log4jLogger.getLevel());
    Category parent = log4jLogger.getParent();
    while (parent.getLevel() == null) {
        parent = parent.getParent();
    }
    assertSame(log4jLogger.getEffectiveLevel(), parent.getLevel());
}
Also used : Logger(org.apache.log4j.Logger) Category(org.apache.log4j.Category) Test(org.junit.Test)

Example 4 with Category

use of org.apache.log4j.Category in project apex-core by apache.

the class LoggerUtilTest method setup.

@BeforeClass
public static void setup() throws Exception {
    logger.debug("Logger repository before LoggerUtil.changeLoggersLevel() {}", LogManager.getLoggerRepository());
    LoggerUtil.changeLoggersLevel(Maps.<String, String>newHashMap());
    logger.debug("Logger repository after LoggerUtil.changeLoggersLevel() {}", LogManager.getLoggerRepository());
    log4jLogger.setLevel(Level.TRACE);
    Category category = log4jLogger;
    while (category != null) {
        Enumeration appenders = category.getAllAppenders();
        while (appenders.hasMoreElements()) {
            Object o = appenders.nextElement();
            if (o instanceof AppenderSkeleton) {
                AppenderSkeleton appender = (AppenderSkeleton) o;
                if (!appenderLevelMap.containsKey(appender)) {
                    appenderLevelMap.put(appender, appender.getThreshold());
                    appender.setThreshold(Level.INFO);
                }
            }
        }
        if (category.getAdditivity()) {
            category = category.getParent();
        } else {
            category = null;
        }
    }
}
Also used : AppenderSkeleton(org.apache.log4j.AppenderSkeleton) Category(org.apache.log4j.Category) Enumeration(java.util.Enumeration) BeforeClass(org.junit.BeforeClass)

Example 5 with Category

use of org.apache.log4j.Category in project commons by twitter.

the class JULBridgeHandlerTest method checkToLoggingEvent.

@Test
public void checkToLoggingEvent() {
    LogRecord record = new LogRecord(Level.FINEST, "test is {0}");
    record.setParameters(new Object[] { "successful" });
    record.setThreadID(42);
    Throwable t = new Throwable();
    record.setThrown(t);
    // source class and method names are usually inferred, but because there's no JUL in the stack
    // frame, it won't work as expected.
    record.setSourceClassName(getClass().getName());
    record.setSourceMethodName("checkToLoggingEvent");
    Logger log4jLogger = new JULBridgeHandler().getLogger(record);
    org.apache.log4j.Level log4jLevel = JULBridgeLevelConverter.toLog4jLevel(Level.FINEST);
    LoggingEvent event = JULBridgeHandler.toLoggingEvent(record, log4jLogger, log4jLevel, false);
    assertThat(event.getLogger(), is((Category) log4jLogger));
    assertThat(event.getLevel(), is(log4jLevel));
    assertThat(event.getMessage(), is((Object) "test is successful"));
    assertThat(event.getThreadName(), is("42"));
    assertThat(event.getTimeStamp(), is(record.getMillis()));
    assertThat(event.getThrowableInformation().getThrowable(), is(sameInstance(t)));
    LocationInfo info = event.getLocationInformation();
    assertThat(info.getClassName(), is(getClass().getName()));
    assertThat(info.getMethodName(), is("checkToLoggingEvent"));
}
Also used : JULBridgeHandler(com.twitter.common.logging.julbridge.JULBridgeHandler) LoggingEvent(org.apache.log4j.spi.LoggingEvent) Category(org.apache.log4j.Category) LogRecord(java.util.logging.LogRecord) Logger(org.apache.log4j.Logger) LocationInfo(org.apache.log4j.spi.LocationInfo) Test(org.junit.Test)

Aggregations

Category (org.apache.log4j.Category)12 LoggingEvent (org.apache.log4j.spi.LoggingEvent)4 Enumeration (java.util.Enumeration)3 ConsoleAppender (org.apache.log4j.ConsoleAppender)3 Level (org.apache.log4j.Level)3 Logger (org.apache.log4j.Logger)3 Test (org.junit.Test)3 Date (java.util.Date)2 Appender (org.apache.log4j.Appender)2 FileAppender (org.apache.log4j.FileAppender)2 Layout (org.apache.log4j.Layout)2 PatternLayout (org.apache.log4j.PatternLayout)2 LocationInfo (org.apache.log4j.spi.LocationInfo)2 CapabilitiesLoder (com.qaprosoft.carina.core.foundation.webdriver.core.capability.CapabilitiesLoder)1 JULBridgeHandler (com.twitter.common.logging.julbridge.JULBridgeHandler)1 LogEvent (io.fabric8.insight.log.LogEvent)1 FileNotFoundException (java.io.FileNotFoundException)1 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 Calendar (java.util.Calendar)1