pedestal

orestis 2019-11-08T12:41:17.064500Z

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

orestis 2019-11-08T12:42:01.065Z

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.

orestis 2019-11-08T12:42:19.065600Z

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

orestis 2019-11-08T14:22:50.066300Z

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

orestis 2019-11-08T14:30:35.067100Z

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

2019-11-08T17:34:55.072500Z

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