libdoip  0.1.0
DoIP (Diagnostics over Internet Protocol) ISO 13400 C++17 Library
Logging in libdoip

This library uses spdlog for high-performance logging.

Features

  • High Performance: spdlog is one of the fastest C++ logging libraries
  • Thread Safe: All logging operations are thread-safe
  • Multiple Log Levels: TRACE, DEBUG, INFO, WARN, ERROR, CRITICAL
  • Formatted Output: Support for fmt-style formatting
  • Configurable Patterns: Customize log message format
  • Color Support: Colored console output for better readability

Usage

Basic Logging

#include "Logger.h"
// Different log levels
LOG_DOIP_TRACE("Detailed trace information");
LOG_DOIP_DEBUG("Debug information");
LOG_DOIP_INFO("General information");
LOG_DOIP_WARN("Warning message");
LOG_DOIP_ERROR("Error occurred");
LOG_DOIP_CRITICAL("Critical error");
#define LOG_DOIP_CRITICAL(...)
Definition: Logger.h:129
#define LOG_DOIP_WARN(...)
Definition: Logger.h:127
#define LOG_DOIP_ERROR(...)
Definition: Logger.h:128
#define LOG_DOIP_TRACE(...)
Definition: Logger.h:124
#define LOG_DOIP_INFO(...)
Definition: Logger.h:126
#define LOG_DOIP_DEBUG(...)
Definition: Logger.h:125

Formatted Logging

#include "Logger.h"
int port = 13400;
std::string interface = "eth0";
LOG_DOIP_INFO("DoIP server starting on interface '{}' port {}", interface, port);
// Works with any type that supports fmt formatting
auto timestamp = std::chrono::system_clock::now();
LOG_DOIP_DEBUG("Connection established at {}", timestamp);

Configuration

#include "Logger.h"
// Set log level (only messages at this level or higher will be shown)
doip::Logger::setLevel(spdlog::level::debug);
// Set custom pattern
doip::Logger::setPattern("[%H:%M:%S] [%^%l%$] %v");
// Available levels: trace, debug, info, warn, err, critical, off
static void setLevel(spdlog::level::level_enum level)
Definition: Logger.h:95
static void setPattern(const std::string &pattern)
Definition: Logger.h:99

Pattern Format

The default pattern is: [Y-m-d H:M:S.e] [n] [%^l%$] v

Common pattern flags:

  • Y - Year (4 digits)
  • m - Month (01-12)
  • d - Day (01-31)
  • H - Hour (00-23)
  • M - Minute (00-59)
  • S - Second (00-59)
  • e - Milliseconds (000-999)
  • n - Logger name
  • l - Log level
  • %^ - Start color range
  • %$ - End color range
  • v - The actual message