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)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, defaulttrue):falseturns logging off.level:"error","warn","info"(default),"debug"or"trace".file(string ornull): log file path;nullor 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, defaultfalse): adds periodic process samples; requires thedebugortracelevel.
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
| Name | Description |
|---|---|
input | UTF-8 JSON configuration; read during the call only. |
size | Size 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_errorsin the status. Waits up to two seconds for the log writer to apply it.