Search in sources :

Example 11 with Log4JLogger

use of org.apache.commons.logging.impl.Log4JLogger in project hadoop by apache.

the class NavBlock method render.

@Override
protected void render(Block html) {
    boolean addErrorsAndWarningsLink = false;
    Log log = LogFactory.getLog(NMErrorsAndWarningsPage.class);
    if (log instanceof Log4JLogger) {
        Log4jWarningErrorMetricsAppender appender = Log4jWarningErrorMetricsAppender.findAppender();
        if (appender != null) {
            addErrorsAndWarningsLink = true;
        }
    }
    String RMWebAppURL = WebAppUtils.getResolvedRMWebAppURLWithScheme(this.conf);
    Hamlet.UL<Hamlet.DIV<Hamlet>> ul = html.div("#nav").h3()._("ResourceManager")._().ul().li().a(RMWebAppURL, "RM Home")._()._().h3()._("NodeManager")._().ul().li().a(url("node"), "Node Information")._().li().a(url("allApplications"), "List of Applications")._().li().a(url("allContainers"), "List of Containers")._()._().h3("Tools").ul().li().a("/conf", "Configuration")._().li().a("/logs", "Local logs")._().li().a("/stacks", "Server stacks")._().li().a("/jmx?qry=Hadoop:*", "Server metrics")._();
    if (addErrorsAndWarningsLink) {
        ul.li().a(url("errors-and-warnings"), "Errors/Warnings")._();
    }
    ul._()._();
}
Also used : Hamlet(org.apache.hadoop.yarn.webapp.hamlet.Hamlet) Log(org.apache.commons.logging.Log) Log4JLogger(org.apache.commons.logging.impl.Log4JLogger) Log4jWarningErrorMetricsAppender(org.apache.hadoop.yarn.util.Log4jWarningErrorMetricsAppender)

Example 12 with Log4JLogger

use of org.apache.commons.logging.impl.Log4JLogger in project hadoop by apache.

the class TestNativeAzureFileSystemClientLogging method testLoggingEnabled.

@Test
public void testLoggingEnabled() throws Exception {
    LogCapturer logs = LogCapturer.captureLogs(new Log4JLogger(Logger.getRootLogger()));
    // Update configuration based on the Test.
    updateFileSystemConfiguration(true);
    performWASBOperations();
    assertTrue(verifyStorageClientLogs(logs.getOutput(), TEMP_DIR));
}
Also used : Log4JLogger(org.apache.commons.logging.impl.Log4JLogger) LogCapturer(org.apache.hadoop.test.GenericTestUtils.LogCapturer) Test(org.junit.Test)

Example 13 with Log4JLogger

use of org.apache.commons.logging.impl.Log4JLogger in project hadoop by apache.

the class NavBlock method render.

@Override
public void render(Block html) {
    boolean addErrorsAndWarningsLink = false;
    Log log = LogFactory.getLog(NavBlock.class);
    if (log instanceof Log4JLogger) {
        Log4jWarningErrorMetricsAppender appender = Log4jWarningErrorMetricsAppender.findAppender();
        if (appender != null) {
            addErrorsAndWarningsLink = true;
        }
    }
    Hamlet.DIV<Hamlet> nav = html.div("#nav").h3("Application History").ul().li().a(url("about"), "About")._().li().a(url("apps"), "Applications").ul().li().a(url("apps", YarnApplicationState.FINISHED.toString()), YarnApplicationState.FINISHED.toString())._().li().a(url("apps", YarnApplicationState.FAILED.toString()), YarnApplicationState.FAILED.toString())._().li().a(url("apps", YarnApplicationState.KILLED.toString()), YarnApplicationState.KILLED.toString())._()._()._()._();
    Hamlet.UL<Hamlet.DIV<Hamlet>> tools = nav.h3("Tools").ul();
    tools.li().a("/conf", "Configuration")._().li().a("/logs", "Local logs")._().li().a("/stacks", "Server stacks")._().li().a("/jmx?qry=Hadoop:*", "Server metrics")._();
    if (addErrorsAndWarningsLink) {
        tools.li().a(url("errors-and-warnings"), "Errors/Warnings")._();
    }
    tools._()._();
}
Also used : Hamlet(org.apache.hadoop.yarn.webapp.hamlet.Hamlet) Log(org.apache.commons.logging.Log) Log4JLogger(org.apache.commons.logging.impl.Log4JLogger) Log4jWarningErrorMetricsAppender(org.apache.hadoop.yarn.util.Log4jWarningErrorMetricsAppender)

Example 14 with Log4JLogger

use of org.apache.commons.logging.impl.Log4JLogger in project hadoop by apache.

the class AdHocLogDumper method dumpLogs.

public void dumpLogs(String level, int timePeriod) throws YarnRuntimeException, IOException {
    synchronized (lock) {
        if (logFlag) {
            LOG.info("Attempt to dump logs when appender is already running");
            throw new YarnRuntimeException("Appender is already dumping logs");
        }
        Level targetLevel = Level.toLevel(level);
        Log log = LogFactory.getLog(name);
        appenderLevels.clear();
        if (log instanceof Log4JLogger) {
            Logger packageLogger = ((Log4JLogger) log).getLogger();
            currentLogLevel = packageLogger.getLevel();
            Level currentEffectiveLevel = packageLogger.getEffectiveLevel();
            // make sure we can create the appender first
            Layout layout = new PatternLayout("%d{ISO8601} %p %c: %m%n");
            FileAppender fApp;
            File file = new File(System.getProperty("yarn.log.dir"), targetFilename);
            try {
                fApp = new FileAppender(layout, file.getAbsolutePath(), false);
            } catch (IOException ie) {
                LOG.warn("Error creating file, can't dump logs to " + file.getAbsolutePath(), ie);
                throw ie;
            }
            fApp.setName(AdHocLogDumper.AD_HOC_DUMPER_APPENDER);
            fApp.setThreshold(targetLevel);
            // level
            for (Enumeration appenders = Logger.getRootLogger().getAllAppenders(); appenders.hasMoreElements(); ) {
                Object obj = appenders.nextElement();
                if (obj instanceof AppenderSkeleton) {
                    AppenderSkeleton appender = (AppenderSkeleton) obj;
                    appenderLevels.put(appender.getName(), appender.getThreshold());
                    appender.setThreshold(currentEffectiveLevel);
                }
            }
            packageLogger.addAppender(fApp);
            LOG.info("Dumping adhoc logs for " + name + " to " + file.getAbsolutePath() + " for " + timePeriod + " milliseconds");
            packageLogger.setLevel(targetLevel);
            logFlag = true;
            TimerTask restoreLogLevel = new RestoreLogLevel();
            Timer restoreLogLevelTimer = new Timer();
            restoreLogLevelTimer.schedule(restoreLogLevel, timePeriod);
        }
    }
}
Also used : Log(org.apache.commons.logging.Log) Log4JLogger(org.apache.commons.logging.impl.Log4JLogger) IOException(java.io.IOException) Log4JLogger(org.apache.commons.logging.impl.Log4JLogger) YarnRuntimeException(org.apache.hadoop.yarn.exceptions.YarnRuntimeException) File(java.io.File)

Example 15 with Log4JLogger

use of org.apache.commons.logging.impl.Log4JLogger in project hbase by apache.

the class HttpRequestLog method getRequestLog.

public static RequestLog getRequestLog(String name) {
    String lookup = serverToComponent.get(name);
    if (lookup != null) {
        name = lookup;
    }
    String loggerName = "http.requests." + name;
    String appenderName = name + "requestlog";
    Log logger = LogFactory.getLog(loggerName);
    if (logger instanceof Log4JLogger) {
        Log4JLogger httpLog4JLog = (Log4JLogger) logger;
        Logger httpLogger = httpLog4JLog.getLogger();
        Appender appender = null;
        try {
            appender = httpLogger.getAppender(appenderName);
        } catch (LogConfigurationException e) {
            LOG.warn("Http request log for " + loggerName + " could not be created");
            throw e;
        }
        if (appender == null) {
            LOG.info("Http request log for " + loggerName + " is not defined");
            return null;
        }
        if (appender instanceof HttpRequestLogAppender) {
            HttpRequestLogAppender requestLogAppender = (HttpRequestLogAppender) appender;
            NCSARequestLog requestLog = new NCSARequestLog();
            requestLog.setFilename(requestLogAppender.getFilename());
            requestLog.setRetainDays(requestLogAppender.getRetainDays());
            return requestLog;
        } else {
            LOG.warn("Jetty request log for " + loggerName + " was of the wrong class");
            return null;
        }
    } else {
        LOG.warn("Jetty request log can only be enabled using Log4j");
        return null;
    }
}
Also used : Appender(org.apache.log4j.Appender) RequestLog(org.eclipse.jetty.server.RequestLog) NCSARequestLog(org.eclipse.jetty.server.NCSARequestLog) Log(org.apache.commons.logging.Log) Log4JLogger(org.apache.commons.logging.impl.Log4JLogger) NCSARequestLog(org.eclipse.jetty.server.NCSARequestLog) LogConfigurationException(org.apache.commons.logging.LogConfigurationException) Logger(org.apache.log4j.Logger) Log4JLogger(org.apache.commons.logging.impl.Log4JLogger)

Aggregations

Log4JLogger (org.apache.commons.logging.impl.Log4JLogger)21 Logger (org.apache.log4j.Logger)10 Log (org.apache.commons.logging.Log)9 Appender (org.apache.log4j.Appender)8 AsyncAppender (org.apache.log4j.AsyncAppender)5 RollingFileAppender (org.apache.log4j.RollingFileAppender)5 File (java.io.File)4 Log4jWarningErrorMetricsAppender (org.apache.hadoop.yarn.util.Log4jWarningErrorMetricsAppender)4 BufferedReader (java.io.BufferedReader)3 FileReader (java.io.FileReader)3 Hamlet (org.apache.hadoop.yarn.webapp.hamlet.Hamlet)3 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 LogConfigurationException (org.apache.commons.logging.LogConfigurationException)2 Configuration (org.apache.hadoop.conf.Configuration)2 LogCapturer (org.apache.hadoop.test.GenericTestUtils.LogCapturer)2 PatternLayout (org.apache.log4j.PatternLayout)2 NCSARequestLog (org.eclipse.jetty.server.NCSARequestLog)2 RequestLog (org.eclipse.jetty.server.RequestLog)2 Before (org.junit.Before)2