Skip to content

Commit 9e94a53

Browse files
committed
drivers/*.c: remove useless custom logging, hide useful messages behind may_log_reconnect_trying() [#3541]
Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
1 parent ea8370b commit 9e94a53

10 files changed

Lines changed: 38 additions & 22 deletions

File tree

drivers/apcsmart.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2402,7 +2402,8 @@ void upsdrv_updateinfo(void)
24022402

24032403
/* become aggressive after a few tries */
24042404
if (!(last_worked % 60)) {
2405-
upslogx(LOG_WARNING, "Trying to reconnect to the UPS");
2405+
upsdebugx(1, "%s: Trying to reconnect to the UPS", __func__);
2406+
24062407
reconnect_trying(RECONNECT_TRYING);
24072408

24082409
upsdebugx(1, "%s: call upsdrv_cleanup", __func__);

drivers/belkin.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,15 @@ void upsdrv_updateinfo(void)
229229
return;
230230
}
231231

232-
upslogx(LOG_WARNING, "Communications with UPS lost: status read failed; attempting reconnect");
232+
if (may_log_reconnect_trying(0))
233+
upslogx(LOG_WARNING, "Communications with UPS lost: status read failed; attempting reconnect");
234+
233235
if (!reconnect_ups()) {
234236
dstate_datastale();
237+
} else {
238+
/* Do not extra-log below */
239+
retry = 0;
235240
}
236-
retry = 0;
237241
return;
238242
}
239243

@@ -538,7 +542,9 @@ static int init_driver_state(int fatal_on_failure)
538542
);
539543
}
540544

541-
upslogx(LOG_WARNING, "Unable to re-establish communication with the Belkin UPS on port %s", device_path);
545+
if (may_log_reconnect_trying(1))
546+
upslogx(LOG_WARNING, "Unable to re-establish communication with the Belkin UPS on port %s", device_path);
547+
542548
return 0;
543549
}
544550

@@ -596,7 +602,6 @@ void upsdrv_initinfo(void)
596602
static int reconnect_ups(void)
597603
{
598604
reconnect_trying(RECONNECT_TRYING);
599-
upslogx(LOG_WARNING, "Communications with UPS lost; attempting to re-establish the connection");
600605

601606
upsdrv_cleanup();
602607
upsdrv_initups();

drivers/bestfortress.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,6 @@ void upsdrv_initups(void)
646646
static int reconnect_ups(void)
647647
{
648648
reconnect_trying(RECONNECT_TRYING);
649-
upslogx(LOG_WARNING, "Communications with UPS lost; attempting to re-establish the connection");
650649

651650
upsdrv_cleanup();
652651
upsdrv_initups();

drivers/genericups.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ static void parse_input_signals(const char *value, int *line, int *val)
183183
static int reconnect_ups(void)
184184
{
185185
reconnect_trying(RECONNECT_TRYING);
186-
upslogx(LOG_WARNING, "Communications with UPS lost; attempting to re-establish the connection");
187186

188187
upsdrv_cleanup();
189188
upsdrv_initups();

drivers/nhs_ser.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1942,19 +1942,21 @@ static TYPE_FD_SER reconnect_ups_if_needed(void) {
19421942
serial_fd = openfd(porta, baudrate);
19431943
retries++;
19441944
/* Try above at least once per main cycle */
1945-
if (retries >= MAXTRIES)
1945+
if (retries >= MAXTRIES) {
1946+
upsdebugx(1, "%s: serial port reopen failed", __func__);
19461947
break;
1948+
}
19471949
usleep(checktime);
19481950
}
19491951

19501952
if (VALID_FD_SER(serial_fd)) {
1951-
if (retries > MAXTRIES) {
1953+
if (retries > MAXTRIES && may_log_reconnect_trying(1)) {
19521954
upslogx(LOG_NOTICE, "Communications with UPS re-established");
19531955
}
19541956
retries = 0;
19551957
reconnect_trying(RECONNECT_SUCCESS);
19561958
} else {
1957-
if (retries == MAXTRIES) {
1959+
if (retries == MAXTRIES && may_log_reconnect_trying(1)) {
19581960
upslogx(LOG_WARNING, "Communications with UPS lost: port reopen failed!");
19591961
}
19601962
dstate_datastale();

drivers/powerpanel.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ upsdrv_info_t upsdrv_info = {
5353
static int reconnect_ups(void)
5454
{
5555
reconnect_trying(RECONNECT_TRYING);
56-
upslogx(LOG_WARNING, "Communications with UPS lost; attempting to re-establish the connection");
5756

5857
upsdrv_cleanup();
5958
upsdrv_initups();

drivers/powervar_cx_usb.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -400,16 +400,22 @@ void upsdrv_updateinfo(void)
400400

401401
if (ReconnectFlag)
402402
{
403+
int maylog = may_log_reconnect_trying(1);
404+
405+
if (maylog)
406+
upslogx(LOG_WARNING, "USB device may be detached.");
407+
403408
reconnect_trying(RECONNECT_TRYING);
404-
upslogx(LOG_WARNING, "USB device may be detached.");
405409

406410
hd = NULL;
407411

408412
ret = comm_driver->open_dev(&udev, &curDevice, reopen_matcher, match_by_something);
409413
if (ret < 1)
410414
{
411-
upslogx(LOG_INFO, "USB reconnect attempt failed.");
412-
upslogx(LOG_INFO, "Will try another reconnect in a bit.");
415+
if (maylog) {
416+
upslogx(LOG_INFO, "USB reconnect attempt failed.");
417+
upslogx(LOG_INFO, "Will try another reconnect in a bit.");
418+
}
413419
dstate_datastale();
414420
return;
415421
}
@@ -419,7 +425,9 @@ void upsdrv_updateinfo(void)
419425

420426
hd = &curDevice;
421427

422-
upslogx(LOG_NOTICE, "USB reconnect successful");
428+
if (maylog)
429+
upslogx(LOG_NOTICE, "USB reconnect successful");
430+
423431
reconnect_trying(RECONNECT_UPDATEINFO);
424432
upsdrv_initinfo();
425433

drivers/tripplite.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,6 @@ void upsdrv_shutdown(void)
410410
static int reconnect_ups(void)
411411
{
412412
reconnect_trying(RECONNECT_TRYING);
413-
upslogx(LOG_WARNING, "Communications with UPS lost; attempting to re-establish the connection");
414413

415414
upsdrv_cleanup();
416415
upsdrv_initups();

drivers/tripplite_usb.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -384,21 +384,23 @@ int match_by_unitid(usb_dev_handle *argudev, USBDevice_t *arghd, usb_ctrl_charbu
384384
*/
385385
static int reconnect_ups(void)
386386
{
387-
int ret;
387+
int ret, maylog;
388388

389389
if (hd != NULL) {
390390
return 1;
391391
}
392392

393+
maylog = may_log_reconnect_trying(1);
393394
reconnect_trying(RECONNECT_TRYING);
394395

395-
upsdebugx(2, "==================================================");
396-
upsdebugx(2, "= device has been disconnected, try to reconnect =");
397-
upsdebugx(2, "==================================================");
396+
upsdebugx(4, "==================================================");
397+
upsdebugx(4, "= device has been disconnected, try to reconnect =");
398+
upsdebugx(4, "==================================================");
398399

399400
ret = comm_driver->open_dev(&udev, &curDevice, reopen_matcher, match_by_unitid);
400401
if (ret < 1) {
401-
upslogx(LOG_INFO, "Reconnecting to UPS failed; will retry later...");
402+
if (maylog)
403+
upslogx(LOG_INFO, "Reconnecting to UPS failed; will retry later...");
402404
dstate_datastale();
403405
return 0;
404406
}

drivers/usbhid-ups.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1391,13 +1391,15 @@ void upsdrv_updateinfo(void)
13911391
/* check for device availability to set datastale! */
13921392
if (reconnecting) {
13931393
/* don't flood reconnection attempts */
1394+
int maylog;
13941395
if (now < (lastpoll + poll_interval)) {
13951396
return;
13961397
}
13971398

1399+
maylog = may_log_reconnect_trying(1);
13981400
reconnect_trying(RECONNECT_TRYING);
13991401
upsdebugx(1, "Got to reconnect!");
1400-
if (use_interrupt_pipe == TRUE && interrupt_pipe_EIO_count > 0) {
1402+
if (use_interrupt_pipe == TRUE && interrupt_pipe_EIO_count > 0 && maylog) {
14011403
upsdebugx(0, "Reconnecting. If you saw \"nut_libusb_get_interrupt: Input/Output Error\" "
14021404
"or similar message in the log above, try setting \"pollonly\" flag in \"ups.conf\" "
14031405
"options section for this driver!");

0 commit comments

Comments
 (0)