Search in sources :

Example 81 with Logger

use of org.apache.logging.log4j.Logger in project gatk-protected 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)

Example 82 with Logger

use of org.apache.logging.log4j.Logger in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class log4j2Test method testLog4j2.

@Test
public void testLog4j2() throws InterruptedException, MQClientException {
    Logger logger = LogManager.getLogger("test");
    for (int i = 0; i < 50; i++) {
        logger.info("log4j2 log message " + i);
    }
    int received = consumeMessages(30, "log4j2", 30);
    Assert.assertTrue(received > 20);
}
Also used : Logger(org.apache.logging.log4j.Logger) Test(org.junit.Test)

Example 83 with Logger

use of org.apache.logging.log4j.Logger in project SpongeForge by SpongePowered.

the class TerminateVM method terminate.

@SuppressWarnings("unchecked")
public static void terminate(String masqueradePackage, int status) {
    final Logger log = LogManager.getLogger("Sponge");
    try {
        log.info("Attempting to shut down the VM cleanly");
        FMLCommonHandler.instance().exitJava(status, true);
    } catch (Throwable th) {
        log.info("Clean shutdown failed, forcing VM termination");
    }
    IExitHandler handler = null;
    try {
        MasqueradeClassLoader cl = new MasqueradeClassLoader(Launch.classLoader, masqueradePackage);
        Constructor<IExitHandler> ctor = ((Class<IExitHandler>) Class.forName(cl.getClassName(), true, cl)).getDeclaredConstructor();
        ctor.setAccessible(true);
        handler = ctor.newInstance();
    } catch (Throwable th) {
        log.catching(th);
        handler = new TerminateVM();
    }
    handler.exit(status);
}
Also used : Logger(org.apache.logging.log4j.Logger)

Example 84 with Logger

use of org.apache.logging.log4j.Logger in project tutorials by eugenp.

the class MyServiceTest method testRollingFileAppender.

@Test
public void testRollingFileAppender() {
    Logger rfLogger = LogManager.getLogger("RollingFileLogger");
    rfLogger.info("Json Message 1");
    rfLogger.info("Json Message 2");
}
Also used : Logger(org.apache.logging.log4j.Logger) Test(org.junit.Test)

Example 85 with Logger

use of org.apache.logging.log4j.Logger in project tutorials by eugenp.

the class MyServiceTest method testProgrammaticConfig.

@Test
public void testProgrammaticConfig() {
    LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
    Configuration config = ctx.getConfiguration();
    PatternLayout layout = PatternLayout.newBuilder().withConfiguration(config).withPattern("%d{HH:mm:ss.SSS} %level %msg%n").build();
    Appender appender = FileAppender.newBuilder().setConfiguration(config).withName("programmaticFileAppender").withLayout(layout).withFileName("java.log").build();
    appender.start();
    config.addAppender(appender);
    AppenderRef ref = AppenderRef.createAppenderRef("programmaticFileAppender", null, null);
    AppenderRef[] refs = new AppenderRef[] { ref };
    LoggerConfig loggerConfig = LoggerConfig.createLogger(false, Level.INFO, "programmaticLogger", "true", refs, null, config, null);
    loggerConfig.addAppender(appender, null, null);
    config.addLogger("programmaticLogger", loggerConfig);
    ctx.updateLoggers();
    Logger pLogger = LogManager.getLogger("programmaticLogger");
    pLogger.info("Programmatic Logger Message");
}
Also used : Appender(org.apache.logging.log4j.core.Appender) FileAppender(org.apache.logging.log4j.core.appender.FileAppender) Configuration(org.apache.logging.log4j.core.config.Configuration) PatternLayout(org.apache.logging.log4j.core.layout.PatternLayout) AppenderRef(org.apache.logging.log4j.core.config.AppenderRef) Logger(org.apache.logging.log4j.Logger) LoggerContext(org.apache.logging.log4j.core.LoggerContext) LoggerConfig(org.apache.logging.log4j.core.config.LoggerConfig) Test(org.junit.Test)

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