diff options
author | Aleksander Morgado <aleksandermj@chromium.org> | 2022-08-05 15:27:37 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2022-08-05 16:09:58 +0200 |
commit | c7d9b40e3d0aa812d5875cee104dc8dd935e88c8 (patch) | |
tree | e68925457b79f846392bbccbc290dbcda25ee853 | |
parent | d4c0fd9754b77392b495219e049a938e0c1bf859 (diff) | |
download | libqmi-c7d9b40e3d0aa812d5875cee104dc8dd935e88c8.tar.gz |
qmi-proxy: compute log time string only if printing the log
-rw-r--r-- | src/qmi-proxy/qmi-proxy.c | 25 |
1 files changed, 12 insertions, 13 deletions
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, |