introduce runtime loglevel
With this the verbosity of barebox can be controlled during runtime using the 'loglevel' globalvar. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
parent
61694c93cd
commit
666f12e0c1
|
@ -607,7 +607,7 @@ endmenu
|
||||||
menu "Debugging"
|
menu "Debugging"
|
||||||
|
|
||||||
config COMPILE_LOGLEVEL
|
config COMPILE_LOGLEVEL
|
||||||
int "loglevel"
|
int "compile loglevel"
|
||||||
default 6
|
default 6
|
||||||
help
|
help
|
||||||
This defines the maximum loglevel compiled into the binary. Less important
|
This defines the maximum loglevel compiled into the binary. Less important
|
||||||
|
@ -622,6 +622,22 @@ config COMPILE_LOGLEVEL
|
||||||
6 informational (info)
|
6 informational (info)
|
||||||
7 debug-level messages (debug)
|
7 debug-level messages (debug)
|
||||||
|
|
||||||
|
config DEFAULT_LOGLEVEL
|
||||||
|
int "default loglevel"
|
||||||
|
default 7
|
||||||
|
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
|
config DEBUG_INFO
|
||||||
bool
|
bool
|
||||||
prompt "enable debug symbols"
|
prompt "enable debug symbols"
|
||||||
|
|
|
@ -57,6 +57,33 @@ void console_allow_input(bool val)
|
||||||
console_input_allow = 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, ...)
|
int printf(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include <command.h>
|
#include <command.h>
|
||||||
#include <driver.h>
|
#include <driver.h>
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
|
#include <console.h>
|
||||||
#include <linux/ctype.h>
|
#include <linux/ctype.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fs.h>
|
#include <fs.h>
|
||||||
|
@ -370,11 +371,14 @@ const char *dev_id(const struct device_d *dev)
|
||||||
return buf;
|
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;
|
va_list args;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
|
if (level > barebox_loglevel)
|
||||||
|
return 0;
|
||||||
|
|
||||||
if (dev->driver && dev->driver->name)
|
if (dev->driver && dev->driver->name)
|
||||||
ret += printf("%s ", dev->driver->name);
|
ret += printf("%s ", dev->driver->name);
|
||||||
|
|
||||||
|
|
|
@ -57,4 +57,6 @@ extern struct list_head console_list;
|
||||||
bool console_is_input_allow(void);
|
bool console_is_input_allow(void);
|
||||||
void console_allow_input(bool val);
|
void console_allow_input(bool val);
|
||||||
|
|
||||||
|
extern int barebox_loglevel;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -18,12 +18,15 @@
|
||||||
|
|
||||||
/* debugging and troubleshooting/diagnostic helpers. */
|
/* 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)));
|
__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...) \
|
#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...) \
|
#define __pr_printk(level, format, args...) \
|
||||||
({ \
|
({ \
|
||||||
(level) <= LOGLEVEL ? printk((format), ##args) : 0; \
|
(level) <= LOGLEVEL ? pr_print((level), (format), ##args) : 0; \
|
||||||
})
|
})
|
||||||
|
|
||||||
#ifndef pr_fmt
|
#ifndef pr_fmt
|
||||||
|
|
Loading…
Reference in New Issue