[knx] Improve logging for serial gateways (#17793)

* Logger in SerialAdapter respects the log setting for the binding.
* Additional warning if open port is detected.

Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
This commit is contained in:
Holger Friedrich 2024-11-24 10:19:33 +01:00 committed by GitHub
parent 336875797b
commit 7b1c44547e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -74,7 +74,7 @@ public class SerialTransportAdapter implements SerialCom {
if (portId == null) {
throw new IOException("Port not available");
}
logger = LoggerFactory.getLogger("SerialTransportAdapter:" + portId);
logger = LoggerFactory.getLogger(SerialTransportAdapter.class.getName() + ":" + portId);
final @Nullable SerialPortManager tmpSerialPortManager = serialPortManager;
if (tmpSerialPortManager == null) {
@ -83,6 +83,10 @@ public class SerialTransportAdapter implements SerialCom {
try {
SerialPortIdentifier portIdentifier = tmpSerialPortManager.getIdentifier(portId);
if (portIdentifier != null) {
if (portIdentifier.isCurrentlyOwned()) {
logger.warn("Configured port {} is currently in use by another application: {}", portId,
portIdentifier.getCurrentOwner());
}
logger.trace("Trying to open port {}", portId);
SerialPort serialPort = portIdentifier.open(this.getClass().getName(), OPEN_TIMEOUT_MS);
// apply default settings for com port, may be overwritten by caller