Log Levels

Log Levels

Introduction

Logging levels categorise the severity of messages logged in software applications. They allow developers to filter and prioritise logs, making identifying and troubleshooting problems easier.

Common Log Levels

  1. TRACE: The most detailed level, used for tracing the execution of the application and identifying specific points of interest.
  2. DEBUG: Used for logging non-critical information during the development phase, such as setting up and configuring the application.
  3. INFO: Used for logging general information about the application’s operation, such as user activity, database connections, and application events.
  4. WARN: Used for logging potential issues that may not cause the application to crash but could indicate problems or potential issues.
  5. ERROR: Used for logging critical errors that prevent the application from functioning as intended.
  6. FATAL: The most severe level, used for logging errors that cause the application to crash or terminate unexpectedly.

Interpreting Log Levels

  • TRACE: Usually not logged in production environments due to its high volume.
  • DEBUG: Rarely logged in production environments unless explicitly enabled for debugging purposes.
  • INFO: Frequently logged in production environments to provide insights into application behaviour.
  • WARN: Can be logged in production environments to notify developers of potential issues or configuration problems.
  • ERROR: Should be logged in production environments for errors that prevent the application from functioning correctly.
  • FATAL: Must be logged in production environments for errors that cause the application to crash or terminate.

Choosing Log Levels

The choice of log levels depends on the specific application and its requirements. For production environments, it’s generally recommended to log at the INFO level and selectively log DEBUG, WARN, and ERROR levels for specific events or conditions.

Using log levels appropriately allows developers to effectively capture helpful information for debugging, monitoring, and optimizing their applications.

Stephen

Hi, my name is Stephen Finchett. I have been a software engineer for over 30 years and worked on complex, business critical, multi-user systems for all of my career. For the last 15 years, I have been concentrating on web based solutions using the Microsoft Stack including ASP.Net, C#, TypeScript, SQL Server and running everything at scale within Kubernetes.