Skip to content
Start free evaluation

pdcomm_modbus_logging_configure

Function

Configures the optional diagnostic log of this library.

int32_t pdcomm_modbus_logging_configure(const uint8_t *input, size_t size)

Declared in: #include <pdcomm/modbus/pdcomm_modbus.h>

Logging is off by default and is local to the Modbus library; the SECS/GEM library has its own control. Records are written asynchronously as JSON Lines through a bounded queue, so a full queue drops records instead of blocking protocol calls. Payload bytes are never logged.

The configuration is a JSON object with these optional members:

  • enabled (boolean, default true): false turns logging off.
  • level: "error", "warn", "info" (default), "debug" or "trace".
  • file (string or null): log file path; null or absent writes to stderr.
  • max_bytes (default 10 MiB): rotation size, 8192 bytes to 1 GiB.
  • files (default 3): number of retained files, 1 to 16.
  • forensics (boolean, default false): adds periodic process samples; requires the debug or trace level.

Unknown members are rejected. The PDCOMM_LOG (a level name or off), PDCOMM_LOG_FILE, PDCOMM_LOG_MAX_BYTES, PDCOMM_LOG_FILES and PDCOMM_LOG_FORENSICS environment variables supply an initial configuration the first time the library uses its logger.

Parameters

NameDescription
inputUTF-8 JSON configuration; read during the call only.
sizeSize of input in bytes, 1 to 16384.

Returns

#PDCOMM_MODBUS_OK, #PDCOMM_MODBUS_INVALID_INPUT for a null or oversized input, invalid JSON, an invalid option or a log file that cannot be opened, or #PDCOMM_MODBUS_INTERNAL_ERROR.

Notes

  • Thread-safe. A configuration that fails validation leaves the previous one active and increments configuration_errors in the status. Waits up to two seconds for the log writer to apply it.