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);
}
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();
}
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());
}
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;
}
}
}
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"));
}
Aggregations