Skip to content

Commit

Permalink
Better Log Messages (#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
pglombardo authored May 6, 2024
1 parent af79b77 commit 6158c9b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Source/HiveMQtt/Client/HiveMQClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public async Task<bool> DisconnectAsync(DisconnectOptions? options = null)
{
if (this.ConnectState != ConnectState.Connected)
{
Logger.Warn("DisconnectAsync: Client is not connected.");
Logger.Warn("DisconnectAsync called but this client is not connected. State is ${this.ConnectState}.");
return false;
}

Expand Down Expand Up @@ -343,7 +343,7 @@ public async Task<SubscribeResult> SubscribeAsync(SubscribeOptions options)
}
catch (TimeoutException)
{
Logger.Error("Subscribe timeout. No response received in time.");
Logger.Error("Subscribe timeout. No SUBACK response received in time.");
throw;
}
finally
Expand Down
4 changes: 2 additions & 2 deletions Source/HiveMQtt/Client/HiveMQClientOptionsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,12 @@ public HiveMQClientOptionsBuilder WithClientCertificate(string clientCertificate
}
catch (UnauthorizedAccessException)
{
Logger.Error("File exists but is not readable due to access permissions.");
Logger.Error("WithClientCertificate: File exists but is not readable due to access permissions.");
throw;
}
catch (IOException)
{
Logger.Error("An I/O error occurred while trying to read the file.");
Logger.Error("WithClientCertificate: An I/O error occurred while trying to read the file.");
throw;
}
}
Expand Down
11 changes: 7 additions & 4 deletions Source/HiveMQtt/Client/HiveMQClientTrafficProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ private Task<bool> ConnectionWriterAsync(CancellationToken cancellationToken) =>
// QoS > 0 - Add to transaction queue
if (this.transactionQueue.TryAdd(publishPacket.PacketIdentifier, new List<ControlPacket> { publishPacket }) == false)
{
Logger.Warn("Duplicate packet ID detected.");
Logger.Warn($"Duplicate packet ID detected {publishPacket.PacketIdentifier} while queueing to transaction queue for an outgoing QoS {publishPacket.Message.QoS} publish .");
continue;
}
}
Expand Down Expand Up @@ -334,8 +334,8 @@ private Task<bool> ReceivedPacketsHandlerAsync(CancellationToken cancellationTok
{
if (packet.PacketSize > this.Options.ClientMaximumPacketSize)
{
Logger.Warn($"Packet size {packet.PacketSize} exceeds maximum packet size {this.Options.ClientMaximumPacketSize}. Disconnecting.");
Logger.Debug($"{this.Options.ClientId}-(RPH)- Packet size {packet.PacketSize} exceeds maximum packet size {this.Options.ClientMaximumPacketSize}. Disconnecting.");
Logger.Warn($"Received packet size {packet.PacketSize} exceeds maximum packet size {this.Options.ClientMaximumPacketSize}. Disconnecting.");
Logger.Debug($"{this.Options.ClientId}-(RPH)- Received packet size {packet.PacketSize} exceeds maximum packet size {this.Options.ClientMaximumPacketSize}. Disconnecting.");

var opts = new DisconnectOptions
{
Expand Down Expand Up @@ -411,6 +411,9 @@ internal void HandleIncomingPublishPacket(PublishPacket publishPacket)
{
// We've received a QoS 1 publish. Send a PubAck.
var pubAckResponse = new PubAckPacket(publishPacket.PacketIdentifier, PubAckReasonCode.Success);

// FIXME We should wait until puback is sent before launching event
// FIXME Check DUP flag setting
this.SendQueue.Add(pubAckResponse);
}
else if (publishPacket.Message.QoS is MQTT5.Types.QualityOfService.ExactlyOnceDelivery)
Expand All @@ -421,7 +424,7 @@ internal void HandleIncomingPublishPacket(PublishPacket publishPacket)

if (this.transactionQueue.TryAdd(publishPacket.PacketIdentifier, publishQoS2Chain) == false)
{
Logger.Warn("QoS2: Duplicate packet ID detected.");
Logger.Warn($"Duplicate packet ID detected {publishPacket.PacketIdentifier} while queueing to transaction queue for an incoming QoS {publishPacket.Message.QoS} publish .");
pubRecResponse.ReasonCode = PubRecReasonCode.PacketIdentifierInUse;
}

Expand Down

0 comments on commit 6158c9b

Please sign in to comment.