Today I have started using LogBack in combination with SLF4J for my project. I have been trying to redirect all console output (From my own project and others) to a custom appender.
The final goal is to redirect all the output to a Discord chat channel.
I have looked into the following approach: java runtime.getruntime() getting output from executing a command line program but it wasn't successful.
I am aiming for the following structure:
- Console message is sent by another library
- Catch the message and process it
I have tried the following implementation:
public class DiscordAppender extends AppenderBase<ILoggingEvent> {
@Override
protected void append(ILoggingEvent eventObject) {
SomeDiscordClient.sendMessage(specificChannel, eventObject.getFormattedMessage());
}
}
With the following logback.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="DISCORD" class="package.DiscordAppender"/>
<root level="TRACE">
<appender-ref ref="DISCORD"/>
</root>
</configuration>
But this approach is not working, hopefully someone can help me out.