Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I recently added an optional JSON log format so that our logs would be more useful in places like AWS CloudWatch (which has powerful search and filtering options if you send it JSON).
However, in my initial attempt the JSON logs just looked like this:
or sometimes like this:
...with an opaque (to a JSON parser) blob of EDN inside the
"message"
value.But then I had a 💡! If we're just sending JSON to CloudWatch, couldn't we send arbitrary data serialized as JSON too and then be able to search and filter based on our own domain concepts?
So I started searching around and I discovered a) yes, yes we can and b) this is apparently called "structured logging" (I was today years old when I learned...).
And thus here it is. This PR does a few things:
FDB_LOG_FORMAT=json
). Note that its a good idea to wrap the data in a map w/ a namespaced key like in those examples b/c they get merged into the JSON object w/ all of the logging-related keys (e.g."message"
,"timestamp"
, etc.).%mdc
in our default text logging patterns that will contain any data we log out w/ the cambium logging fns. Note that by default these get formatted in akey=val
pattern in the logs. If you want to retain thepr-str
EDN format, you can just keep using the fluree.db.util.log fns instead (but then you don't get the JSON goodness in environments that can process it like CloudWatch!).pr-str
from cambium too.%mdc
thingy stands for Mapped Diagnostic Context and it is something built into logback for this purpose. That highfalutin name tho. Java devs, man...So what good is this? Well I could imagine a few ways we could put it to use:
jq
.Oh right, how about an example JSON structured log message:
outputs this in JSON logging mode (prettified with
jq
):