As the number of log levels increases, it becomes less user friendly to assign a log level, as this is given as a bitmask in decimal form. This commit changes this, so that one or more log levels can be given as human readable words (e.g. "batctl ll batman routes"). --- sys.c | 32 +++++++++++++++++++++++++++++--- 1 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/sys.c b/sys.c index 4f2b2c5..1fefc6d 100644 --- a/sys.c +++ b/sys.c @@ -174,16 +174,24 @@ err:
static void log_level_usage(void) { - printf("Usage: batctl [options] loglevel [level]\n"); + printf("Usage: batctl [options] loglevel [level[ level[ level]...]\n"); printf("options:\n"); printf(" \t -h print this help\n"); + printf("levels:\n"); + printf(" \t none Debug logging is disabled\n"); + printf(" \t all Print messages from all below\n"); + printf(" \t batman Messages related to routing / flooding / broadcasting\n"); + printf(" \t routes Messages related to route added / changed / deleted\n"); + printf(" \t tt Messages related to translation table operations\n"); }
int handle_loglevel(char *mesh_iface, int argc, char **argv) { int optchar, res; - int log_level; + int log_level = 0; char *path_buff; + char str[4]; + int i;
while ((optchar = getopt(argc, argv, "h")) != -1) { switch (optchar) { @@ -200,7 +208,25 @@ int handle_loglevel(char *mesh_iface, int argc, char **argv) snprintf(path_buff, PATH_BUFF_LEN, SYS_BATIF_PATH_FMT, mesh_iface);
if (argc != 1) { - res = write_file(path_buff, SYS_LOG_LEVEL, argv[1], NULL); + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "none") == 0) { + log_level = 0; + break; + } else if (strcmp(argv[i], "all") == 0) { + log_level = 15; + break; + } else if (strcmp(argv[i], "batman") == 0) + log_level |= (1 << 0); + else if (strcmp(argv[i], "routes") == 0) + log_level |= (1 << 1); + else if (strcmp(argv[i], "tt") == 0) + log_level |= (1 << 2); + else + log_level_usage(); + } + + snprintf(str, 4, "%u", log_level); + res = write_file(path_buff, SYS_LOG_LEVEL, str, NULL); goto out; }
On Monday, November 07, 2011 19:52:39 Martin Hundebøll wrote:
As the number of log levels increases, it becomes less user friendly to assign a log level, as this is given as a bitmask in decimal form. This commit changes this, so that one or more log levels can be given as human readable words (e.g. "batctl ll batman routes").
The "Signed-off-by" is missing.
snprintf(str, 4, "%u", log_level);
res = write_file(path_buff, SYS_LOG_LEVEL, str, NULL);
Shouldn't it be "sizeof(str)" instead of "4" and "%i" instead of "%u" ?
Regards, Marek
As the number of log levels increases, it becomes less user friendly to assign a log level, as this is given as a bitmask in decimal form. This patch changes this, so that one or more log levels can be given as human readable words (e.g. "batctl ll batman routes").
Signed-off-by: Martin Hundebøll martin@hundeboll.net --- sys.c | 32 +++++++++++++++++++++++++++++--- 1 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/sys.c b/sys.c index 4f2b2c5..9cf8a06 100644 --- a/sys.c +++ b/sys.c @@ -174,16 +174,24 @@ err:
static void log_level_usage(void) { - printf("Usage: batctl [options] loglevel [level]\n"); + printf("Usage: batctl [options] loglevel [level[ level[ level]]...]\n"); printf("options:\n"); printf(" \t -h print this help\n"); + printf("levels:\n"); + printf(" \t none Debug logging is disabled\n"); + printf(" \t all Print messages from all below\n"); + printf(" \t batman Messages related to routing / flooding / broadcasting\n"); + printf(" \t routes Messages related to route added / changed / deleted\n"); + printf(" \t tt Messages related to translation table operations\n"); }
int handle_loglevel(char *mesh_iface, int argc, char **argv) { int optchar, res; - int log_level; + int log_level = 0; char *path_buff; + char str[4]; + int i;
while ((optchar = getopt(argc, argv, "h")) != -1) { switch (optchar) { @@ -200,7 +208,25 @@ int handle_loglevel(char *mesh_iface, int argc, char **argv) snprintf(path_buff, PATH_BUFF_LEN, SYS_BATIF_PATH_FMT, mesh_iface);
if (argc != 1) { - res = write_file(path_buff, SYS_LOG_LEVEL, argv[1], NULL); + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "none") == 0) { + log_level = 0; + break; + } else if (strcmp(argv[i], "all") == 0) { + log_level = 15; + break; + } else if (strcmp(argv[i], "batman") == 0) + log_level |= (1 << 0); + else if (strcmp(argv[i], "routes") == 0) + log_level |= (1 << 1); + else if (strcmp(argv[i], "tt") == 0) + log_level |= (1 << 2); + else + log_level_usage(); + } + + snprintf(str, sizeof(str), "%i", log_level); + res = write_file(path_buff, SYS_LOG_LEVEL, str, NULL); goto out; }
On Monday, November 07, 2011 20:14:31 Martin Hundebøll wrote:
As the number of log levels increases, it becomes less user friendly to assign a log level, as this is given as a bitmask in decimal form. This patch changes this, so that one or more log levels can be given as human readable words (e.g. "batctl ll batman routes").
Applied in revision edab69b.
Thanks, Marek
b.a.t.m.a.n@lists.open-mesh.org