aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2017-01-16 12:41:15 +0100
committerAleksander Morgado <aleksander@aleksander.es>2017-01-16 12:53:37 +0100
commitc10a0338dec90704871206b8f7fc76fe8779c8d4 (patch)
tree9527bf0acd897fce0078a06c81191fe75cc6b8f8
parentd6e8ec8d617e137fc2535a746e615fb7e8d26248 (diff)
downloadexternal_libqmi-c10a0338dec90704871206b8f7fc76fe8779c8d4.zip
external_libqmi-c10a0338dec90704871206b8f7fc76fe8779c8d4.tar.gz
external_libqmi-c10a0338dec90704871206b8f7fc76fe8779c8d4.tar.bz2
qmi-firmware-update: new option to enable verbose logging file output
So that we can run the operation in stdout with standard logging level but storing in an external file the verbose logs in case they have to be analyzed later on, e.g. if the update failed.
-rw-r--r--src/qmi-firmware-update/qfu-log.c72
-rw-r--r--src/qmi-firmware-update/qfu-log.h13
-rw-r--r--src/qmi-firmware-update/qfu-main.c26
-rw-r--r--src/qmi-firmware-update/qfu-updater.c4
4 files changed, 79 insertions, 36 deletions
diff --git a/src/qmi-firmware-update/qfu-log.c b/src/qmi-firmware-update/qfu-log.c
index 1a10ed2..c3226b1 100644
--- a/src/qmi-firmware-update/qfu-log.c
+++ b/src/qmi-firmware-update/qfu-log.c
@@ -15,11 +15,12 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
- * Copyright (C) 2016 Zodiac Inflight Innovations
- * Copyright (C) 2016 Aleksander Morgado <aleksander@aleksander.es>
+ * Copyright (C) 2016-2017 Zodiac Inflight Innovations
+ * Copyright (C) 2016-2017 Aleksander Morgado <aleksander@aleksander.es>
*/
#include <config.h>
+#include <errno.h>
#include <glib.h>
#include <glib/gprintf.h>
@@ -32,8 +33,9 @@
#include "qfu-log.h"
-static gboolean silent_flag;
-static gboolean verbose_flag;
+static gboolean stdout_silent_flag;
+static gboolean stdout_verbose_flag;
+static FILE *verbose_log_file;
static void
log_handler (const gchar *log_domain,
@@ -48,7 +50,7 @@ log_handler (const gchar *log_domain,
gboolean err;
/* Nothing to do if we're silent */
- if (silent_flag)
+ if (stdout_silent_flag && !verbose_log_file)
return;
now = time ((time_t *) NULL);
@@ -78,49 +80,79 @@ log_handler (const gchar *log_domain,
break;
}
- if (!verbose_flag && !err)
- return;
+ if (verbose_log_file) {
+ g_fprintf (verbose_log_file,
+ "[%s] %s %s\n",
+ time_str,
+ log_level_str,
+ message);
+ fflush (verbose_log_file);
+ }
- g_fprintf (err ? stderr : stdout,
- "[%s] %s %s\n",
- time_str,
- log_level_str,
- message);
+ if (stdout_verbose_flag || err)
+ g_fprintf (err ? stderr : stdout,
+ "[%s] %s %s\n",
+ time_str,
+ log_level_str,
+ message);
}
gboolean
qfu_log_get_verbose (void)
{
- return verbose_flag;
+ return (stdout_verbose_flag || verbose_log_file);
+}
+
+gboolean
+qfu_log_get_verbose_stdout (void)
+{
+ return (stdout_verbose_flag);
}
gboolean
-qfu_log_init (gboolean verbose,
- gboolean silent)
+qfu_log_init (gboolean stdout_verbose,
+ gboolean stdout_silent,
+ const gchar *verbose_log_path)
{
- if (verbose && silent) {
+ if (stdout_verbose && stdout_silent) {
g_printerr ("error: cannot specify --verbose and --silent at the same time\n");
return FALSE;
}
/* Store flags */
- verbose_flag = verbose;
- silent_flag = silent;
+ stdout_verbose_flag = stdout_verbose;
+ stdout_silent_flag = stdout_silent;
+
+ /* Open verbose log if required */
+ if (verbose_log_path) {
+ verbose_log_file = fopen (verbose_log_path, "w");
+ if (!verbose_log_file) {
+ g_printerr ("error: cannot open verbose log file for writing: %s\n", g_strerror (errno));
+ return FALSE;
+ }
+ }
/* Default application logging */
g_log_set_handler (NULL, G_LOG_LEVEL_MASK, log_handler, NULL);
/* libqmi logging */
g_log_set_handler ("Qmi", G_LOG_LEVEL_MASK, log_handler, NULL);
- if (verbose_flag)
+ if (stdout_verbose_flag || verbose_log_file)
qmi_utils_set_traces_enabled (TRUE);
#if defined MBIM_QMUX_ENABLED
/* libmbim logging */
g_log_set_handler ("Mbim", G_LOG_LEVEL_MASK, log_handler, NULL);
- if (verbose_flag)
+ if (stdout_verbose_flag || verbose_log_file)
mbim_utils_set_traces_enabled (TRUE);
#endif
return TRUE;
}
+
+void
+qfu_log_shutdown (void)
+{
+ if (verbose_log_file)
+ fclose (verbose_log_file);
+}
diff --git a/src/qmi-firmware-update/qfu-log.h b/src/qmi-firmware-update/qfu-log.h
index adc7768..c4ad226 100644
--- a/src/qmi-firmware-update/qfu-log.h
+++ b/src/qmi-firmware-update/qfu-log.h
@@ -15,8 +15,8 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
- * Copyright (C) 2016 Zodiac Inflight Innovations
- * Copyright (C) 2016 Aleksander Morgado <aleksander@aleksander.es>
+ * Copyright (C) 2016-2017 Zodiac Inflight Innovations
+ * Copyright (C) 2016-2017 Aleksander Morgado <aleksander@aleksander.es>
*/
#ifndef QFU_LOG_H
@@ -26,9 +26,12 @@
G_BEGIN_DECLS
-gboolean qfu_log_init (gboolean verbose,
- gboolean silent);
-gboolean qfu_log_get_verbose (void);
+gboolean qfu_log_init (gboolean stdout_verbose,
+ gboolean stdout_silent,
+ const gchar *verbose_log_path);
+void qfu_log_shutdown (void);
+gboolean qfu_log_get_verbose (void);
+gboolean qfu_log_get_verbose_stdout (void);
G_END_DECLS
diff --git a/src/qmi-firmware-update/qfu-main.c b/src/qmi-firmware-update/qfu-main.c
index efbf2d0..2757b89 100644
--- a/src/qmi-firmware-update/qfu-main.c
+++ b/src/qmi-firmware-update/qfu-main.c
@@ -15,8 +15,8 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
- * Copyright (C) 2016 Zodiac Inflight Innovation
- * Copyright (C) 2016 Aleksander Morgado <aleksander@aleksander.es>
+ * Copyright (C) 2016-2017 Zodiac Inflight Innovation
+ * Copyright (C) 2016-2017 Aleksander Morgado <aleksander@aleksander.es>
*/
#include "config.h"
@@ -68,8 +68,9 @@ static gboolean action_verify_flag;
/* Main */
static gchar **image_strv;
-static gboolean verbose_flag;
-static gboolean silent_flag;
+static gboolean stdout_verbose_flag;
+static gboolean stdout_silent_flag;
+static gchar *verbose_log_str;
static gboolean version_flag;
static gboolean help_flag;
static gboolean help_examples_flag;
@@ -249,14 +250,18 @@ static GOptionEntry context_main_entries[] = {
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &image_strv, "",
"FILE1 FILE2..."
},
- { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose_flag,
- "Run action with verbose logs, including the debug ones.",
+ { "verbose", 'v', 0, G_OPTION_ARG_NONE, &stdout_verbose_flag,
+ "Run action with verbose messages in standard output, including the debug ones.",
NULL
},
- { "silent", 'S', 0, G_OPTION_ARG_NONE, &silent_flag,
- "Run action with no logs; not even the error/warning ones.",
+ { "silent", 'S', 0, G_OPTION_ARG_NONE, &stdout_silent_flag,
+ "Run action with no messages in standard output; not even the error/warning ones.",
NULL
},
+ { "verbose-log", 'L', 0, G_OPTION_ARG_FILENAME, &verbose_log_str,
+ "Write verbose messages to an output file.",
+ "[PATH]"
+ },
{ "version", 'V', 0, G_OPTION_ARG_NONE, &version_flag,
"Print version.",
NULL
@@ -503,7 +508,7 @@ int main (int argc, char **argv)
}
/* Initialize logging */
- qfu_log_init (verbose_flag, silent_flag);
+ qfu_log_init (stdout_verbose_flag, stdout_silent_flag, verbose_log_str);
/* We don't allow multiple actions at the same time */
n_actions = (action_verify_flag +
@@ -573,6 +578,9 @@ int main (int argc, char **argv)
g_assert_not_reached ();
out:
+
+ qfu_log_shutdown ();
+
/* Clean exit for a clean memleak report */
if (context)
g_option_context_free (context);
diff --git a/src/qmi-firmware-update/qfu-updater.c b/src/qmi-firmware-update/qfu-updater.c
index 0c8fec4..883432c 100644
--- a/src/qmi-firmware-update/qfu-updater.c
+++ b/src/qmi-firmware-update/qfu-updater.c
@@ -391,7 +391,7 @@ run_context_step_download_image (GTask *task)
n_chunks = qfu_image_get_n_data_chunks (ctx->current_image);
for (sequence = 0; sequence < n_chunks; sequence++) {
- if (!qfu_log_get_verbose ()) {
+ if (!qfu_log_get_verbose_stdout ()) {
/* Use n-1 chunks for progress reporting; because the last one will take
* a lot longer. */
if (n_chunks > 1 && sequence < (n_chunks - 1))
@@ -409,7 +409,7 @@ run_context_step_download_image (GTask *task)
g_debug ("[qfu-updater] all chunks ack-ed");
- if (!qfu_log_get_verbose ())
+ if (!qfu_log_get_verbose_stdout ())
g_print (CLEAR_LINE);
if (!qfu_qdl_device_ufclose (ctx->qdl_device, cancellable, &error)) {