mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: Re: [PATCH v2] introduce runtime loglevel
Date: Sun, 29 Sep 2013 12:18:56 +0200	[thread overview]
Message-ID: <20130929101856.GW30088@pengutronix.de> (raw)
In-Reply-To: <1380302397-20010-1-git-send-email-s.hauer@pengutronix.de>

On Fri, Sep 27, 2013 at 07:19:57PM +0200, Sascha Hauer wrote:
> With this the verbosity of barebox can be controlled during runtime
> using the 'loglevel' globalvar.
> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
> 
> +config DEFAULT_LOGLEVEL
> +	int "default loglevel"
> +	default 6

Changed the default to '7'. Reason is that normally when we #define
DEBUG in a file we see the debug messages. With a default loglevel of
'6' we wouldn't see them even if DEBUG is defined.

Sascha

> +	help
> +	  This defines the default runtime loglevel. It can be changed using the
> +	  global.loglevel variable. Available logelevels are:
> +
> +	  0    system is unusable (emerg)
> +	  1    action must be taken immediately (alert)
> +	  2    critical conditions (crit)
> +	  3    error conditions (err)
> +	  4    warning conditions (warn)
> +	  5    normal but significant condition (notice)
> +	  6    informational (info)
> +	  7    debug-level messages (debug)
> +
>  config DEBUG_INFO
>  	bool
>  	prompt "enable debug symbols"
> diff --git a/common/console_common.c b/common/console_common.c
> index d1b823e..18b7676 100644
> --- a/common/console_common.c
> +++ b/common/console_common.c
> @@ -57,6 +57,33 @@ void console_allow_input(bool val)
>  	console_input_allow = val;
>  }
>  
> +int barebox_loglevel = CONFIG_DEFAULT_LOGLEVEL;
> +
> +int pr_print(int level, const char *fmt, ...)
> +{
> +	va_list args;
> +	uint i;
> +	char printbuffer[CFG_PBSIZE];
> +
> +	if (level > barebox_loglevel)
> +		return 0;
> +
> +	va_start(args, fmt);
> +	i = vsprintf(printbuffer, fmt, args);
> +	va_end(args);
> +
> +	/* Print the string */
> +	puts(printbuffer);
> +
> +	return i;
> +}
> +
> +static int loglevel_init(void)
> +{
> +	return globalvar_add_simple_int("loglevel", &barebox_loglevel, "%d");
> +}
> +device_initcall(loglevel_init);
> +
>  int printf(const char *fmt, ...)
>  {
>  	va_list args;
> diff --git a/drivers/base/driver.c b/drivers/base/driver.c
> index 16b7f06..e587e3a 100644
> --- a/drivers/base/driver.c
> +++ b/drivers/base/driver.c
> @@ -26,6 +26,7 @@
>  #include <command.h>
>  #include <driver.h>
>  #include <malloc.h>
> +#include <console.h>
>  #include <linux/ctype.h>
>  #include <errno.h>
>  #include <fs.h>
> @@ -370,11 +371,14 @@ const char *dev_id(const struct device_d *dev)
>  	return buf;
>  }
>  
> -int dev_printf(const struct device_d *dev, const char *format, ...)
> +int dev_printf(int level, const struct device_d *dev, const char *format, ...)
>  {
>  	va_list args;
>  	int ret = 0;
>  
> +	if (level > barebox_loglevel)
> +		return 0;
> +
>  	if (dev->driver && dev->driver->name)
>  		ret += printf("%s ", dev->driver->name);
>  
> diff --git a/include/console.h b/include/console.h
> index e94c5ae..393579b 100644
> --- a/include/console.h
> +++ b/include/console.h
> @@ -57,4 +57,6 @@ extern struct list_head console_list;
>  bool console_is_input_allow(void);
>  void console_allow_input(bool val);
>  
> +extern int barebox_loglevel;
> +
>  #endif
> diff --git a/include/printk.h b/include/printk.h
> index 86bf208..f550f07 100644
> --- a/include/printk.h
> +++ b/include/printk.h
> @@ -18,12 +18,15 @@
>  
>  /* debugging and troubleshooting/diagnostic helpers. */
>  
> -int dev_printf(const struct device_d *dev, const char *format, ...)
> +int pr_print(int level, const char *format, ...)
>  	__attribute__ ((format(__printf__, 2, 3)));
>  
> +int dev_printf(int level, const struct device_d *dev, const char *format, ...)
> +	__attribute__ ((format(__printf__, 3, 4)));
> +
>  #define __dev_printf(level, dev, format, args...) \
>  	({	\
> -		(level) <= LOGLEVEL ? dev_printf((dev), (format), ##args) : 0; \
> +		(level) <= LOGLEVEL ? dev_printf((level), (dev), (format), ##args) : 0; \
>  	 })
>  
>  
> @@ -46,7 +49,7 @@ int dev_printf(const struct device_d *dev, const char *format, ...)
>  
>  #define __pr_printk(level, format, args...) \
>  	({	\
> -		(level) <= LOGLEVEL ? printk((format), ##args) : 0; \
> +		(level) <= LOGLEVEL ? pr_print((level), (format), ##args) : 0; \
>  	 })
>  
>  #ifndef pr_fmt
> -- 
> 1.8.4.rc3
> 
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

      reply	other threads:[~2013-09-29 10:19 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-27 17:19 Sascha Hauer
2013-09-29 10:18 ` Sascha Hauer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130929101856.GW30088@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox