Closed jmorrispa closed 6 years ago
I found an answer. In order to access properties field in ElasticsearchAppender using logback.groovy use component.properties, Ex:
appender("ELASTIC", ElasticsearchAppender){
ElasticsearchProperties e = new ElasticsearchProperties()
e.addProperty( new Property("logger", '%logger', false ))
e.addProperty( new Property("host", System.getenv("HOSTNAME"), false ))
component.properties = e
url = 'http://localhost:9200/_bulk'
index = 'app-logs-%date{yyyy-MM-dd}'
type = 'log'
rawJsonMessage = false
errorsToStderr = true
includeCallerData = true
def configHeaders = new HttpRequestHeaders()
configHeaders.addHeader(new HttpRequestHeader(name: 'Content-Type', value: 'application/x-ndjson'))
headers = configHeaders
}
I'm trying to set AbstractElasticsearchAppender.elasticsearchProperties from logback.groovy but the method AbstractElasticsearchAppender.setProperties(...) is never called.
Appender configuration is:
I can see logs sent to elasticsearch, but the logger property is not there.
Using logback.xml configuration works fine.
I tried using a property name other that "properties" like this:
With that code and using props instead of properties it works :(
I attached a sample with both groovy and xml logback configurations where you can see that setting "properties" from logback.groovy is not working.
@balopat I will really appreciate if you can replicate and confirm this issue since this is a bit weird.
sample.zip