Search in sources :

Example 1 with Log

use of org.apache.commons.logging.Log in project checkstyle by checkstyle.

the class TranslationCheck method checkFilesForConsistencyRegardingTheirKeys.

/**
     * Compares th the specified key set with the key sets of the given translation files (arranged
     * in a map). All missing keys are reported.
     * @param fileKeys a Map from translation files to their key sets.
     * @param keysThatMustExist the set of keys to compare with.
     */
private void checkFilesForConsistencyRegardingTheirKeys(SetMultimap<File, String> fileKeys, Set<String> keysThatMustExist) {
    for (File currentFile : fileKeys.keySet()) {
        final MessageDispatcher dispatcher = getMessageDispatcher();
        final String path = currentFile.getPath();
        dispatcher.fireFileStarted(path);
        final Set<String> currentFileKeys = fileKeys.get(currentFile);
        final Set<String> missingKeys = keysThatMustExist.stream().filter(e -> !currentFileKeys.contains(e)).collect(Collectors.toSet());
        if (!missingKeys.isEmpty()) {
            for (Object key : missingKeys) {
                log(0, MSG_KEY, key);
            }
        }
        fireErrors(path);
        dispatcher.fireFileFinished(path);
    }
}
Also used : Arrays(java.util.Arrays) SortedSet(java.util.SortedSet) LocalizedMessage(com.puppycrawl.tools.checkstyle.api.LocalizedMessage) CommonUtils(com.puppycrawl.tools.checkstyle.utils.CommonUtils) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Matcher(java.util.regex.Matcher) HashMultimap(com.google.common.collect.HashMultimap) Locale(java.util.Locale) Closeables(com.google.common.io.Closeables) MessageDispatcher(com.puppycrawl.tools.checkstyle.api.MessageDispatcher) Definitions(com.puppycrawl.tools.checkstyle.Definitions) Properties(java.util.Properties) AbstractFileSetCheck(com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck) Set(java.util.Set) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Collectors(java.util.stream.Collectors) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) SetMultimap(com.google.common.collect.SetMultimap) List(java.util.List) Optional(java.util.Optional) Log(org.apache.commons.logging.Log) Pattern(java.util.regex.Pattern) LogFactory(org.apache.commons.logging.LogFactory) Collections(java.util.Collections) InputStream(java.io.InputStream) MessageDispatcher(com.puppycrawl.tools.checkstyle.api.MessageDispatcher) File(java.io.File)

Example 2 with Log

use of org.apache.commons.logging.Log 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 3 with Log

use of org.apache.commons.logging.Log 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 4 with Log

use of org.apache.commons.logging.Log 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 5 with Log

use of org.apache.commons.logging.Log in project hadoop by apache.

the class TestDistributedShell method testDSShellWithCustomLogPropertyFile.

@Test
public void testDSShellWithCustomLogPropertyFile() throws Exception {
    final File basedir = new File("target", TestDistributedShell.class.getName());
    final File tmpDir = new File(basedir, "tmpDir");
    tmpDir.mkdirs();
    final File customLogProperty = new File(tmpDir, "custom_log4j.properties");
    if (customLogProperty.exists()) {
        customLogProperty.delete();
    }
    if (!customLogProperty.createNewFile()) {
        Assert.fail("Can not create custom log4j property file.");
    }
    PrintWriter fileWriter = new PrintWriter(customLogProperty);
    // set the output to DEBUG level
    fileWriter.write("log4j.rootLogger=debug,stdout");
    fileWriter.close();
    String[] args = { "--jar", APPMASTER_JAR, "--num_containers", "3", "--shell_command", "echo", "--shell_args", "HADOOP", "--log_properties", customLogProperty.getAbsolutePath(), "--master_memory", "512", "--master_vcores", "2", "--container_memory", "128", "--container_vcores", "1" };
    //Before run the DS, the default the log level is INFO
    final Log LOG_Client = LogFactory.getLog(Client.class);
    Assert.assertTrue(LOG_Client.isInfoEnabled());
    Assert.assertFalse(LOG_Client.isDebugEnabled());
    final Log LOG_AM = LogFactory.getLog(ApplicationMaster.class);
    Assert.assertTrue(LOG_AM.isInfoEnabled());
    Assert.assertFalse(LOG_AM.isDebugEnabled());
    LOG.info("Initializing DS Client");
    final Client client = new Client(new Configuration(yarnCluster.getConfig()));
    boolean initSuccess = client.init(args);
    Assert.assertTrue(initSuccess);
    LOG.info("Running DS Client");
    boolean result = client.run();
    LOG.info("Client run completed. Result=" + result);
    Assert.assertTrue(verifyContainerLog(3, null, true, "DEBUG") > 10);
    //After DS is finished, the log level should be DEBUG
    Assert.assertTrue(LOG_Client.isInfoEnabled());
    Assert.assertTrue(LOG_Client.isDebugEnabled());
    Assert.assertTrue(LOG_AM.isInfoEnabled());
    Assert.assertTrue(LOG_AM.isDebugEnabled());
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) HdfsConfiguration(org.apache.hadoop.hdfs.HdfsConfiguration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) Log(org.apache.commons.logging.Log) TestTimelineClient(org.apache.hadoop.yarn.client.api.impl.TestTimelineClient) YarnClient(org.apache.hadoop.yarn.client.api.YarnClient) File(java.io.File) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Aggregations

Log (org.apache.commons.logging.Log)205 Test (org.junit.Test)61 Test (org.junit.jupiter.api.Test)40 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)35 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)19 ArrayList (java.util.ArrayList)18 BeanFactory (org.springframework.beans.factory.BeanFactory)17 CountDownLatch (java.util.concurrent.CountDownLatch)15 LogConfigurationException (org.apache.commons.logging.LogConfigurationException)15 LogFactory (org.apache.commons.logging.LogFactory)14 List (java.util.List)13 File (java.io.File)12 Map (java.util.Map)11 QueueChannel (org.springframework.integration.channel.QueueChannel)11 IOException (java.io.IOException)10 MethodInvocation (org.aopalliance.intercept.MethodInvocation)10 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)10 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)10 AtomicReference (java.util.concurrent.atomic.AtomicReference)9 Log4JLogger (org.apache.commons.logging.impl.Log4JLogger)9