Chapter 17. Monitoring and troubleshooting errors with logging

 

This chapter covers

  • Understanding the components of a log message
  • Writing logs to multiple output locations
  • Controlling log verbosity in different environments using filtering
  • Using structured logging to make logs searchable

Logging is one of those topics that seems unnecessary, right up until the point when you desperately need it! There’s nothing more frustrating than finding an issue that you can only reproduce in production, and then discovering there are no logs to help you debug it.

Logging is the process of recording events or activities in an app and often involves writing a record to a console, a file, the Windows Event Log, or some other system. You can record anything in a log message, though there are generally two different types of message:

  • Informational messagesA standard event occurred: a user logged in, a product was placed in a shopping cart, or a new post was created on a blogging app.
  • Warning and errorsAn error or unexpected condition occurred: a user had a negative total in the shopping cart, or an exception occurred.

Historically, a common problem with logging in larger applications was that each library and framework would generate logs in a slightly different format, if at all. When an error occurred in your app and you were trying to diagnose it, this inconsistency made it harder to connect the dots in your app to get the full picture and understand the problem.

17.1. Using logging effectively in a production app

 
 
 

17.2. Adding log messages to your application

 
 

17.3. Controlling where logs are written using logging providers

 
 

17.4. Changing log verbosity with filtering

 
 
 

17.5. Structured logging: creating searchable, useful logs

 
 
 
 

Summary

 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage