[logback-dev] Custom Encoder issues

Jeremy Pierre j.14159 at gmail.com
Wed Jan 30 00:40:04 CET 2013


Hi all,

Cursory googling/ML search didn't turn anything up so I thought I'd ask a
(possibly dumb) question.

I'm working on a custom encoder (tried a LayoutBase as well, same issue
described below) in order to output JSON formatted log messages.  The
reason I'm going down this particular route vs using the existing JSON
layout extension is that for some messages, I need to append additional sub
documents (log messages will go through logstash to ElasticSearch and
possibly HDFS).  My issue:  I don't seem to be receiving "ERROR" level
messages in my encoder although the same test code using a pattern layout
seems to pass through error messages just fine.  Simple encoder
implementation (in Scala but should be intelligible regardless) follows,
JSON stuff absent:

class SimpleEncoder[T] extends EncoderBase[T] {
  override def close() {}

  override def doEncode(event: T) {
    event match {
      case loggingEvent: ILoggingEvent => {

 outputStream.write(loggingEvent.getArgumentArray().head.toString.getBytes())
outputStream.flush()
      }
      case other => {
outputStream.write(s"OTHER:  ${other}".getBytes())
 outputStream.flush()
      }
    }
  }
}

logback.xml:

<configuration>
  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder class="com.sample.logging.SimpleEncoder"/>
  </appender>

  <root level="DEBUG">
    <appender-ref ref="STDOUT" />
  </root>
</configuration>

Am I missing anything obvious?

Thanks,

Jeremy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/logback-dev/attachments/20130129/de9609e6/attachment.html>


More information about the logback-dev mailing list