Fix inconsistent client disconnect log format

This commit is contained in:
Roger A. Light
2026-02-03 00:19:59 +00:00
parent 750c0f44d8
commit 3c45da8d7e
2 changed files with 26 additions and 26 deletions
+25 -25
View File
@@ -318,87 +318,87 @@ void do_disconnect(struct mosquitto *context, int reason)
case MOSQ_ERR_SUCCESS:
break;
case MOSQ_ERR_MALFORMED_PACKET:
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] disconnected due to malformed packet.", id, context->address, context->remote_port);
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] disconnected: malformed packet.", id, context->address, context->remote_port);
break;
case MOSQ_ERR_PROTOCOL:
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] disconnected due to protocol error.", id, context->address, context->remote_port);
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] disconnected: protocol error.", id, context->address, context->remote_port);
break;
case MOSQ_ERR_CONN_LOST:
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] closed its connection.", id, context->address, context->remote_port);
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] disconnected: connection closed by client.", id, context->address, context->remote_port);
break;
case MOSQ_ERR_AUTH:
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] disconnected, not authorised.", id, context->address, context->remote_port);
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] disconnected: not authorised.", id, context->address, context->remote_port);
break;
case MOSQ_ERR_KEEPALIVE:
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] has exceeded timeout, disconnecting.", id, context->address, context->remote_port);
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] disconnected: exceeded timeout.", id, context->address, context->remote_port);
break;
case MOSQ_ERR_OVERSIZE_PACKET:
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] disconnected due to oversize packet.", id, context->address, context->remote_port);
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] disconnected: oversize packet.", id, context->address, context->remote_port);
break;
case MOSQ_ERR_PAYLOAD_SIZE:
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] disconnected due to oversize payload.", id, context->address, context->remote_port);
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] disconnected: oversize payload.", id, context->address, context->remote_port);
break;
case MOSQ_ERR_NOMEM:
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] disconnected due to out of memory.", id, context->address, context->remote_port);
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] disconnected: out of memory.", id, context->address, context->remote_port);
break;
case MOSQ_ERR_NOT_SUPPORTED:
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] disconnected due to using not allowed feature (QoS too high, retain not supported, or bad AUTH method).", id, context->address, context->remote_port);
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] disconnected: used disallowed feature (QoS too high, retain not supported, or bad AUTH method).", id, context->address, context->remote_port);
break;
case MOSQ_ERR_ADMINISTRATIVE_ACTION:
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] been disconnected by administrative action.", id, context->address, context->remote_port);
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] disconnected: administrative action.", id, context->address, context->remote_port);
break;
case MOSQ_ERR_ERRNO:
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] disconnected: %s.", id, context->address, context->remote_port, strerror(errno));
break;
case MOSQ_ERR_RECEIVE_MAXIMUM_EXCEEDED:
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] disconnected due to exceeding the receive maximum.", id, context->address, context->remote_port);
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] disconnected: receive maximum exceeded.", id, context->address, context->remote_port);
break;
case MOSQ_ERR_IMPLEMENTATION_SPECIFIC:
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] disconnected, implementation specific error.", id, context->address, context->remote_port);
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] disconnected: implementation specific error.", id, context->address, context->remote_port);
break;
case MOSQ_ERR_CLIENT_IDENTIFIER_NOT_VALID:
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] disconnected, client identifier not valid.", id, context->address, context->remote_port);
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] disconnected: client identifier not valid.", id, context->address, context->remote_port);
break;
case MOSQ_ERR_BAD_USERNAME_OR_PASSWORD:
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] disconnected, bad username or password.", id, context->address, context->remote_port);
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] disconnected: bad username or password.", id, context->address, context->remote_port);
break;
case MOSQ_ERR_SERVER_UNAVAILABLE:
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] disconnected, server unavailable.", id, context->address, context->remote_port);
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] disconnected: server unavailable.", id, context->address, context->remote_port);
break;
case MOSQ_ERR_SERVER_BUSY:
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] disconnected, server busy.", id, context->address, context->remote_port);
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] disconnected: server busy.", id, context->address, context->remote_port);
break;
case MOSQ_ERR_BANNED:
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] disconnected, client banned.", id, context->address, context->remote_port);
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] disconnected: client banned.", id, context->address, context->remote_port);
break;
case MOSQ_ERR_BAD_AUTHENTICATION_METHOD:
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] disconnected, bad authentication method.", id, context->address, context->remote_port);
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] disconnected: bad authentication method.", id, context->address, context->remote_port);
break;
case MOSQ_ERR_QUOTA_EXCEEDED:
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] disconnected, quota exceeded.", id, context->address, context->remote_port);
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] disconnected: quota exceeded.", id, context->address, context->remote_port);
break;
case MOSQ_ERR_CONNECTION_RATE_EXCEEDED:
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] disconnected, connection rate exceeded.", id, context->address, context->remote_port);
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] disconnected: connection rate exceeded.", id, context->address, context->remote_port);
break;
case MOSQ_ERR_SESSION_TAKEN_OVER:
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] disconnected, session taken over.", id, context->address, context->remote_port);
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] disconnected: session taken over.", id, context->address, context->remote_port);
break;
case MOSQ_ERR_TOPIC_ALIAS_INVALID:
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] disconnected, topic alias invalid.", id, context->address, context->remote_port);
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] disconnected: topic alias invalid.", id, context->address, context->remote_port);
break;
case MOSQ_ERR_HTTP_BAD_ORIGIN:
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] disconnected, non-matching http origin.", id, context->address, context->remote_port);
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] disconnected: non-matching http origin.", id, context->address, context->remote_port);
break;
case MOSQ_ERR_PROXY:
/* This was a proxy v2 health check connection, so don't report */
break;
default:
log__printf(NULL, MOSQ_LOG_NOTICE, "Bad socket read/write on client %s [%s:%d]: %s", id, context->address, context->remote_port, mosquitto_strerror(reason));
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] disconnected: bad socket read/write: %s", id, context->address, context->remote_port, mosquitto_strerror(reason));
break;
}
}else{
if(reason == MOSQ_ERR_ADMINISTRATIVE_ACTION){
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] been disconnected by administrative action.", id, context->address, context->remote_port);
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] disconnected: administrative action.", id, context->address, context->remote_port);
}else{
log__printf(NULL, MOSQ_LOG_NOTICE, "Client %s [%s:%d] disconnected.", id, context->address, context->remote_port);
}
@@ -92,5 +92,5 @@ data = b"\xC0\x00\x02\x05" + b"\x00\x00\x00\x00" + b"\x18\x83" + b"\x00\x00" \
+ b"\x21" \
+ b"\x00\x07" \
+ b"\x54\x4C\x53\x76\x31\x2E\x33"
expect_log = "Client proxy-test disconnected, not authorised."
expect_log = "Client proxy-test [192.0.2.5:6275] disconnected: not authorised."
do_test(data, expect_log)