[WIP] Set up logging and alerting with CloudWatch - #20
wagnerlmichael wants to merge 5 commits into
Conversation
| # Log records are built from the named arguments passed to the logging call, | ||
| # so every call should pass a `msg` plus any other fields worth recording | ||
| logger::log_formatter(logger::formatter_json) | ||
| logger::log_layout(logger::layout_json_parser(fields = c("time", "level"))) |
There was a problem hiding this comment.
Are time and level the layout fields that we want?
| # The layout above always writes `time` and then `level` as the first two | ||
| # fields of the record, so we can route on the level without parsing the JSON | ||
| appender_split_by_level <- function(lines) { | ||
| is_error <- grepl('^\\{"time":"[^"]*","level":"(ERROR|FATAL)"', lines) |
There was a problem hiding this comment.
This grepl grabs the error and fatal levels. I'm curious if this is what you meant by
Emit errors to stderr with full traceback and an ERROR log level
In my crash course on logging, I see that these are the different levels: docs. Are error and fatal levels that are typically routed to stderr instead of stdout?
From what I can tell this split doesn't actually impact anything, and that if we removed the split it would land in cloudwatch the same, what do you think?
| @@ -0,0 +1,86 @@ | |||
| # Logging setup and helpers for the API. Every log record is a single line of | |||
| # JSON so that CloudWatch (or any other log consumer) can parse its fields. | |||
There was a problem hiding this comment.
There is a formatter, layout, appender anatomy https://daroczig.github.io/logger/articles/anatomy.html
| } | ||
|
|
||
| # Plumber error handler. Mirrors the response produced by plumber's default | ||
| # handler (plumber:::defaultErrorHandler) but replaces its print(err) with a |
There was a problem hiding this comment.
[WIP]