@@ -10,6 +10,7 @@ use futures::SinkExt;
10
10
use futures:: StreamExt ;
11
11
use log:: error;
12
12
use log:: info;
13
+ use log:: warn;
13
14
use rumqttc:: AsyncClient ;
14
15
use rumqttc:: Event ;
15
16
use rumqttc:: EventLoop ;
@@ -132,17 +133,17 @@ impl Connection {
132
133
const SECURE_MQTT_PORT : u16 = 8883 ;
133
134
134
135
if config. broker . port == INSECURE_MQTT_PORT && config. broker . authentication . is_some ( ) {
135
- eprintln ! ( "WARNING: Connecting on port 1883 for insecure MQTT using a TLS connection") ;
136
+ warn ! ( target : "MQTT" , " Connecting on port 1883 for insecure MQTT using a TLS connection") ;
136
137
}
137
138
if config. broker . port == SECURE_MQTT_PORT && config. broker . authentication . is_none ( ) {
138
- eprintln ! ( "WARNING: Connecting on port 8883 for secure MQTT without a CA file") ;
139
+ warn ! ( target : "MQTT" , " Connecting on port 8883 for secure MQTT without a CA file") ;
139
140
}
140
141
141
142
let mqtt_options = config. rumqttc_options ( ) ?;
142
143
let ( mqtt_client, mut event_loop) = AsyncClient :: new ( mqtt_options, config. queue_capacity ) ;
143
144
144
- info ! (
145
- "MQTT connecting to broker: host={}:{}, session_name={:?}" ,
145
+ info ! ( target : "MQTT" ,
146
+ "Connecting to broker: host={}:{}, session_name={:?}" ,
146
147
config. broker. host, config. broker. port, config. session_name
147
148
) ;
148
149
@@ -152,7 +153,7 @@ impl Connection {
152
153
if let Some ( err) = MqttError :: maybe_connection_error ( & ack) {
153
154
return Err ( err) ;
154
155
} ;
155
- info ! ( "MQTT connection established" ) ;
156
+ info ! ( target : "MQTT" , "Connection established") ;
156
157
157
158
let subscriptions = config. subscriptions . filters ( ) ;
158
159
@@ -175,16 +176,16 @@ impl Connection {
175
176
// Messages can be received before a sub ack
176
177
// Errors on send are ignored: it just means the client has closed the receiving channel.
177
178
if msg. payload . len ( ) > config. max_packet_size {
178
- error ! ( " Dropping message received on topic {} with payload size {} that exceeds the maximum packet size of {}",
179
+ error ! ( target : "MQTT" , " Dropping message received on topic {} with payload size {} that exceeds the maximum packet size of {}",
179
180
msg. topic, msg. payload. len( ) , config. max_packet_size) ;
180
181
continue ;
181
182
}
182
183
let _ = message_sender. send ( msg. into ( ) ) . await ;
183
184
}
184
185
185
186
Err ( err) => {
186
- error ! (
187
- "MQTT: failed to connect to broker at '{host}:{port}': {err}" ,
187
+ error ! ( target : "MQTT" ,
188
+ "Failed to connect to broker at '{host}:{port}': {err}" ,
188
189
host = config. broker. host,
189
190
port = config. broker. port
190
191
) ;
@@ -244,7 +245,7 @@ impl Connection {
244
245
match event {
245
246
Ok ( Event :: Incoming ( Packet :: Publish ( msg) ) ) => {
246
247
if msg. payload . len ( ) > config. max_packet_size {
247
- error ! ( " Dropping message received on topic {} with payload size {} that exceeds the maximum packet size of {}",
248
+ error ! ( target : "MQTT" , " Dropping message received on topic {} with payload size {} that exceeds the maximum packet size of {}",
248
249
msg. topic, msg. payload. len( ) , config. max_packet_size) ;
249
250
continue ;
250
251
}
@@ -255,9 +256,9 @@ impl Connection {
255
256
256
257
Ok ( Event :: Incoming ( Packet :: ConnAck ( ack) ) ) => {
257
258
if let Some ( err) = MqttError :: maybe_connection_error ( & ack) {
258
- error ! ( "MQTT connection Error {err}" ) ;
259
+ error ! ( target : "MQTT" , "Connection Error {err}") ;
259
260
} else {
260
- info ! ( "MQTT connection re-established" ) ;
261
+ info ! ( target : "MQTT" , "Connection re-established") ;
261
262
if let Some ( ref imsg_fn) = config. initial_message {
262
263
// publish the initial message on connect
263
264
let message = imsg_fn. new_init_message ( ) ;
@@ -292,7 +293,7 @@ impl Connection {
292
293
}
293
294
294
295
Err ( err) => {
295
- error ! ( "MQTT connection error: {err}" ) ;
296
+ error ! ( target : "MQTT" , "Connection error: {err}") ;
296
297
297
298
// Errors on send are ignored: it just means the client has closed the receiving channel.
298
299
let _ = error_sender. send ( err. into ( ) ) . await ;
@@ -307,7 +308,7 @@ impl Connection {
307
308
// to make sure the disconnect is effective
308
309
loop {
309
310
if ( event_loop. poll ( ) . await ) . is_err ( ) {
310
- info ! ( "MQTT connection closed" ) ;
311
+ info ! ( target : "MQTT" , "Connection closed") ;
311
312
break ;
312
313
}
313
314
}
0 commit comments