forked from osmocom/wireshark
wslog: Add backward compatibility with 'console.log.level'
This adds some custom logic to check if we were given the obsolete 'console.log.level' setting from the CLI arguments, that specified the log level using a bitmask copied from GLib. If we find that map the bitmask to a wslog log level. In any case the option is not removed from the argv (unlike other wslog arguments like --log-level, etc.). Adds deprecation warning for 'console.log.level' printed to the console. Related to #17763.
This commit is contained in:
parent
7d7873187e
commit
53cded5062
|
@ -5487,6 +5487,9 @@ set_pref(gchar *pref_name, const gchar *value, void *private_data _U_,
|
|||
/* Handled within deprecated_enable_dissector_pref() if found */
|
||||
} else if (deprecated_port_pref(pref_name, value)) {
|
||||
/* Handled within deprecated_port_pref() if found */
|
||||
} else if (strcmp(pref_name, "console.log.level") == 0) {
|
||||
/* Handled on the command line within ws_log_parse_args() */
|
||||
return PREFS_SET_OK;
|
||||
} else {
|
||||
/* Handle deprecated "global" options that don't have a module
|
||||
* associated with them
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
|
||||
#include "file_util.h"
|
||||
#include "to_str.h"
|
||||
#include "strtoi.h"
|
||||
|
||||
|
||||
/* Runtime log level. */
|
||||
|
@ -114,7 +115,7 @@ static gboolean init_complete = FALSE;
|
|||
|
||||
static void print_err(void (*vcmdarg_err)(const char *, va_list ap),
|
||||
int exit_failure,
|
||||
const char *fmt, ...);
|
||||
const char *fmt, ...) G_GNUC_PRINTF(3,4);
|
||||
|
||||
static void ws_log_cleanup(void);
|
||||
|
||||
|
@ -329,6 +330,88 @@ static void print_err(void (*vcmdarg_err)(const char *, va_list ap),
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
* This tries to convert old log level preference to a wslog
|
||||
* configuration. The string must start with "console.log.level:"
|
||||
* It receives an argv for { '-o', 'console.log.level:nnn', ...} or
|
||||
* { '-oconsole.log.level:nnn', ...}.
|
||||
*/
|
||||
static void
|
||||
parse_console_compat_option(char *argv[],
|
||||
void (*vcmdarg_err)(const char *, va_list ap),
|
||||
int exit_failure)
|
||||
{
|
||||
const char *mask_str;
|
||||
guint32 mask;
|
||||
enum ws_log_level level;
|
||||
|
||||
ws_assert(argv != NULL);
|
||||
|
||||
if (argv[0] == NULL)
|
||||
return;
|
||||
|
||||
if (strcmp(argv[0], "-o") == 0) {
|
||||
if (argv[1] == NULL ||
|
||||
!g_str_has_prefix(argv[1], "console.log.level:")) {
|
||||
/* Not what we were looking for. */
|
||||
return;
|
||||
}
|
||||
mask_str = argv[1] + strlen("console.log.level:");
|
||||
}
|
||||
else if (g_str_has_prefix(argv[0], "-oconsole.log.level:")) {
|
||||
mask_str = argv[0] + strlen("-oconsole.log.level:");
|
||||
}
|
||||
else {
|
||||
/* Not what we were looking for. */
|
||||
return;
|
||||
}
|
||||
|
||||
print_err(vcmdarg_err, LOG_ARGS_NOEXIT,
|
||||
"Option 'console.log.level' is deprecated, consult '--help' "
|
||||
"for diagnostic message options.");
|
||||
|
||||
if (*mask_str == '\0') {
|
||||
print_err(vcmdarg_err, exit_failure,
|
||||
"Missing value to 'console.log.level' option.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ws_basestrtou32(mask_str, NULL, &mask, 10)) {
|
||||
print_err(vcmdarg_err, exit_failure,
|
||||
"%s is not a valid decimal number.", mask_str);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* The lowest priority bit in the mask defines the level.
|
||||
*/
|
||||
if (mask & G_LOG_LEVEL_DEBUG)
|
||||
level = LOG_LEVEL_DEBUG;
|
||||
else if (mask & G_LOG_LEVEL_INFO)
|
||||
level = LOG_LEVEL_INFO;
|
||||
else if (mask & G_LOG_LEVEL_MESSAGE)
|
||||
level = LOG_LEVEL_MESSAGE;
|
||||
else if (mask & G_LOG_LEVEL_WARNING)
|
||||
level = LOG_LEVEL_WARNING;
|
||||
else if (mask & G_LOG_LEVEL_CRITICAL)
|
||||
level = LOG_LEVEL_CRITICAL;
|
||||
else if (mask & G_LOG_LEVEL_ERROR)
|
||||
level = LOG_LEVEL_ERROR;
|
||||
else
|
||||
level = LOG_LEVEL_NONE;
|
||||
|
||||
if (level == LOG_LEVEL_NONE) {
|
||||
/* Some values (like zero) might not contain any meaningful bits.
|
||||
* Throwing an error in that case seems appropriate. */
|
||||
print_err(vcmdarg_err, exit_failure,
|
||||
"Value %s is not a valid log mask.", mask_str);
|
||||
return;
|
||||
}
|
||||
|
||||
ws_log_set_level(level);
|
||||
}
|
||||
|
||||
|
||||
int ws_log_parse_args(int *argc_ptr, char *argv[],
|
||||
void (*vcmdarg_err)(const char *, va_list ap),
|
||||
int exit_failure)
|
||||
|
@ -375,6 +458,13 @@ int ws_log_parse_args(int *argc_ptr, char *argv[],
|
|||
optlen = strlen(opt_noisy);
|
||||
}
|
||||
else {
|
||||
/* Check is we have the old '-o console.log.level' flag,
|
||||
* or '-oconsole.log.level', for backward compatibility.
|
||||
* Then if we do ignore it after processing and let the
|
||||
* preferences module handle it later. */
|
||||
if (*(*ptr + 0) == '-' && *(*ptr + 1) == 'o') {
|
||||
parse_console_compat_option(ptr, vcmdarg_err, exit_failure);
|
||||
}
|
||||
ptr += 1;
|
||||
count -= 1;
|
||||
continue;
|
||||
|
|
Loading…
Reference in New Issue