cli: add commands to change daemon logging level
This commit is contained in:
43
cli/main.c
43
cli/main.c
@@ -44,12 +44,17 @@ static gboolean async_flag;
|
|||||||
static gboolean list_modems_flag;
|
static gboolean list_modems_flag;
|
||||||
static gboolean monitor_modems_flag;
|
static gboolean monitor_modems_flag;
|
||||||
static gboolean scan_modems_flag;
|
static gboolean scan_modems_flag;
|
||||||
|
static gchar *set_logging_str;
|
||||||
|
|
||||||
static GOptionEntry entries[] = {
|
static GOptionEntry entries[] = {
|
||||||
{ "version", 'V', 0, G_OPTION_ARG_NONE, &version_flag,
|
{ "version", 'V', 0, G_OPTION_ARG_NONE, &version_flag,
|
||||||
"Print version",
|
"Print version",
|
||||||
NULL
|
NULL
|
||||||
},
|
},
|
||||||
|
{ "set-logging", 'L', 0, G_OPTION_ARG_STRING, &set_logging_str,
|
||||||
|
"Set logging level in the ModemManager daemon",
|
||||||
|
"[ERR,WARN,INFO,DEBUG]",
|
||||||
|
},
|
||||||
{ "async", 'a', 0, G_OPTION_ARG_NONE, &async_flag,
|
{ "async", 'a', 0, G_OPTION_ARG_NONE, &async_flag,
|
||||||
"Use asynchronous methods",
|
"Use asynchronous methods",
|
||||||
NULL
|
NULL
|
||||||
@@ -248,6 +253,33 @@ synchronous (MMManager *manager)
|
|||||||
|
|
||||||
g_debug ("Running synchronous operations...");
|
g_debug ("Running synchronous operations...");
|
||||||
|
|
||||||
|
/* Request to set log level? */
|
||||||
|
if (set_logging_str) {
|
||||||
|
MMLogLevel level;
|
||||||
|
|
||||||
|
if (g_strcmp0 (set_logging_str, "ERR") == 0)
|
||||||
|
level = MM_LOG_LEVEL_ERROR;
|
||||||
|
else if (g_strcmp0 (set_logging_str, "WARN") == 0)
|
||||||
|
level = MM_LOG_LEVEL_WARNING;
|
||||||
|
else if (g_strcmp0 (set_logging_str, "INFO") == 0)
|
||||||
|
level = MM_LOG_LEVEL_INFO;
|
||||||
|
else if (g_strcmp0 (set_logging_str, "DEBUG") == 0)
|
||||||
|
level = MM_LOG_LEVEL_DEBUG;
|
||||||
|
else {
|
||||||
|
g_printerr ("couldn't set unknown logging level: '%s'\n",
|
||||||
|
set_logging_str);
|
||||||
|
exit (EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mm_manager_set_logging (manager, level, &error)) {
|
||||||
|
g_printerr ("couldn't set logging level: '%s'\n",
|
||||||
|
error ? error->message : "unknown error");
|
||||||
|
exit (EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
g_print ("successfully set log level '%s'\n", set_logging_str);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* Request to scan modems? */
|
/* Request to scan modems? */
|
||||||
if (scan_modems_flag) {
|
if (scan_modems_flag) {
|
||||||
gboolean result;
|
gboolean result;
|
||||||
@@ -275,7 +307,8 @@ ensure_single_action (void)
|
|||||||
|
|
||||||
n_actions = (scan_modems_flag +
|
n_actions = (scan_modems_flag +
|
||||||
list_modems_flag +
|
list_modems_flag +
|
||||||
monitor_modems_flag);
|
monitor_modems_flag +
|
||||||
|
(set_logging_str ? 1 : 0));
|
||||||
|
|
||||||
if (n_actions == 0)
|
if (n_actions == 0)
|
||||||
print_version_and_exit ();
|
print_version_and_exit ();
|
||||||
@@ -294,6 +327,14 @@ ensure_single_action (void)
|
|||||||
/* Monitoring always asynchronously */
|
/* Monitoring always asynchronously */
|
||||||
async_flag = TRUE;
|
async_flag = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Additional fixes for the log level setting request */
|
||||||
|
if (set_logging_str) {
|
||||||
|
/* Log level setting always synchronously */
|
||||||
|
async_flag = FALSE;
|
||||||
|
/* Always stop loop after setting log level */
|
||||||
|
keep_loop = FALSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gint
|
gint
|
||||||
|
Reference in New Issue
Block a user