Can't quite find an answer to this, can anyone state a fix.
I have a library jar i'm building and using logback (logabck 1.2.3, jansi 1.16) and groovy, and i'm trying to colour code the log display - as spring boot manages to do - but i didn't want spring boot as dependency for this library i'm building.
I have included the jansi (1.16 as stated in logabck docs) library as dependency to the gradle build.
the relevant section of my logback.groovy looks like this
appender('STDOUT', ConsoleAppender) {
withJansi = true
encoder(PatternLayoutEncoder) {
charset = Charset.forName('UTF-8')
pattern = consolePatternFormat
}
}
when i run a test i get and error (with jansi enabled) like this
16:17:42,344 |-WARN in com.softwood.logging.logback.AnsiConsoleAppender[STDOUT] - Failed to create WindowsAnsiOutputStream. Falling back on the default stream. ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type org.fusesource.jansi.WindowsAnsiOutputStream
at ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type org.fusesource.jansi.WindowsAnsiOutputStream
at at ch.qos.logback.core.util.OptionHelper.instantiateByClassNameAndParameter(OptionHelper.java:69)
at at ch.qos.logback.core.util.OptionHelper.instantiateByClassNameAndParameter(OptionHelper.java:40)
at at ch.qos.logback.core.ConsoleAppender.getTargetStreamForWindows(ConsoleAppender.java:88)
at at ch.qos.logback.core.ConsoleAppender.start(ConsoleAppender.java:79)
...
Caused by: java.lang.reflect.InvocationTargetException
at at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at at ch.qos.logback.core.util.OptionHelper.instantiateByClassNameAndParameter(OptionHelper.java:64)
there was a suggestion here https://jira.qos.ch/browse/LOGBACK-762 that all one needed to do was to wrap the output stream, so i created a custom console appender in my project like this
import java.io.OutputStream;
import org.fusesource.jansi.AnsiConsole;
import ch.qos.logback.core.ConsoleAppender;
public class AnsiConsoleAppender<E> extends ConsoleAppender<E> {
@Override
public void setOutputStream(OutputStream outputStream) {
super.setOutputStream(AnsiConsole.wrapOutputStream(outputStream));
}
}
and modified the logback.groovy appender to to use the AnsiConsoleAppender like this
appender('STDOUT', AnsiConsoleAppender) {
withJansi = true
encoder(PatternLayoutEncoder) {
charset = Charset.forName('UTF-8')
pattern = consolePatternFormat
}
}
however this fails the same way as before. If i disable the jansi support - it all works as you'd expect. When I enable with jansi and run tests then these fail as shown
Colour logging works with springboot and you get the coloured console, so someone knows how to do this. But i don't know what the logback problem is
has any one got the basic jansi colour coding for logback (1.2.3) under windows to work ? If so whats the secret.
For now i've had to disable, but would like to get this to work. Bit frustrating