Structuring log messages

Log messages are often used as plain strings via console.log or print statements. These quick and dirty additions to code can be helpful during development but won't suffice in a production-level system. Rather than logging flat strings, log statements need to be structured so that you can easily find the bits of information you're looking for. JSON is an excellent choice for a format since it's widely used among different log aggregator services and easy to implement in practically any language.

Let's take the simple case of our previous divide function. At some point, we may want to understand how people are using our service: specifically, what numerator and denominators they're sending us. To do this, we will ...

Get Serverless Design Patterns and Best Practices now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.