0

I'm writing a Java app that uses a third-party library; this library emits useful warning messages to the console when things go wrong. So useful, in fact, that I'd like my code to act on them at the time they are produced (or shortly afterwards). Is this possible given the fact that I have no control over how the third-party library's logs are produced?

My best Googling has turned this up so far, which looks promising; but I don't know anything about PrintStream or whether the third-party library uses it for logging.

Is there some sort of equivalent to reflection whereby an application can process its own logs?

Ed Graham
  • 4,306
  • 3
  • 30
  • 30
  • 1
    You'll get more useful answers if you explain how this library produces log messages. – tgdavies Jul 27 '21 at 13:53
  • 1
    Learn about PrintStreams before even thinking about doing reflection. Reflection is not the answer here, anyhow. – Anders Lindgren Jul 27 '21 at 14:07
  • @tgdavies - I have no idea how it produces log messages! That's the point; it's a black box to me. They just appear in the console when I run my `.jar` file. I include them as `logger`s in my `log4j2` configuration file. – Ed Graham Jul 27 '21 at 16:28
  • @tgdavies - slf4j/logback may well provide an answer, or at least a route to be explored: thank you! – Ed Graham Jul 27 '21 at 16:31

0 Answers0