0
votes

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,

1

1 Answers

0
votes

It said "No output stream set for the appender named "outputstream"." You defined an appender, but not output stream in it. I don't know where to write the message.

logback manual said that you should not use outputstream appender directly. And from the manual, I also didn't find any way to configure the output stream into this appender.

If you really want to use it, I think the only way is that add it in your program.