Disclaimer I have not tested this in openshift. I do not know what technical stack you use for your microservice.
Here's how I do it in a spring boot application (with a log) deployed to Kubernetes.
1. Use a logarithmic log for the log (this will record logs in Json format, which is more suitable for ELK)
I have a gradle dependency to enable this
compile "net.logstash.logback:logstash-logback-encoder:3.5"
Then configure LogstashEncoder as an encoder in the application, in logback- spring.groovy / logback- spring.xml (or logabck.xml)
2. Have multiple filters or libraries to write access logs
For 2. Either use
A. Use "net.rakugakibox.springbootext: spring-boot-ext-logback-access: 1.6" library
(This is what I use)
It gives in good json format as shown below.
{ "@timestamp":"2017-03-29T09:43:09.536-05:00", "@version":1, "@message":"0:0:0:0:0:0:0:1 - - [2017-03-29T09:43:09.536-05:00] \"GET /orders/v1/items/42 HTTP/1.1\" 200 991", "@fields.method":"GET", "@fields.protocol":"HTTP/1.1", "@fields.status_code":200, "@fields.requested_url":"GET /orders/v1/items/42 HTTP/1.1", "@fields.requested_uri":"/orders/v1/items/42", "@fields.remote_host":"0:0:0:0:0:0:0:1", "@fields.HOSTNAME":"0:0:0:0:0:0:0:1", "@fields.content_length":991, "@fields.elapsed_time":48, "HOSTNAME":"ABCD" }
OR
B. Use Tee Filter Log
OR
C. spring CommonsRequestLoggingFilter (not really verified)
Add bean definition
@Bean public CommonsRequestLoggingFilter requestLoggingFilter() { CommonsRequestLoggingFilter crlf = new CommonsRequestLoggingFilter(); crlf.setIncludeClientInfo(true); crlf.setIncludeQueryString(true); crlf.setIncludePayload(true); return crlf; }
Then set org.springframework.web.filter.CommonsRequestLoggingFilter to DEBUG, this can be done using application.properties by adding:
logging.level.org.springframework.web.filter.CommonsRequestLoggingFilter=DEBUG
so-random-dude
source share