This is a fork of from the stalar fork of the larrymyers fork, which itself is a fork of the poorly maintained wikia fork. Don't expected this fork to be maintained in time.
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.
- dropwizard 0.8.4 => dropwizard-logstash-encoder 1.1.0
- dropwizard 0.9.0 => dropwizard-logstash-encoder 1.2.0
- dropwizard 1.3.14 => dropwizard-logstash-encoder 3.0.0 (Java 11)
Must be manually build and added to your repository manager.
Maven:
<dependency>
<groupId>de.joblift</groupId>
<artifactId>dropwizard-logstash-encoder</artifactId>
<version>3.0.0</version>
</dependency>
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:
host
- string - maps tosyslogHost
when usinglogstash-socket
, andremoteHost
when usinglogstash-tcp
port
- intincludeCallerInfo
- booleanincludeContext
- booleanincludeMdc
- booleancustomFields
- hashmap - the configuration differs from the original logstash-logback-encoder config in that this is not a raw json string (see example below)fieldNames
- hashmapqueueSize
- int - only valid forlogstash-tcp
includeCallerData
- bool - only valid forlogstash-tcp
prefix
- string - pattern written before the JSON object, only valid forlogstash-socket
suffix
- string - pattern written after the JSON object, only valid forlogstash-socket
For more information about prefixes and suffixes, please refer to logstash-logback-encoder#prefixsuffix.
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!");
Or even more simpler, by using de.galan:commons Say class, eg.:
Say.warn("Hello {key}", "World");
Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.