The following commit has been merged in the next branch: commit edab69b199080cf0c7eac1288441a5e37dd22278 Author: Martin Hundebøll martin@hundeboll.net Date: Mon Nov 7 13:14:31 2011 +0100
batctl: Human readable log levels instead of bitmasks
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
diff --git a/man/batctl.8 b/man/batctl.8 index 928c7e3..0cf0a7b 100644 --- a/man/batctl.8 +++ b/man/batctl.8 @@ -64,8 +64,8 @@ Once started batctl will display the list of announced gateways in the network. .IP "\fBinterval\fP|\fBit\fP [\fBorig_interval\fP]" If no parameter is given the current originator interval setting is displayed otherwise the parameter is used to set the originator interval. The interval is in units of milliseconds. .br -.IP "\fBloglevel\fP|\fBll\fP [\fBlevel\fP]" -If no parameter is given the current log level settings are displayed otherwise the parameter is used to set the log level. Level 0 disables all verbose logging. Level 1 enables messages related to routing / flooding / broadcasting. Level 2 enables messages related to route or tt entry added / changed / deleted. Level 3 enables all messages. The messages are sent to the batman-adv debug log. Use \fBbatctl log\fP to see them. Make sure to have debugging output enabled when compiling the module otherwise the output as well as the loglevel options won't be available. +.IP "\fBloglevel\fP|\fBll\fP [\fBlevel\fP[ \fBlevel\fP[ \fBlevel\fP]] \fB...\fP]" +If no parameter is given the current log level settings are displayed otherwise the parameter(s) is/are used to set the log level. Level 'none' disables all verbose logging. Level 'batman' enables messages related to routing / flooding / broadcasting. Level 'routes' enables messages related to routes being added / changed / deleted. Level 'tt' enables messages related to translation table operations. Level 'all' enables all messages. The messages are sent to the batman-adv debug log. Use \fBbatctl log\fP to see them. Make sure to have debugging output enabled when compiling the module otherwise the output as well as the loglevel options won't be available. .br .IP "\fBlog\fP|\fBl\fP [\fB-n\fP]\fP" batctl will read the batman-adv debug log which has to be compiled into the kernel module. If "-n" is given batctl will not replace the MAC addresses with bat-host names in the output. diff --git a/sys.c b/sys.c index 14fc577..bddaaa3 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; }