When I create an ApplicationLoadBalancedFargateService with a Firelens logdriver, and the application writes JSON lines as the log message, such as when using net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder with Logback, the log messages are displayed in my logging repository (ex. Sumo Logic), as an escaped string, like:
How can I get the log messages to save as parsed JSON?
After scanning CDK source code, browsing several related references (which I will provide links for to help direct appropriate traffic here), and using
cdk diff
until the only change was to enable json parsing, I was able to make is work as shown in the following code. The key here is the use of theaddFirelensLogRouter
method and the Firelens config contained therein.TaskDefinition
code does not automatically create aLogRouter
container, if the task definition already contains one, which is what allows us to override the default behavior.Resources: