Skip to content

Commit

Permalink
reduce LOG4J pollution
Browse files Browse the repository at this point in the history
  • Loading branch information
rbossy committed Jul 7, 2017
1 parent 22cf6df commit 462e939
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
16 changes: 16 additions & 0 deletions bibliome/src/main/java/org/bibliome/alvisnlp/MiscUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.bibliome.alvisnlp;

import java.util.Properties;

import org.apache.log4j.PropertyConfigurator;

public enum MiscUtils {
;

public static void configureSilentLog4J() {
Properties props = new Properties();
props.setProperty("log4j.rootLogger", "WARNING, A1");
props.setProperty("log4j.appender.A1", "org.apache.log4j.varia.NullAppender");
PropertyConfigurator.configure(props);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.jena.riot.RDFFormat;
import org.apache.jena.shared.PrefixMapping;
import org.apache.log4j.BasicConfigurator;
import org.bibliome.alvisnlp.MiscUtils;
import org.bibliome.alvisnlp.modules.CorpusModule;
import org.bibliome.alvisnlp.modules.ResolvedObjects;
import org.bibliome.alvisnlp.modules.rdf.RDFExport.RDFExportResolvedObjects;
Expand Down Expand Up @@ -83,7 +84,7 @@ private RDFExportResolvedObjects(ProcessingContext<Corpus> ctx, RDFExport module
}

private static Model createModel(RDFExport module) {
BasicConfigurator.configure();
MiscUtils.configureSilentLog4J();
Model model = ModelFactory.createDefaultModel();
model.setNsPrefixes(PrefixMapping.Standard);
model.setNsPrefix("xsd", "http://www.w3.org/2001/XMLSchema#");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.apache.jena.riot.RDFDataMgr;
import org.apache.jena.shared.PrefixMapping;
import org.apache.log4j.PropertyConfigurator;
import org.bibliome.alvisnlp.MiscUtils;
import org.bibliome.alvisnlp.modules.SectionModule.SectionResolvedObjects;
import org.bibliome.alvisnlp.modules.trie.TrieProjector;
import org.bibliome.util.Iterators;
Expand Down Expand Up @@ -110,11 +111,7 @@ private static String getNodeValue(RDFNode node) {
}

private Model createModel(Logger logger) throws IOException {
Properties props = new Properties();
props.setProperty("log4j.rootLogger", "WARNING, A1");
props.setProperty("log4j.appender.A1", "org.apache.log4j.varia.NullAppender");
// BasicConfigurator.configure();
PropertyConfigurator.configure(props);
MiscUtils.configureSilentLog4J();
Model model = ModelFactory.createDefaultModel();
model.setNsPrefixes(PrefixMapping.Standard);
model.setNsPrefix("xsd", "http://www.w3.org/2001/XMLSchema#");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Logger;

import org.bibliome.alvisnlp.MiscUtils;
import org.bibliome.alvisnlp.modules.SectionModule;
import org.bibliome.alvisnlp.modules.SectionModule.SectionResolvedObjects;
import org.bibliome.util.Iterators;
Expand Down Expand Up @@ -66,6 +67,7 @@ protected SectionResolvedObjects createResolvedObjects(ProcessingContext<Corpus>
@Override
public void process(ProcessingContext<Corpus> ctx, Corpus corpus) throws ModuleException {
try {
MiscUtils.configureSilentLog4J();
Logger logger = getLogger(ctx);
EvaluationContext evalCtx = new EvaluationContext(logger );
AbstractSequenceClassifier<CoreLabel> classifier = createClassifier();
Expand Down

0 comments on commit 462e939

Please sign in to comment.