From 6e40a64aef56fb45f41f12ec3d887501f6051c2e Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Wed, 25 Sep 2024 14:58:35 +0200 Subject: [PATCH] Improve logging --- src/Helpers/LocaleHelper.vala | 10 ++++++---- src/MainWindow.vala | 2 +- src/Utils.vala | 16 ++++++++-------- src/Views/CheckView.vala | 6 +++--- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/Helpers/LocaleHelper.vala b/src/Helpers/LocaleHelper.vala index 13b538de2..4adcce9d7 100644 --- a/src/Helpers/LocaleHelper.vala +++ b/src/Helpers/LocaleHelper.vala @@ -54,8 +54,9 @@ namespace LocaleHelper { var langs = Build.LANG_LIST.split (";"); var parser = new Json.Parser (); + const string ISO_639_3_PATH = "%s/iso_639-3.json".printf (Build.ISO_CODES_LOCATION); try { - parser.load_from_file ("%s/iso_639-3.json".printf (Build.ISO_CODES_LOCATION)); + parser.load_from_file (ISO_639_3_PATH); weak Json.Object root_object = parser.get_root ().get_object (); weak Json.Array 639_3_array = root_object.get_array_member ("639-3"); foreach (unowned Json.Node element in 639_3_array.get_elements ()) { @@ -73,13 +74,14 @@ namespace LocaleHelper { } } } catch (Error e) { - critical (e.message); + critical ("Unable to parse '%s': %s", ISO_639_3_PATH, e.message); } var countries = new Gee.HashMap (); parser = new Json.Parser (); + const string ISO_3166_1_PATH = "%s/iso_3166-1.json".printf (Build.ISO_CODES_LOCATION); try { - parser.load_from_file ("%s/iso_3166-1.json".printf (Build.ISO_CODES_LOCATION)); + parser.load_from_file (ISO_3166_1_PATH); weak Json.Object root_object = parser.get_root ().get_object (); weak Json.Array 3166_1_array = root_object.get_array_member ("3166-1"); foreach (unowned Json.Node element in 3166_1_array.get_elements ()) { @@ -98,7 +100,7 @@ namespace LocaleHelper { countries[entry.alpha_2] = entry; } } catch (Error e) { - critical (e.message); + critical ("Unable to parse '%s': %s", ISO_3166_1_PATH, e.message); } foreach (var lang in langs) { diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 2faf178f8..e0ae0bf16 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -93,7 +93,7 @@ public class Installer.MainWindow : Gtk.Window { } }); } catch (Error e) { - warning (e.message); + warning ("Unable to query upower: %s", e.message); battery_infobar.revealed = false; } diff --git a/src/Utils.vala b/src/Utils.vala index 8c7afcc34..7b008c8f2 100644 --- a/src/Utils.vala +++ b/src/Utils.vala @@ -38,7 +38,7 @@ namespace Utils { try { system_instance.power_off (false); } catch (GLib.Error e) { - critical (e.message); + critical ("Unable to shutdown: %s", e.message); } } } @@ -52,7 +52,7 @@ namespace Utils { try { system_instance.reboot (false); } catch (GLib.Error e) { - critical (e.message); + critical ("Unable to restart: %s", e.message); } } } @@ -102,7 +102,7 @@ namespace Utils { "/org/freedesktop/login1" ); } catch (GLib.Error e) { - warning ("%s", e.message); + warning ("Unable to get system instance: %s", e.message); } } } @@ -145,7 +145,7 @@ namespace Utils { "/org/freedesktop/hostname1" ); } catch (GLib.Error e) { - warning ("%s", e.message); + warning ("Unable to get hostname instance: %s", e.message); } } } @@ -161,7 +161,7 @@ namespace Utils { try { FileUtils.get_contents ("/etc/machine-id", out machine_id); } catch (FileError e) { - warning ("%s", e.message); + warning ("Unable to get machine id: %s", e.message); return null; } @@ -173,7 +173,7 @@ namespace Utils { try { FileUtils.get_contents ("/sys/devices/virtual/dmi/id/sys_vendor", out vendor); } catch (FileError e) { - warning ("%s", e.message); + warning ("Unable to get sys vendor: %s", e.message); return null; } @@ -185,7 +185,7 @@ namespace Utils { try { FileUtils.get_contents ("/sys/devices/virtual/dmi/id/product_name", out model); } catch (FileError e) { - warning ("%s", e.message); + warning ("Unable to get product name: %s", e.message); return null; } @@ -197,7 +197,7 @@ namespace Utils { try { FileUtils.get_contents ("/sys/devices/virtual/dmi/id/product_version", out model); } catch (FileError e) { - warning ("%s", e.message); + warning ("Unable to get product version: %s", e.message); return null; } diff --git a/src/Views/CheckView.vala b/src/Views/CheckView.vala index 06d26a501..d1bb34239 100644 --- a/src/Views/CheckView.vala +++ b/src/Views/CheckView.vala @@ -132,7 +132,7 @@ public class Installer.CheckView : AbstractInstallerView { return int.parse (line); } } catch (Error e) { - stdout.printf ("Error: %s\n", e.message); + warning ("Unable to get frequency: %s\n", e.message); } return 0; @@ -151,7 +151,7 @@ public class Installer.CheckView : AbstractInstallerView { } } } catch (Error e) { - warning (e.message); + warning ("Unable to get meminfo: %s", e.message); } return 0; @@ -168,7 +168,7 @@ public class Installer.CheckView : AbstractInstallerView { } } } catch (Error e) { - critical (e.message); + critical ("Unable to get vm: %s", e.message); } return false;