Permalink
Browse files

Fix Noisy print messages from logging framework #516

To fix, call SLF4JSilencer.silence();
  • Loading branch information...
ignazio1977 committed May 5, 2016
1 parent ba3f320 commit 70cf682f7f52d8010f83469e9e29c5136c39c260
Showing with 36 additions and 0 deletions.
  1. +36 −0 api/src/main/java/org/semanticweb/owlapi/util/SLF4JSilencer.java
@@ -0,0 +1,36 @@
package org.semanticweb.owlapi.util;

import java.io.PrintStream;

import javax.annotation.Nullable;

/**
* A small wrapper class that allows SLF4J error messages about not having a
* binding (or more than one) silenced. Just add {@code SLF4J.silence();} before
* any logger is initialised - ideally as first instruction in your main. If the
* default behaviour becomes useful, {@code SLF4J.deSilence();} will restore
* things.
*/
public class SLF4JSilencer {

private static final PrintStream originalErr = System.err;
private static final PrintStream filterOut = new PrintStream(System.err) {

@Override
public void println(@Nullable String l) {
if (l == null || !l.startsWith("SLF4J")) {
super.println(l);
}
}
};

/** Silence SLF4J warnings. */
public static void silence() {
System.setErr(filterOut);
}

/** Restore regular behaviour. */
public static void deSilence() {
System.setErr(originalErr);
}
}

0 comments on commit 70cf682

Please sign in to comment.