Skip to content
This repository was archived by the owner on Oct 17, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 41 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,61 @@ Maven:
```

## Usage
You must configure dropwizard to use these appenders in your application.yml file:
You must configure dropwizard to use these appenders in your application.yml file. There are 3 different
appenders available: socket, tcp, and file. To configure each set the proper appender type:

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

Additional configuration keys for the appender, see [logstash-logback-encoder#usage](https://github.com/logstash/logstash-logback-encoder/blob/master/README.md#usage) for info. All configs apply to both `logstash-socket` and `logstash-tcp`, unless otherwise noted:
* `host` - string - maps to `syslogHost` when using `logstash-socket`, and `remoteHost` when using `logstash-tcp`
* `port` - int
## Logstash tcp
```yml
logging:
appenders:
- type: logstash-tcp
...
```

## Logstash file
```yml
logging:
appenders:
- type: logstash-file
...
```

# Common fields across all appenders

* `includeCallerInfo` - boolean
* `includeContext` - boolean
* `includeMdc` - boolean
* `customFields` - hashmap - the configuration differs from the original logstash-logback-encoder config in that this is not a raw json string (see example below)
* `fieldNames` - hashmap

# Settings available to logstash-tcp and logstash-socket

* `host` - string - maps to `syslogHost` when using `logstash-socket`, and `remoteHost` when using `logstash-tcp`
* `port` - int
* `queueSize` - int - only valid for `logstash-tcp`
* `includeCallerData` - bool - only valid for `logstash-tcp`

# Settings available to logstash-file

These settings are the same as the dropwizard [file appender](http://www.dropwizard.io/manual/configuration.html#file) settings except
without the log pattern. Defaults in parenthesis.

* `currentLogFilename` - (REQUIRED) The filename where current events are logged.
* `threshold` - (ALL) The lowest level of events to write to the file.
* `archive` - (true) Whether or not to archive old events in separate files.
* `archivedLogFilenamePattern` - (none) Required if archive is true. The filename pattern for archived files. %d is replaced with the date in yyyy-MM-dd form, and the fact that it ends with .gz indicates the file will be gzipped as it’s archived. Likewise, filename patterns which end in .zip will be filled as they are archived.
* `archivedFileCount` - (5) The number of archived files to keep. Must be between 1 and 50.

# Examples

Example config:
```yaml
logging:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,91 +8,95 @@
import javax.validation.constraints.NotNull;
import java.util.HashMap;

abstract class AbstractLogstashRemoteAppenderFactory extends AbstractLogstashAppenderFactory {
@NotNull
protected String host;

@Min(1)
@Max(65535)

protected int port;

@JsonProperty
public void setHost(String host) {
this.host = host;
}

@JsonProperty
public String getHost() {
return host;
}

@JsonProperty
public void setPort(int port) {
this.port = port;
}

@JsonProperty
public int getPort() {
return port;
}
}

abstract class AbstractLogstashAppenderFactory extends AbstractAppenderFactory {
@NotNull
protected String host;

@Min(1)
@Max(65535)
protected int port;

protected boolean includeCallerInfo = false;

protected boolean includeContext = true;

protected boolean includeMdc = true;

protected HashMap<String, String> customFields;

protected HashMap<String, String> fieldNames;

@JsonProperty
public void setHost(String host) {
this.host = host;
}

@JsonProperty
public String getHost() {
return host;
}

@JsonProperty
public void setPort(int port) {
this.port = port;
}

@JsonProperty
public int getPort() {
return port;
}

@JsonProperty
public boolean getIncludeCallerInfo() {
return includeCallerInfo;
}

@JsonProperty
public void setIncludeCallerInfo(boolean includeCallerInfo) {
this.includeCallerInfo = includeCallerInfo;
}

@JsonProperty
public boolean getIncludeContext() {
return includeContext;
}

@JsonProperty
public void setIncludeContext(boolean includeContext) {
this.includeContext = includeContext;
}

@JsonProperty
public boolean getIncludeMdc() {
return includeMdc;
}

@JsonProperty
public void setIncludeMdc(boolean includeMdc) {
this.includeMdc = includeMdc;
}

@JsonProperty
public HashMap<String, String> getCustomFields() {
return customFields;
}

@JsonProperty
public void setCustomFields(HashMap<String, String> customFields) {
this.customFields = customFields;
}

@JsonProperty
public HashMap<String, String> getFieldNames() {
return fieldNames;
}

@JsonProperty
public void setFieldNames(HashMap<String, String> fieldNames) {
this.fieldNames = fieldNames;
}

protected boolean includeCallerInfo = false;

protected boolean includeContext = true;

protected boolean includeMdc = true;

protected HashMap<String, String> customFields;

protected HashMap<String, String> fieldNames;

@JsonProperty
public boolean getIncludeCallerInfo() {
return includeCallerInfo;
}

@JsonProperty
public void setIncludeCallerInfo(boolean includeCallerInfo) {
this.includeCallerInfo = includeCallerInfo;
}

@JsonProperty
public boolean getIncludeContext() {
return includeContext;
}

@JsonProperty
public void setIncludeContext(boolean includeContext) {
this.includeContext = includeContext;
}

@JsonProperty
public boolean getIncludeMdc() {
return includeMdc;
}

@JsonProperty
public void setIncludeMdc(boolean includeMdc) {
this.includeMdc = includeMdc;
}

@JsonProperty
public HashMap<String, String> getCustomFields() {
return customFields;
}

@JsonProperty
public void setCustomFields(HashMap<String, String> customFields) {
this.customFields = customFields;
}

@JsonProperty
public HashMap<String, String> getFieldNames() {
return fieldNames;
}

@JsonProperty
public void setFieldNames(HashMap<String, String> fieldNames) {
this.fieldNames = fieldNames;
}
}
Loading