Search in sources :

Example 66 with Logger

use of org.apache.logging.log4j.Logger in project logging-log4j2 by apache.

the class AbstractScriptFilterTest method testGroovyFilter.

@Test
public void testGroovyFilter() throws Exception {
    final Logger logger = LogManager.getLogger("TestGroovyFilter");
    logger.traceEntry();
    logger.info("This should not be logged");
    ThreadContext.put("UserId", "JohnDoe");
    logger.info("This should be logged");
    ThreadContext.clearMap();
    final ListAppender app = getContext().getListAppender("List");
    try {
        final List<String> messages = app.getMessages();
        assertNotNull("No Messages", messages);
        assertTrue("Incorrect number of messages. Expected 2, Actual " + messages.size(), messages.size() == 2);
    } finally {
        app.clear();
    }
}
Also used : ListAppender(org.apache.logging.log4j.test.appender.ListAppender) Logger(org.apache.logging.log4j.Logger) Test(org.junit.Test)

Example 67 with Logger

use of org.apache.logging.log4j.Logger in project logging-log4j2 by apache.

the class AbstractScriptFilterTest method testJavascriptFilter.

@Test
public void testJavascriptFilter() throws Exception {
    final Logger logger = LogManager.getLogger("TestJavaScriptFilter");
    logger.traceEntry();
    logger.info("This should not be logged");
    ThreadContext.put("UserId", "JohnDoe");
    logger.info("This should be logged");
    ThreadContext.clearMap();
    final ListAppender app = getContext().getListAppender("List");
    final List<String> messages = app.getMessages();
    try {
        assertNotNull("No Messages", messages);
        assertTrue("Incorrect number of messages. Expected 2, Actual " + messages.size(), messages.size() == 2);
    } finally {
        app.clear();
    }
}
Also used : ListAppender(org.apache.logging.log4j.test.appender.ListAppender) Logger(org.apache.logging.log4j.Logger) Test(org.junit.Test)

Example 68 with Logger

use of org.apache.logging.log4j.Logger in project logging-log4j2 by apache.

the class XmlLoggerPropsTest method testWithProps.

@Test
public void testWithProps() {
    final ListAppender listAppender = context.getListAppender("List");
    assertNotNull("No List Appender", listAppender);
    try {
        assertThat(context.getConfiguration(), is(instanceOf(XmlConfiguration.class)));
        Logger logger = LogManager.getLogger(XmlLoggerPropsTest.class);
        logger.debug("Test with props");
        logger = LogManager.getLogger("tiny.bubbles");
        logger.debug("Test on root");
        final List<String> events = listAppender.getMessages();
        assertTrue("No events", events.size() > 0);
        assertTrue("Incorrect number of events", events.size() == 2);
        assertThat(events.get(0), allOf(containsString("user="), containsString("phrasex=****"), containsString("test=test"), containsString("test2=test2default"), containsString("test3=Unknown"), containsString("test4=test"), containsString("test5=test"), containsString("attribKey=attribValue"), containsString("duplicateKey=nodeValue")));
        assertThat(events.get(1), allOf(containsString("user="), containsString("phrasex=****"), containsString("test=test"), containsString("test2=test2default"), containsString("test3=Unknown"), containsString("test4=test"), containsString("test5=test"), containsString("attribKey=attribValue"), containsString("duplicateKey=nodeValue")));
    } finally {
        System.clearProperty("test");
    }
}
Also used : ListAppender(org.apache.logging.log4j.test.appender.ListAppender) Matchers.containsString(org.hamcrest.Matchers.containsString) Logger(org.apache.logging.log4j.Logger) Test(org.junit.Test)

Example 69 with Logger

use of org.apache.logging.log4j.Logger in project logging-log4j2 by apache.

the class MongoDbTest method test.

@Test
public void test() {
    final Logger logger = LogManager.getLogger();
    logger.info("Hello log");
}
Also used : Logger(org.apache.logging.log4j.Logger) Test(org.junit.Test)

Example 70 with Logger

use of org.apache.logging.log4j.Logger in project gatk by broadinstitute.

the class HDF5PCACoveragePoNCreationUtils method subsetReadCountsToUsableTargets.

/**
     * Subsets targets in the input count to the usable ones based on the percentile threshold indicated
     * by the user.
     *
     * <p>
     *     It returns a pair of object, where the left one is the updated read-counts with only the usable
     *     targets, and the right one is the corresponding target factors.
     * </p>
     *
     * @param readCounts the input read-counts.
     * @param targetFactorPercentileThreshold the minimum median count percentile under which targets are not considered useful.
     * @return never {@code null}.
     */
@VisibleForTesting
static Pair<ReadCountCollection, double[]> subsetReadCountsToUsableTargets(final ReadCountCollection readCounts, final double targetFactorPercentileThreshold, final Logger logger) {
    final double[] targetFactors = calculateTargetFactors(readCounts);
    final double threshold = new Percentile(targetFactorPercentileThreshold).evaluate(targetFactors);
    final List<Target> targetByIndex = readCounts.targets();
    final Set<Target> result = IntStream.range(0, targetFactors.length).filter(i -> targetFactors[i] >= threshold).mapToObj(targetByIndex::get).collect(Collectors.toCollection(LinkedHashSet::new));
    if (result.size() == targetByIndex.size()) {
        logger.info(String.format("All %d targets are kept", targetByIndex.size()));
        return new ImmutablePair<>(readCounts, targetFactors);
    } else {
        final int discardedCount = targetFactors.length - result.size();
        logger.info(String.format("Discarded %d target(s) out of %d with factors below %.2g (%.2f percentile)", discardedCount, targetFactors.length, threshold, targetFactorPercentileThreshold));
        final double[] targetFactorSubset = DoubleStream.of(targetFactors).filter(i -> i >= threshold).toArray();
        return new ImmutablePair<>(readCounts.subsetTargets(result), targetFactorSubset);
    }
}
Also used : IntStream(java.util.stream.IntStream) DefaultRealMatrixChangingVisitor(org.apache.commons.math3.linear.DefaultRealMatrixChangingVisitor) SVD(org.broadinstitute.hellbender.utils.svd.SVD) java.util(java.util) JavaSparkContext(org.apache.spark.api.java.JavaSparkContext) MatrixSummaryUtils(org.broadinstitute.hellbender.utils.MatrixSummaryUtils) ParamUtils(org.broadinstitute.hellbender.utils.param.ParamUtils) Pair(org.apache.commons.lang3.tuple.Pair) Median(org.apache.commons.math3.stat.descriptive.rank.Median) HDF5File(org.broadinstitute.hdf5.HDF5File) IOUtils(org.broadinstitute.hellbender.utils.io.IOUtils) org.broadinstitute.hellbender.tools.exome(org.broadinstitute.hellbender.tools.exome) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) File(java.io.File) DoubleStream(java.util.stream.DoubleStream) Percentile(org.apache.commons.math3.stat.descriptive.rank.Percentile) Logger(org.apache.logging.log4j.Logger) MathUtils(org.broadinstitute.hellbender.utils.MathUtils) UserException(org.broadinstitute.hellbender.exceptions.UserException) SVDFactory(org.broadinstitute.hellbender.utils.svd.SVDFactory) Utils(org.broadinstitute.hellbender.utils.Utils) RealMatrix(org.apache.commons.math3.linear.RealMatrix) VisibleForTesting(com.google.common.annotations.VisibleForTesting) LogManager(org.apache.logging.log4j.LogManager) Percentile(org.apache.commons.math3.stat.descriptive.rank.Percentile) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

Logger (org.apache.logging.log4j.Logger)491 Test (org.junit.Test)226 File (java.io.File)80 Test (org.junit.jupiter.api.Test)69 IOException (java.io.IOException)34 LoggerContext (org.apache.logging.log4j.core.LoggerContext)33 Appender (org.apache.logging.log4j.core.Appender)32 Collectors (java.util.stream.Collectors)30 StatusLogger (org.apache.logging.log4j.status.StatusLogger)30 BufferedReader (java.io.BufferedReader)29 Level (org.apache.logging.log4j.Level)27 FileReader (java.io.FileReader)26 Path (java.nio.file.Path)26 CountDownLatch (java.util.concurrent.CountDownLatch)23 Map (java.util.Map)21 IntStream (java.util.stream.IntStream)20 LoggerConfig (org.apache.logging.log4j.core.config.LoggerConfig)20 java.util (java.util)18 HashMap (java.util.HashMap)18 Configuration (org.apache.logging.log4j.core.config.Configuration)18