Fork me on GitHub
#pedestal
<
2019-11-08
>
orestis12:11:17

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

orestis12:11:01

I've found this: https://github.com/osiegmar/logback-awslogs-json-encoder which seems to be what I want but I'm not certain if that's the level of abstraction I should be using.

orestis12:11:19

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

orestis14:11:50

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

orestis14:11:35

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

ddeaguiar17:11:55

@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.