📦 Studio Log
v1.5 released
Now serializing error codes
and causing exceptions
Studio Log is the tiny ndjson logger that JavaScript Studio uses in the CLI and on the server. The open source library comes with the emojilog
pretty printer and it just received a little feature update to provide more information when serializing errors.
Error codes
It’s a common convention to put a code
property on an error object with an enum-style string. For example, the Studio JSON Request library uses the error code E_JSON
if the response could not be parsed, and E_EXPECT
to signal that the response status code does not meet the expectation. When handling an error, this information can be used to react accordingly.
While the error message hopefully explains what the issue is, having the error code in a machine readable structure has some advantages. It allows to apply queries or run statistics on the log data. With the latest release, Studio Log adds this information to the ndjson log entry automatically:
log.error('Oh noes!', err);
As an example, AWS CloudWatch allows you to filter logs with a query like this:
{ $.topic = "error" && $.data.code = "E_EXPECT" }
Error cause
Together with error code support, Studio Log is now also aware of cause
properties on errors. If a cause
is found, it’s stack is added to the log output. Consider a source file called stacks.js
with this content:
Running it with node stacks.js | emojilog --stack
shows this output:
More information
Check out the refreshed setup instructions and API docs in the project README. If you like the tiny logger, please leave a star on the GitHub repository.
Thanks for reading and happy logging!