use of org.apache.log4j.Priority in project hadoop by apache.
the class TestAdHocLogDumper method testDumpingSchedulerLogs.
@Test
public void testDumpingSchedulerLogs() throws Exception {
Map<Appender, Priority> levels = new HashMap<>();
String logHierarchy = TestAdHocLogDumper.class.getName();
String logFilename = "test.log";
Log log = LogFactory.getLog(logHierarchy);
if (log instanceof Log4JLogger) {
for (Enumeration appenders = Logger.getRootLogger().getAllAppenders(); appenders.hasMoreElements(); ) {
Object obj = appenders.nextElement();
if (obj instanceof AppenderSkeleton) {
AppenderSkeleton appender = (AppenderSkeleton) obj;
levels.put(appender, appender.getThreshold());
}
}
}
AdHocLogDumper dumper = new AdHocLogDumper(logHierarchy, logFilename);
dumper.dumpLogs("DEBUG", 1000);
LOG.debug("test message 1");
LOG.info("test message 2");
File logFile = new File(logFilename);
Assert.assertTrue(logFile.exists());
Thread.sleep(2000);
long lastWrite = logFile.lastModified();
Assert.assertTrue(lastWrite < Time.now());
Assert.assertTrue(logFile.length() != 0);
// make sure levels are set back to their original values
if (log instanceof Log4JLogger) {
for (Enumeration appenders = Logger.getRootLogger().getAllAppenders(); appenders.hasMoreElements(); ) {
Object obj = appenders.nextElement();
if (obj instanceof AppenderSkeleton) {
AppenderSkeleton appender = (AppenderSkeleton) obj;
Assert.assertEquals(levels.get(appender), appender.getThreshold());
}
}
}
boolean del = logFile.delete();
if (!del) {
LOG.info("Couldn't clean up after test");
}
}
use of org.apache.log4j.Priority in project jop by jop-devel.
the class ClinitOrder method printDependency.
/**
* Print the dependency for debugging. Not used at the moment.
* @param warn if true, print with warning level
*/
private void printDependency(boolean warn) {
Priority lvl = warn ? Level.WARN : Level.DEBUG;
Set<ClassInfo> cliSet = clinit.keySet();
for (ClassInfo clinf : cliSet) {
logger.log(lvl, "Class " + clinf.getClassName());
Set<ClassInfo> depends = clinit.get(clinf);
for (ClassInfo clf : depends) {
logger.log(lvl, "\tdepends " + clf.getClassName());
}
}
}
use of org.apache.log4j.Priority in project tdi-studio-se by Talend.
the class MessageBoxExceptionHandler method showMessage.
/**
* Open a message box showing a generic message and exception message.
*
* @param ex - exception to show
*/
protected static void showMessage(Throwable ex, Shell shell) {
if (ex.equals(lastShowedAction)) {
return;
}
lastShowedAction = ex;
// TODO smallet use ErrorDialogWidthDetailArea ?
//$NON-NLS-1$
String title = Messages.getString("commons.error");
//$NON-NLS-1$
String msg = Messages.getString("exception.errorOccured", ex.getMessage());
Priority priority = Level.ERROR;
if (priority == Level.FATAL || priority == Level.ERROR) {
MessageDialog.openError(shell, title, msg);
} else if (priority == Level.WARN) {
MessageDialog.openWarning(shell, title, msg);
} else if (priority == Level.INFO) {
MessageDialog.openInformation(shell, title, msg);
} else {
MessageDialog.openInformation(shell, title, msg);
}
}
Aggregations