Skip to content

Commit

Permalink
Log4j updates
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickDeelen committed Jan 18, 2023
1 parent 75b906a commit 5998632
Show file tree
Hide file tree
Showing 103 changed files with 763 additions and 632 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public BinaryMicrobePcaAnalysis(String settingsFile, String textToReplace, Strin
try {
run((maxResults + tmpbuffersize));
} catch (IOException ex) {
Logger.getLogger(BinaryMicrobePcaAnalysis.class.getName()).log(Level.SEVERE, null, ex);
throw new RuntimeException(ex);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ void save() {
try {
config.save(output + "metasettings.xml");
} catch (ConfigurationException ex) {
Logger.getLogger(BinaryMetaAnalysisSettings.class.getName()).log(Level.SEVERE, null, ex);
throw new RuntimeException(ex);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public InternalMetaAnalysis(String settingsFile, String textToReplace, String re
try {
run();
} catch (IOException ex) {
Logger.getLogger(InternalMetaAnalysis.class.getName()).log(Level.SEVERE, null, ex);
throw new RuntimeException(ex);
}
//ToDo, check for non overlapping sites.
//Check allele assesed?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ void save() {
try {
config.save(output + "metasettings.xml");
} catch (ConfigurationException ex) {
Logger.getLogger(InternalMetaAnalysisSettings.class.getName()).log(Level.SEVERE, null, ex);
throw new RuntimeException(ex);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public CheckZScoreMeanAndVariance(String settingsFile, String textToReplace, Str
runPerDataset();
} catch (IOException ex) {
ex.printStackTrace();
Logger.getLogger(BinaryMetaAnalysis.class.getName()).log(Level.SEVERE, null, ex);
throw new RuntimeException(ex);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public SortedBinaryZScoreFile(File datasetloc, boolean r) throws IOException {
}

private void openrowdata() throws IOException {
String rowfile = loc.replaceAll("-data.dat", "-combos.txt.gz");
String rowfile = loc.getAbsolutePath().replaceAll("-data.dat", "-combos.txt.gz");
rowdata = new TextFile(rowfile, TextFile.R);

availableGenes = new LinkedHashMap<>();
Expand Down Expand Up @@ -157,7 +157,7 @@ public void skipTo(String gene) throws IllegalAccessException, IOException {
}

is.close();
FileChannel ch = FileChannel.open(Paths.get(loc), StandardOpenOption.READ);
FileChannel ch = FileChannel.open(Paths.get(loc.getAbsolutePath()), StandardOpenOption.READ);
is = new DataInputStream(Channels.newInputStream(ch.position(lookuppositioninbinaryfile)));


Expand All @@ -183,7 +183,7 @@ public void close() throws IOException {
rowdata.close();
} else {
super.close();
File f = new File(this.loc);
File f = this.loc;

long length = f.length();
System.out.println(length + " bytes (" + Gpio.humanizeFileSize(length) + ") written to " + f.getAbsolutePath());
Expand All @@ -195,7 +195,7 @@ public void close() throws IOException {
}

public String getName() {
File f = new File(this.loc);
File f = this.loc;
String name = f.getName().replaceAll("-data.dat", "");
return name;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

public class DeconvolutionLogger {
static private FileHandler outfilePath;
protected final static Logger log = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
protected final static Logger log = LogManager.getLogger(Logger.GLOBAL_LOGGER_NAME);
static public void setup(String outputDir, Boolean noConsole) throws IOException {
// get the global logger to configure it
LogManager.getLogManager().reset();
Expand Down
18 changes: 0 additions & 18 deletions Downstreamer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,6 @@
<artifactId>progressbar</artifactId>
<version>0.7.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.19.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.19.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
Expand All @@ -146,14 +136,6 @@
<groupId>com.facebook.presto.hive</groupId>
<artifactId>hive-apache</artifactId>
</exclusion>
<exclusion>
<groupId>log4j-core</groupId>
<artifactId>log4j-core</artifactId>
</exclusion>
<exclusion>
<groupId>log4j-api</groupId>
<artifactId>log4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,15 +281,15 @@ public static void main(String[] args) throws InterruptedException {

public static void initializeLoggers(Level loggingLevel, File logFile) throws IOException {
Configurator.setRootLevel(loggingLevel);
LoggerContext context = LoggerContext.getContext(false);
LoggerContext context = LoggerContext.getContext(false);
Configuration config = context.getConfiguration();

PatternLayout loggingLayoutFull = PatternLayout.newBuilder()
.withPattern("[%level] %d{ABSOLUTE} - %c{1} - %msg%n")
.build();

PatternLayout loggingLayoutReduced = PatternLayout.newBuilder()
.withPattern("[%level] %d{HH:mm:ss} - %msg%n")
.withPattern("%msg%n")
.build();

// Stdout appender
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public static DownstreamerStep2Results enrichmentAnalysis(OptionsModeEnrichment
//TODO papamters
List<LinearRegressionResult> pathwayRegeressionResults = DownstreamerRegressionEngine.performDownstreamerRegression(null, null, null, null, null, blockDiagonalIndices, true, true, true);

final DoubleMatrixDataset<String, String> pathwayPvalues = new DoubleMatrixDataset<>(pathwayData.getColObjects(), )
final DoubleMatrixDataset<String, String> pathwayPvalues = new DoubleMatrixDataset<>(pathwayData.getColObjects(), gwasGenePvalues.getColObjects());


}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,25 @@
*/
package nl.systemsgenetics.gadocommandline;

import java.io.File;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.ResourceBundle;
import org.apache.commons.cli.ParseException;
import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.FileAppender;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.SimpleLayout;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.appender.ConsoleAppender;
import org.apache.logging.log4j.core.appender.FileAppender;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.Configurator;
import org.apache.logging.log4j.core.config.LoggerConfig;
import org.apache.logging.log4j.core.layout.PatternLayout;
import org.molgenis.genotype.GenotypeDataException;
import org.molgenis.genotype.multipart.IncompatibleMultiPartGenotypeDataException;
import org.molgenis.genotype.tabix.TabixFileNotFoundException;

/**
*
Expand All @@ -29,7 +33,7 @@ public class GadoCommandline {

public static final String VERSION = ResourceBundle.getBundle("verion").getString("application.version");
private static final DateFormat DATE_TIME_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
private static final Logger LOGGER = Logger.getLogger(GadoCommandline.class);
private static final Logger LOGGER = LogManager.getLogger(GadoCommandline.class);
private static final String HEADER
= " /---------------------------------------\\\n"
+ " | GADO |\n"
Expand All @@ -41,7 +45,7 @@ public class GadoCommandline {
* @param args the command line arguments
*/
public static void main(String[] args) {

System.out.println(HEADER);
System.out.println();
System.out.println(" --- Version: " + VERSION + " ---");
Expand All @@ -57,7 +61,8 @@ public static void main(String[] args) {
System.out.flush(); //flush to make sure header is before errors
try {
Thread.sleep(25); //Allows flush to complete
} catch (InterruptedException ex) {}
} catch (InterruptedException ex) {
}

GadoOptions options;

Expand All @@ -80,24 +85,55 @@ public static void main(String[] args) {
System.exit(1);
}
}

try {
FileAppender logFileAppender = new FileAppender(new SimpleLayout(), options.getLogFile().getCanonicalPath(), false);
ConsoleAppender logConsoleInfoAppender = new ConsoleAppender(new InfoOnlyLogLayout());
Logger.getRootLogger().removeAllAppenders();
Logger.getRootLogger().addAppender(logFileAppender);

LOGGER.info("DEPICT" + VERSION);
LOGGER.info("Current date and time: " + startDateTime);

Logger.getRootLogger().addAppender(logConsoleInfoAppender);
try {

if (options.isDebugMode()) {
Logger.getRootLogger().setLevel(Level.DEBUG);
Configurator.setRootLevel(Level.DEBUG);
} else {
Logger.getRootLogger().setLevel(Level.INFO);
Configurator.setRootLevel(Level.INFO);
}
LoggerContext context = LoggerContext.getContext(false);
Configuration config = context.getConfiguration();

PatternLayout loggingLayoutFull = PatternLayout.newBuilder()
.withPattern("[%level] %d{ABSOLUTE} - %c{1} - %msg%n")
.build();

PatternLayout loggingLayoutReduced = PatternLayout.newBuilder()
.withPattern("%msg%n")
.build();

// Stdout appender
ConsoleAppender stdOut = ConsoleAppender.newBuilder()
.setName("stdout")
.setLayout(loggingLayoutReduced)
.build();
stdOut.start();

// Log file appender
FileAppender file = FileAppender.newBuilder()
.setName("file")
.setLayout(loggingLayoutFull)
.withFileName(options.getLogFile().getCanonicalPath())
.build();
file.start();

// Make sure any existing loggers are removed
for (Appender appender : context.getRootLogger().getAppenders().values()) {
context.getRootLogger().removeAppender(appender);
}

// Add the appenders to the root logger
Logger rootLogger = context.getRootLogger();
LoggerConfig rootLoggerConfig = config.getRootLogger();

rootLoggerConfig.addAppender(stdOut, Level.INFO, null);
rootLoggerConfig.addAppender(file, options.isDebugMode() ? Level.DEBUG : Level.INFO, null);
config.addLogger(rootLogger.getName(), rootLoggerConfig);

context.updateLoggers(config);

} catch (IOException e) {
System.err.println("Failed to create logger: " + e.getMessage());
System.exit(1);
Expand Down Expand Up @@ -145,9 +181,9 @@ public static void main(String[] args) {
}
System.exit(1);
}

LOGGER.info("Analysis completed");

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser;
import org.apache.log4j.Logger;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;

/**
*
Expand All @@ -22,7 +23,7 @@
public class GadoOptions {

private static final Options OPTIONS;
private static final Logger LOGGER = Logger.getLogger(GadoOptions.class);
private static final Logger LOGGER = LogManager.getLogger(GadoOptions.class);

private final GadoMode mode;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
import java.util.Map;
import java.util.zip.GZIPInputStream;

import org.apache.log4j.Logger;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.biojava.nbio.ontology.Term;
import umcg.genetica.math.matrix2.DoubleMatrixDataset;

Expand All @@ -35,7 +36,7 @@
public class HpoGenePrioritisation {

private static final NumberFormat Z_FORMAT = new DecimalFormat("#0.0##");
private static final Logger LOGGER = Logger.getLogger(HpoGenePrioritisation.class);
private static final Logger LOGGER = LogManager.getLogger(HpoGenePrioritisation.class);

public static void prioritize(GadoOptions options) throws IOException, ParseException, Exception {

Expand Down
Loading

0 comments on commit 5998632

Please sign in to comment.