Home

Awesome

dropwizard-logback-logstash-encoder

Dropwizard logging addon for sending logs using the logstash-logback-encoder. This is needed because Dropwizard overwrites the default mechanism for loading logback configuration (logback.xml) in favor of its application.yml files.

Installation

Maven:

<dependency>
  <groupId>com.wikia</groupId>
  <artifactId>dropwizard-logstash-encoder</artifactId>
  <version>2.0.0</version>
</dependency>

Use version:

1.0.2 for Dropwizard <1.0

2.0.0 for Dropwizard 1.0

Usage

You must configure dropwizard to use these appenders in your application.yml file:

logging:
  appenders:
    - type: logstash-socket # LogstashSocketAppender, for LogstashTcpSocketAppender use logstash-tcp
      ...

Additional configuration keys for the appender, see logstash-logback-encoder#usage for info. All configs apply to both logstash-socket and logstash-tcp, unless otherwise noted:

Example config:

logging:
  appenders:
    - type: logstash-socket
      host: 127.0.0.1
      fieldNames:
        message: msg
        timestamp: log_date
      customFields:
        myTestField1: myTestVal
        myTestField2: 2

Then, loggers can be used the same way as if they were configured using logback.xml for logstash-logback-encoder, example (using Guava):

LoggerFactory.getLogger("myTestLogger").warn(
	appendEntries(
		new ImmutableMap.Builder<String, Object>()
			.put("some_key", 1)
			.put("some_other_key", "two")
			.build()
	),
	"warning! warning!");

License

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.