We recently configured some applications to log with log4j's SocketAppender to Logstash.
When we startet to add MDC-Attributes we sometimes lost the connection:
| Error log4j:WARN Detected problem with connection: java.net.SocketException: (broken pipe)
In Groovy/Grails I am used to the automatic toString()-Conversion. So Logstash was not able to convert my MDC-Attribute-Object to a string.
The solution is to ensure that the MDC-Attributes are plain strings.
Old code:
MDC.put("user", request.sopUser?:"anonymous");
New Code:
MDC.put("user", request.sopUser?.toString()?:"anonymous");