I use SLF4J with Logback to log events in my application which is deployed on OpenLiberty. The current log output:
[INFO] [07/05/2023 00:07:53:743 CEST] 0000005a SystemOut O [ERROR] o.p.c.p.c.TextArrayConverter - ...
Because of that, all logs appears at the INFO level :
[INFO] [07/05/2023 00:36:53:483 CEST] 000000ab SystemOut O [ERROR] ...
[INFO] [07/05/2023 00:36:53:483 CEST] 000000ab SystemOut O [INFO] ...
[INFO] [07/05/2023 00:37:53:487 CEST] 000000ab SystemOut O [INFO] ...
However, I want the output to look like this :
[ERROR] o.p.c.p.c.TextArrayConverter - ...
Which configuration should I use to have the desired output ? or at least show the correct severity in server logs ?
I have no logging configuration in server.xml.
bootstrap.properties:
com.ibm.ws.logging.stackTraceSingleEntry=true
com.ibm.ws.logging.message.log.level=OFF
com.ibm.ws.logging.message.format=json
com.ibm.ws.logging.message.source=
com.ibm.ws.logging.trace.log.level=OFF
com.ibm.ws.logging.console.format=TBASIC
com.ibm.ws.logging.console.log.level=INFO
logback.xml:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<Pattern>
[%level] %C{1} - %msg%n
</Pattern>
</encoder>
</appender>
<root level="info">
<appender-ref ref="CONSOLE"/>
</root>
</configuration>
I tried different bootstrap configurations but nothing worked. For exemple, I tried to output logs in JSON format by adding to the bootstrap.properties file :
com.ibm.ws.logging.apps.write.json=true
com.ibm.ws.logging.console.format=JSON
The output was :
{"message":"[ERROR] o.p.c.p.c.TextArrayConverter - ...","level":"SystemOut",...}
The level is not set correctly.
EDIT:
An answer was provided in this post: Logback JUL appender.
I did a similar thing by changing the SLF4J binding from Logback to JUL since OpenLiberty uses JUL. Using JUL with SLF4J is described here