I'm using Logback framework v1.0.1 to do logging. I would like to know how to append the log message to an outputstream in java.
I wanted to format the log message into key=value pairs At the end i want to getformatted log message as an output stream. I retrieved the logger instance and log the message at debug level.
ch.qos.logback.classic.Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger("SplunkSearch.SplunkLogger");
logger.info( "wrap = true, setValue = false,");
logger.debug( "wrap = true, setValue = false,");
The logback.xml configuration file is as follows :
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="true">
<timestamp key="bySecond" datePattern="yyyyMMdd'T'HHmmss" timeReference="contextBirth"/>
<contextName>splunksearchcontext</contextName>
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
<Target>System.out</Target>
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<appender name= "outputstream" class="ch.qos.logback.core.OutputStreamAppender">
<encoder>
<pattern></pattern>
</encoder>
</appender>
<root level="debug">
<appender-ref ref="stdout"/>
<appender-ref ref="outputstream" />
</root>
</configuration>
The output is as follows when i run.
i saw this line in the status message that is sort of error. No outputstream set.
15:07:19,399 |-ERROR in ch.qos.logback.core.OutputStreamAppender[outputstream] - No
output stream set for the appender named "outputstream".
15:07:19.414 [main] INFO SplunkSearch.SplunkLogger - wrap = true, setValue = false,
15:07:19.430 [main] DEBUG SplunkSearch.SplunkLogger - wrap = true, setValue = false,