What Are the Different Log Levels Supported by spdlog? A Complete Guide

spdlog defines seven distinct log levels—trace, debug, info, warn, err, critical, and off—through the level::level_enum enumeration in include/spdlog/common.h, allowing granular control over logging verbosity.

The gabime/spdlog library provides a robust severity-based filtering system centered around these log levels. According to the spdlog source code, the enumeration declared at lines 47–55 of include/spdlog/common.h serves as the foundation for all logging threshold decisions, from individual loggers to specific output sinks.

The Seven Log Levels Defined in common.h

The heart of spdlog's severity system resides in the level::level_enum definition. This scoped enumeration assigns integer values to each severity level and provides the basis for compile-time constants like SPDLOG_LEVEL_TRACE.

Understanding level::level_enum

In include/spdlog/common.h (lines 47–55), the enum declares the following levels in ascending order of severity:

  • trace – Detailed debugging information for tracing execution flow; the lowest severity level.
  • debug – General debugging messages useful during development.
  • info – Normal operational messages indicating the application is functioning as expected.
  • warn – Potentially harmful conditions that do not prevent execution.
  • err – Error events that might still allow the application to continue running but require attention.
  • critical – Severe error events that will likely lead to application failure or termination.
  • off – Special level that disables all logging output.

The enumeration also defines n_levels as a sentinel value for internal bounds checking, ensuring level values remain valid throughout the API.

Configuring Log Levels in Your Application

The library exposes log level configuration through two primary interfaces: the spdlog::logger class for per-logger filtering and the spdlog::sinks::sink base class for per-sink granularity.

Setting the Logger Threshold

Use spdlog::logger::set_level(level::level_enum) to establish the minimum severity a logger will process. Messages below this threshold are silently discarded.

#include <spdlog/spdlog.h>

int main() {
    auto console = spdlog::stdout_color_mt("console");
    
    // Only process warnings and above
    console->set_level(spdlog::level::warn);
    
    // These are filtered out
    console->trace("trace message – not shown");
    console->debug("debug message – not shown");
    console->info("info message – not shown");
    
    // These appear in output
    console->warn("warning message");
    console->error("error message");
    console->critical("critical failure");
    
    // Disable logging entirely
    console->set_level(spdlog::level::off);
    console->error("this will never be printed");
}

Per-Sink Filtering

For advanced scenarios, spdlog::sinks::sink::set_level(level::level_enum) allows different outputs to respect different thresholds. This enables patterns like verbose file logging while restricting console output to warnings.

auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>("app.log");
auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();

file_sink->set_level(spdlog::level::trace);   // Log everything to file
console_sink->set_level(spdlog::level::warn); // Only warnings and above to console

spdlog::logger logger("multi", {file_sink, console_sink});
logger.info("info goes to file, not console");
logger.warn("warning goes to both");

String Representations and Character Codes

Beyond numeric values, spdlog provides human-readable names through spdlog::level::to_string_view, mapping each level to its textual name (e.g., "trace", "debug"). Additionally, single-character codes (e.g., "T", "D") are defined in include/spdlog/common.h (lines 58–79) for compact logging formats. These string conversions facilitate log parsing and formatted output without requiring manual switch statements.

Summary

  • spdlog supports seven log levels: trace, debug, info, warn, err, critical, and off, defined in include/spdlog/common.h at lines 47–55.
  • Configuration occurs at two levels: Use spdlog::logger::set_level() for logger-wide filtering or spdlog::sinks::sink::set_level() for individual sink control.
  • The off level completely disables logging output by setting the threshold above critical.
  • String utilities like to_string_view provide human-readable level names and single-character abbreviations as implemented in the source.

Frequently Asked Questions

What is the default log level in spdlog?

By default, spdlog initializes loggers to the info level, meaning debug and trace messages are suppressed unless explicitly configured otherwise via set_level().

How do I disable logging completely in spdlog?

Set the logger or sink level to spdlog::level::off. This special level, defined in the level_enum at include/spdlog/common.h, ensures no messages are processed regardless of their severity.

Can I set different log levels for different sinks in spdlog?

Yes. As implemented in include/spdlog/sinks/sink.h, each sink maintains its own level threshold via set_level(). Create a spdlog::logger with multiple sinks, then configure each sink independently to route different severity levels to different destinations.

What is the difference between err and critical log levels?

According to the spdlog source code, err indicates error conditions that may allow the application to continue, while critical represents severe failures that may cause the application to abort. Both are filtered if the threshold is set above them, but critical typically warrants immediate attention.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →