Fork me on GitHub

I'm running Pedestal under Elastic Beanstalk. Is there a way to configure the Logback logger to emit CloudWatch-friendly JSON?


I've found this: which seems to be what I want but I'm not certain if that's the level of abstraction I should be using.


I'd also like to enhance the logs with various other stuff (e.g. Host, user-id, etc etc)


I saw that I can do something like :io.pedestal.log/formatter cheshire/encode when calling io.pedestal.log/log, and cloudwatch is smart enough to pick that JSON up


But not in insights, sigh. Perhaps it's better if the whole log is JSON (as opposed to prefixed by other logback things)


@orestis I’ve not used the logback-awslogs-json-encoder lib but if you do produce JSON formatted logs and use io.pedestal.log/log with a JSON formatter, then your log message will be a string albeit in JSON format. You could parse that string in CloudWatch Insights using the parse function it provides in order to create virtual fields which can be filtered on. That being said, info like Host, user-id seems better suited for MDC usage. You can use Pedestal’s io.pedestal.log/with-context impl to set a map of data in the MDC but it will be a single value under the io.pedestal key. You could format as JSON and parse as I described above, though. Alternatively, you can use the MDC directly. All values put into the MDC become separate fields prefixed by mdc in Insights which makes log analysis easy.