Redirect output (to file) from Maven dependency in Java

173 views Asked by At

In my project, I'm working with the HeidelTime framework, that I included as a Maven dependency. This framework is very verbose, so I would like to redirect its output to a file (but not all outputs from my application). The constraints are the following:

  • HeidelTime uses a Logger (Log4J), so I can't simply redirect the standard output to a file.
  • I can't access the logger because it's private to the main class (HeidelTimeStandalone.java).
  • I included HeidelTime in my project as a Maven dependency and I prefer to keep it as is (even if I could download the code and modify directly the source code to make the logger public...)
  • Finally, I don't want to simply redirect all outputs (java -jar myApplication.jar > file.txt) because I would like to preserve my standard output apart from HeidelTime's output...

Does anybody have an idea to redirect HeidelTime's output in a file? Hope this at least is possible!

1

There are 1 answers

0
user20728263 On

Turning off the heideltime's logger can be achieved like this (taken from https://github.com/HeidelTime/heideltime/issues/86)

HeidelTimeStandalone heidelTime = new HeidelTimeStandalone();

java.util.logging.logger htLogger = java.utillogging.LogManager.getLogManager().getLogger("HeidelTimeStandalone");
    htLogger.setLevel(java.util.logging.Level.OFF);

heidelTime = new HeidelTimeStandalone(
    Language.ENGLISH,
    DocumnetType.NARRATIVES,
    OutputType.TIMEML,
    "./config.props",
    POSTagger.NO);