]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
systemd-battery-check: provide more debug logs
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 29 Jul 2023 17:29:33 +0000 (19:29 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Mon, 31 Jul 2023 09:06:04 +0000 (10:06 +0100)
The logs would give no hint about the answer to most interesting question: why
we decided to return true or false from the program. If we find batteries
that are low or uncertain, log at info level.

src/shared/battery-util.c

index 71ee89a5498d295c9827f8af9c9c9f0da8ec28a5..8b7bdc704d2c995c90d2a3339b1f769688b979c8 100644 (file)
@@ -254,19 +254,28 @@ int battery_is_discharging_and_low(void) {
 
                 level = battery_read_capacity_percentage(dev);
                 if (level < 0) {
+                        log_device_debug_errno(dev, level, "Battery capacity is unreadable: %m");
                         unsure = true;
                         continue;
                 }
 
-                if (level > BATTERY_LOW_CAPACITY_LEVEL) /* Found a charged battery */
+                if (level > BATTERY_LOW_CAPACITY_LEVEL) { /* Found a charged battery */
+                        log_device_full(dev,
+                                        found_low ? LOG_INFO : LOG_DEBUG,
+                                        "Found battery with capacity above threshold (%d%% > %d%%).",
+                                        level, BATTERY_LOW_CAPACITY_LEVEL);
                         return false;
+                }
 
+                log_device_info(dev,
+                                "Found battery with capacity below threshold (%d%% <= %d%%).",
+                                level, BATTERY_LOW_CAPACITY_LEVEL);
                 found_low = true;
         }
 
         /* If we found a battery whose state we couldn't read, don't assume we are in low battery state */
         if (unsure) {
-                log_debug("Found battery with unreadable state, assuming not in low battery state.");
+                log_info("Found battery with unreadable state, assuming not in low battery state.");
                 return false;
         }