Veethree D7 SDK
Loading...
Searching...
No Matches
Logging library

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 <log/log.h>
#include <iostream>
using namespace vsdk::diag;
int main() {
// Create basic log configuration
nlohmann::json config = {
{"enabled", true},
{"pattern", "[%H:%M:%S.%e] [%^%l%$] %v"},
{"level", "info"},
{"console_output", true},
{"enabled_modules", {"system"}}
};
// Initialize logging, this step is not required if you use the default configuration (/appdata/config/vsdk.json)
log::instance()->load_config_json(config);
// Log messages at different levels
LOG_INFO(module::system, "Application started");
LOG_DEBUG(module::network, "Debug information"); // This will not be logged because it's not in the enabled modules
// Add some values
int count = 42;
LOG_INFO(module::system, "Processing {} items", count);
// Error handling
try {
// Some operation
} catch (const std::exception& e) {
LOG_ERROR(module::system, "Error occurred: {}", e.what());
}
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
Logging interface.
#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"]
}