public inbox for b.a.t.m.a.n@lists.open-mesh.org
 help / color / mirror / Atom feed
* [B.A.T.M.A.N.] [PATCH] batctl: Human readable log levels instead of bitmasks
@ 2011-11-07 11:52 Martin Hundebøll
  2011-11-07 12:00 ` Marek Lindner
  2011-11-07 12:14 ` [B.A.T.M.A.N.] [PATCHv2] " Martin Hundebøll
  0 siblings, 2 replies; 4+ messages in thread
From: Martin Hundebøll @ 2011-11-07 11:52 UTC (permalink / raw)
  To: b.a.t.m.a.n

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;
 	}
 
-- 
1.7.7.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [B.A.T.M.A.N.] [PATCH] batctl: Human readable log levels instead of bitmasks
  2011-11-07 11:52 [B.A.T.M.A.N.] [PATCH] batctl: Human readable log levels instead of bitmasks Martin Hundebøll
@ 2011-11-07 12:00 ` Marek Lindner
  2011-11-07 12:14 ` [B.A.T.M.A.N.] [PATCHv2] " Martin Hundebøll
  1 sibling, 0 replies; 4+ messages in thread
From: Marek Lindner @ 2011-11-07 12:00 UTC (permalink / raw)
  To: The list for a Better Approach To Mobile Ad-hoc Networking

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [B.A.T.M.A.N.] [PATCHv2] batctl: Human readable log levels instead of bitmasks
  2011-11-07 11:52 [B.A.T.M.A.N.] [PATCH] batctl: Human readable log levels instead of bitmasks Martin Hundebøll
  2011-11-07 12:00 ` Marek Lindner
@ 2011-11-07 12:14 ` Martin Hundebøll
  2011-11-08 17:41   ` Marek Lindner
  1 sibling, 1 reply; 4+ messages in thread
From: Martin Hundebøll @ 2011-11-07 12:14 UTC (permalink / raw)
  To: b.a.t.m.a.n

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;
 	}
 
-- 
1.7.7.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [B.A.T.M.A.N.] [PATCHv2] batctl: Human readable log levels instead of bitmasks
  2011-11-07 12:14 ` [B.A.T.M.A.N.] [PATCHv2] " Martin Hundebøll
@ 2011-11-08 17:41   ` Marek Lindner
  0 siblings, 0 replies; 4+ messages in thread
From: Marek Lindner @ 2011-11-08 17:41 UTC (permalink / raw)
  To: The list for a Better Approach To Mobile Ad-hoc Networking

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-11-08 17:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-07 11:52 [B.A.T.M.A.N.] [PATCH] batctl: Human readable log levels instead of bitmasks Martin Hundebøll
2011-11-07 12:00 ` Marek Lindner
2011-11-07 12:14 ` [B.A.T.M.A.N.] [PATCHv2] " Martin Hundebøll
2011-11-08 17:41   ` Marek Lindner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox