Search in sources :

Example 1 with Priority

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");
    }
}
Also used : Appender(org.apache.log4j.Appender) AppenderSkeleton(org.apache.log4j.AppenderSkeleton) Enumeration(java.util.Enumeration) HashMap(java.util.HashMap) Log(org.apache.commons.logging.Log) Priority(org.apache.log4j.Priority) Log4JLogger(org.apache.commons.logging.impl.Log4JLogger) File(java.io.File) Test(org.junit.Test)

Example 2 with Priority

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());
        }
    }
}
Also used : Priority(org.apache.log4j.Priority) ClassInfo(com.jopdesign.common.ClassInfo)

Example 3 with Priority

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);
    }
}
Also used : Priority(org.apache.log4j.Priority)

Aggregations

Priority (org.apache.log4j.Priority)3 ClassInfo (com.jopdesign.common.ClassInfo)1 File (java.io.File)1 Enumeration (java.util.Enumeration)1 HashMap (java.util.HashMap)1 Log (org.apache.commons.logging.Log)1 Log4JLogger (org.apache.commons.logging.impl.Log4JLogger)1 Appender (org.apache.log4j.Appender)1 AppenderSkeleton (org.apache.log4j.AppenderSkeleton)1 Test (org.junit.Test)1