Java Code Examples for htsjdk.samtools.util.Log#LogLevel

The following examples show how to use htsjdk.samtools.util.Log#LogLevel . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PolyATrimmerTest.java    From Drop-seq with MIT License 6 votes vote down vote up
@Test(dataProvider = "testClpDataProvider")
public void testClp(final boolean newTrimmer) throws IOException {
    final File tempDir = Files.createTempDirectory("PolyATrimmerTest.").toFile();
    final Log.LogLevel saveLogLevel = Log.getGlobalLogLevel();
    Log.setGlobalLogLevel(Log.LogLevel.DEBUG);
    try {
        final PolyATrimmer clp = new PolyATrimmer();
        clp.INPUT = INPUT;
        clp.OUTPUT = File.createTempFile("PolyATrimmerTest.", ".sam");
        clp.OUTPUT.deleteOnExit();
        clp.OUTPUT_SUMMARY = File.createTempFile("PolyATrimmerTest.", ".summary");
        clp.OUTPUT_SUMMARY.deleteOnExit();
        clp.TMP_DIR = Arrays.asList(tempDir);
        tempDir.deleteOnExit();
        clp.MISMATCHES = 0;
        clp.NUM_BASES = 6;
        clp.VALIDATION_STRINGENCY = ValidationStringency.STRICT;
        clp.USE_NEW_TRIMMER = newTrimmer;
        Assert.assertEquals(clp.doWork(), 0);
        final File expectedResult = new File(TESTDATA_DIR, String.format("N701.%s_trimmer.sam", newTrimmer? "new": "old"));
        TestUtils.assertSamFilesSame(clp.OUTPUT, expectedResult);
    } finally {
        Log.setGlobalLogLevel(saveLogLevel);
        IOUtil.recursiveDelete(tempDir.toPath());
    }
}
 
Example 2
Source File: SparkCommandLineArgumentCollection.java    From gatk with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Returns the Spark log level for the argument set. This is simply sparkVerbosity
 * if it was specified. Otherwise, it returns the log level corresponding to the
 * provided tool (htsjdk) verbosity.
 *
 * @param  toolVerbosity  Current tool's htsjdk log level
 * @return      Spark log level String
 */
public String getSparkVerbosity(final Log.LogLevel toolVerbosity) {
    Utils.nonNull(toolVerbosity, "Tool verbosity cannot be null");
    if (sparkVerbosity != null) return sparkVerbosity;
    if (toolVerbosity.equals(Log.LogLevel.DEBUG)) {
        return Level.DEBUG.name();
    }
    if (toolVerbosity.equals(Log.LogLevel.INFO)) {
        return Level.INFO.name();
    }
    if (toolVerbosity.equals(Log.LogLevel.WARNING)) {
        return Level.WARN.name();
    }
    if (toolVerbosity.equals(Log.LogLevel.ERROR)) {
        return Level.ERROR.name();
    }
    throw new IllegalStateException("Unknown tool verbosity: " + toolVerbosity.name());
}
 
Example 3
Source File: ConfigFactory.java    From gatk with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Logs all the parameters in the given {@link Config} object at the given {@link Log.LogLevel}
 * @param config A {@link Config} object from which to log all parameters and values.
 * @param logLevel The log {@link htsjdk.samtools.util.Log.LogLevel} at which to log the data in {@code config}
 * @param <T> any {@link Config} type to use to log all configuration information.
 */
public static <T extends Config> void logConfigFields(final T config, final Log.LogLevel logLevel) {

    Utils.nonNull(config);
    Utils.nonNull(logLevel);

    final Level level = LoggingUtils.levelToLog4jLevel(logLevel);

    // Only continue in this method here if we would log the given level:
    if ( !logger.isEnabled(level) ) {
        return;
    }

    logger.log(level, "Configuration file values: ");
    for ( final Map.Entry<String, Object> entry : getConfigMap(config, false).entrySet() ) {
        logger.log(level, "\t" + entry.getKey() + " = " + entry.getValue());
    }
}
 
Example 4
Source File: LoggingUtils.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Propagate the verbosity level to Picard, log4j, the java built in logger, and Kryo's MinLog
 */
public static void setLoggingLevel(final Log.LogLevel verbosity) {

    // Call the Picard API to establish the logging level used by Picard
    Log.setGlobalLogLevel(verbosity);

    // set the Log4JLoggingLevel
    setLog4JLoggingLevel(verbosity);

    // set the java.util.logging Level
    setJavaUtilLoggingLevel(verbosity);

    // set the esotericsoft MinLog level, this is used by kryo
    setMinLogLoggingLevel(verbosity);
}
 
Example 5
Source File: LoggingUtils.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static void setLog4JLoggingLevel(Log.LogLevel verbosity) {
    // Now establish the logging level used by log4j by propagating the requested
    // logging level to all loggers associated with our logging configuration.
    final LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false);
    final Configuration loggerContextConfig = loggerContext.getConfiguration();
    final String contextClassName = LoggingUtils.class.getName();
    final LoggerConfig loggerConfig = loggerContextConfig.getLoggerConfig(contextClassName);

    loggerConfig.setLevel(levelToLog4jLevel(verbosity));
    loggerContext.updateLoggers();
}
 
Example 6
Source File: LoggingUtils.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * set the logging level for {@link com.esotericsoftware.minlog.Log}, the logger used by Kryo
 */
private static void setMinLogLoggingLevel(Log.LogLevel verbosity) {
    switch (verbosity) {
        case DEBUG: com.esotericsoftware.minlog.Log.DEBUG(); break;
        case INFO: com.esotericsoftware.minlog.Log.INFO(); break;
        case WARNING: com.esotericsoftware.minlog.Log.WARN(); break;
        case ERROR: com.esotericsoftware.minlog.Log.ERROR(); break;
        default:
            throw new GATKException("This log level is not implemented properly: " + verbosity);
    }
}
 
Example 7
Source File: LoggingUtils.java    From gatk with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
static Log.LogLevel levelFromLog4jLevel(Level log4jLevel) {
    return loggingLevelNamespaceMap.inverse().get(log4jLevel);
}
 
Example 8
Source File: LoggingUtils.java    From gatk with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private static java.util.logging.Level levelToJavaUtilLevel(Log.LogLevel picardLevel) {
    return javaUtilLevelNamespaceMap.get(picardLevel);
}
 
Example 9
Source File: SparkCommandLineArgumentCollectionTest.java    From gatk with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test(dataProvider = "toolLogLevels")
public void testSparkVerbosityWithValidToolLogLevels(Log.LogLevel toolVerbosity, String expectedSparkLevel){
    final SparkCommandLineArgumentCollection sparkArgumentCollection = new SparkCommandLineArgumentCollection();
    final String level = sparkArgumentCollection.getSparkVerbosity(toolVerbosity);
    Assert.assertEquals(level, expectedSparkLevel);
}
 
Example 10
Source File: CramTools.java    From cramtools with Apache License 2.0 4 votes vote down vote up
@Override
public Log.LogLevel convert(String s) {
	return Log.LogLevel.valueOf(s.toUpperCase());
}
 
Example 11
Source File: LoggingUtils.java    From gatk with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Converts a picard log level to a log4j log level.
 * @param picardLevel Picard {@link Log.LogLevel} to convert to a Log4J {@link Level}.
 * @return The {@link Level} that corresponds to the given {@code picardLevel}.
 */
public static Level levelToLog4jLevel(Log.LogLevel picardLevel) {
    return loggingLevelNamespaceMap.get(picardLevel);
}