Fundamentals for good logging

Patrick Wiseman
CEO and Founder

When it comes to building your product, it’s easy for logging to fall by the wayside, but the truth is logging should never be an afterthought.

Good logging is critical to powering business intelligence and it can make all the difference in troubleshooting by providing the information needed to detect mistakes, review security measures and provide overall context on why developers made certain moves.

With that in mind, it’s important to understand the fundamentals for good logging, including the differences between basic and structured logging, uses for logging and best practices for using logs based on your desired outcomes. Let’s dive in.

Basic vs. structured logging: what’s the difference?

First, let’s cover two types of logging: Basic logging and structured logging.

Basic logging is meant to be human readable. The goal of basic logging is to make it easy for anyone to read through logs to gain insights into how the system or code operates for purposes like debugging or accessing certain information. Basic logging offers a good entry point to evaluate the health of individual software systems and pull analytics for those systems.

Structured logging applies a standard definition to how each log gets formatted. For example, this covers elements like what fields are included in the logs and impacts everything from system analyses to business outcomes. Essentially, structured logging applies a standard format for what’s included in each log that affects what you can get out of the information. Structured logging is important for sharing information with business intelligence tools.

Diving deeper, structured logging typically includes log levels to easily group different types of information. These log levels are as follows:

Uses for logging: how can you apply the information?

Logs provide information that can feed into everything from executive dashboards to business intelligence tools. In most cases where you apply information from logs into other systems, it makes sense to use structured logging, as this allows you to get specific about what you want to analyze.

For instance, a common piece of information startups want to know is how many users were active in the last month. You can easily get a count for monthly active users by building a structured log that looks at when user IDs log in and then sharing that information with a business intelligence tool to track how that number trends over time and to ensure unique IDs only get counted once.

Meanwhile, at Spaceship, one of our top level metrics is customer deliveries, so a lot of our logging and analytics look at delivery trends through the Spaceship platform. This includes sharing structured log data with business intelligence tools to look at elements like increases in deliveries through the platform over time and the number of error rates per delivery.

In general, this type of relationship between a structured log and a business intelligence tool is extremely helpful for B2B SaaS companies that want to use time as a dimension for analysis.

Best practices for logging: how should you set up your logs?

Once you have a goal in mind, how should you set up your logs? There are several pieces of information that make for the most useful logs:

Of course these are just examples of many options that exist for information to include in logs. No matter what information you include, if you have structured logs, you should only have a single metric per line. Keeping each line to a single metric gives you flexibility to filter across log lines, for instance in cases where you want to filter by things like who got what message when. This structure is also important for business intelligence tools, as you can’t slice and dice the data in these tools if you have several facts presented in each log line.

Why good logging matters

Overall, good logging is fundamental to having business intelligence tools that work well. It’s also extremely helpful when it comes to debugging issues. While there’s a lot that goes into logging, what works best for your team will come down to defining the dimensions you want to analyze and then mapping that information appropriately to logs.

Interested in learning more about how good logging can help your team and what it takes to get started? Contact Spaceship today to learn how we can help.

Want to be first in line to get early access to Spaceship?

Be the first to know when we launch! Sign up for our waiting list below: