Introduction
The D7 SDK Logging library provides a flexible and efficient logging system for applications. It allows developers to add detailed logging capabilities with minimal overhead, supporting multiple log levels, destinations, and formatting options.
Key Features
- Multiple log levels (TRACE, DEBUG, INFO, WARNING, ERROR, CRITICAL)
- Customizable log formatting
- File and console output
- Runtime log level configuration
- Module-based logging control
Basic Usage
Here's a simple example of using the logging library:
#include <iostream>
using namespace vsdk::diag;
int main() {
nlohmann::json config = {
{"enabled", true},
{"pattern", "[%H:%M:%S.%e] [%^%l%$] %v"},
{"level", "info"},
{"console_output", true},
{"enabled_modules", {"system"}}
};
int count = 42;
try {
} catch (const std::exception& e) {
}
return 0;
}
static log * instance()
Get a pointer to the singleton instance.
@ system
System module.
Definition log.h:39
@ network
Network module.
Definition log.h:40
#define LOG_ERROR(module,...)
Produce a log at the ERROR level.
Definition log.h:313
#define LOG_DEBUG(module,...)
Produce a log at the DEBUG level.
Definition log.h:280
#define LOG_INFO(module,...)
Produce a log at the INFO level.
Definition log.h:291
Main Components
Configuration
The logging system can be configured through a JSON file or directly via the API. Configuration options include:
{
"enabled": true, // Master enable/disable switch
"pattern": "[%H:%M:%S.%e] [%^%l%$] [%s:%# %!] %v", // Log format pattern
"level": "trace", // Global minimum log level
"console_output": false, // Enable/disable console output
"log_file": "/appdata/logs/vsdk.log", // Path to the log file
"enabled_modules": [ // List of enabled modules
"analog",
"digital_in",
"digital_out",
"pwm_in",
"pwm_out",
"system",
"network"]
}