From c7d9b40e3d0aa812d5875cee104dc8dd935e88c8 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Fri, 5 Aug 2022 15:27:37 +0200 Subject: qmi-proxy: compute log time string only if printing the log --- src/qmi-proxy/qmi-proxy.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/qmi-proxy/qmi-proxy.c b/src/qmi-proxy/qmi-proxy.c index 7ad8f124..9923b5d0 100644 --- a/src/qmi-proxy/qmi-proxy.c +++ b/src/qmi-proxy/qmi-proxy.c @@ -80,21 +80,16 @@ quit_cb (gpointer user_data) } static void -log_handler (const gchar *log_domain, - GLogLevelFlags log_level, - const gchar *message, - gpointer user_data) +log_handler (const gchar *log_domain, + GLogLevelFlags log_level, + const gchar *message, + gpointer user_data) { const gchar *log_level_str; - time_t now; - gchar time_str[64]; - struct tm *local_time; - gboolean err; - - now = time ((time_t *) NULL); - local_time = localtime (&now); - strftime (time_str, 64, "%d %b %Y, %H:%M:%S", local_time); - err = FALSE; + time_t now; + gchar time_str[64]; + struct tm *local_time; + gboolean err = FALSE; switch (log_level) { case G_LOG_LEVEL_WARNING: @@ -127,6 +122,10 @@ log_handler (const gchar *log_domain, if (!verbose_flag && !err) return; + now = time ((time_t *) NULL); + local_time = localtime (&now); + strftime (time_str, 64, "%d %b %Y, %H:%M:%S", local_time); + g_fprintf (err ? stderr : stdout, "[%s] %s %s\n", time_str, -- cgit v1.2.1