pdcomm::modbus::DiagnosticLogging
Class
Static functions that configure, inspect and flush the optional JSON Lines diagnostic log of the Modbus library.
class DiagnosticLoggingLogging is off by default. All functions are thread-safe.
Enable debug logging around a command, then turn it off (examples/diagnostics/modbus/logging.cpp):
pdcomm::modbus::DiagnosticLogging::configure(argv[1]);
pdcomm::modbus::Endpoint endpoint;
std::cout << endpoint.call(R"({"action":"execute","pdu":[6,0,0,0,42]})") << '\n';
pdcomm::modbus::DiagnosticLogging::flush();
std::cout << pdcomm::modbus::DiagnosticLogging::status() << '\n';
pdcomm::modbus::DiagnosticLogging::configure(R"({"enabled":false})");Members
configure
Method
Applies a logging configuration.
static void configure(const std::string &json)Parameters
| Name | Description |
|---|---|
json | UTF-8 JSON object with the optional members enabled, level, file, max_bytes, files and forensics, as described for pdcomm_modbus_logging_configure(). For example {"level":"debug","file":"modbus.jsonl"}. |
Notes
- Throws
std::runtime_error: if the configuration is empty, invalid, larger than 16384 bytes or its log file cannot be opened. The previous configuration stays active.
flush
Method
Waits up to two seconds until queued records are written.
static void flush()Notes
- Throws
std::runtime_error: if the flush cannot be queued, is not confirmed within two seconds or the write fails.
status
Method
Returns the logging status as JSON.
static std::string status()Returns
Status JSON with the active configuration and the written, dropped, write_errors and configuration_errors counters.
Notes
- Throws
std::runtime_error: if the status cannot be read, including a status longer than the 4096-byte buffer this function uses.