From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 08/12] introduce compile time loglevel
Date: Tue, 29 Jan 2013 09:45:43 +0100 [thread overview]
Message-ID: <1359449147-30145-9-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1359449147-30145-1-git-send-email-s.hauer@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
common/Kconfig | 16 +++++++++++++
include/printk.h | 66 +++++++++++++++++++++++++++++++-----------------------
2 files changed, 54 insertions(+), 28 deletions(-)
diff --git a/common/Kconfig b/common/Kconfig
index b60b78b..30d6107 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -637,6 +637,22 @@ endmenu
menu "Debugging"
+config COMPILE_LOGLEVEL
+ int "loglevel"
+ default 6
+ help
+ This defines the maximum loglevel compiled into the binary. Less important
+ messages will be compiled away resulting in a smaller binary.
+
+ 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/include/printk.h b/include/printk.h
index 9e6f4bd..82be308 100644
--- a/include/printk.h
+++ b/include/printk.h
@@ -10,49 +10,59 @@
#define MSG_INFO 6 /* informational */
#define MSG_DEBUG 7 /* debug-level messages */
+#ifdef DEBUG
+#define LOGLEVEL MSG_DEBUG
+#else
+#define LOGLEVEL CONFIG_COMPILE_LOGLEVEL
+#endif
+
/* debugging and troubleshooting/diagnostic helpers. */
int dev_printf(const struct device_d *dev, const char *format, ...)
__attribute__ ((format(__printf__, 2, 3)));
+#define __dev_printf(level, dev, format, args...) \
+ ({ \
+ int ret = 0; \
+ if (level <= LOGLEVEL) \
+ ret = dev_printf(dev, format, ##args); \
+ ret; \
+ })
+
#define dev_emerg(dev, format, arg...) \
- dev_printf((dev) , format , ## arg)
+ __dev_printf(0, (dev) , format , ## arg)
#define dev_alert(dev, format, arg...) \
- dev_printf((dev) , format , ## arg)
+ __dev_printf(1, (dev) , format , ## arg)
#define dev_crit(dev, format, arg...) \
- dev_printf((dev) , format , ## arg)
+ __dev_printf(2, (dev) , format , ## arg)
#define dev_err(dev, format, arg...) \
- dev_printf(dev , format , ## arg)
+ __dev_printf(3, (dev) , format , ## arg)
#define dev_warn(dev, format, arg...) \
- dev_printf((dev) , format , ## arg)
+ __dev_printf(4, (dev) , format , ## arg)
#define dev_notice(dev, format, arg...) \
- dev_printf((dev) , format , ## arg)
+ __dev_printf(5, (dev) , format , ## arg)
#define dev_info(dev, format, arg...) \
- dev_printf((dev) , format , ## arg)
-
-#if defined(DEBUG)
+ __dev_printf(6, (dev) , format , ## arg)
#define dev_dbg(dev, format, arg...) \
- dev_printf((dev) , format , ## arg)
-#else
-#define dev_dbg(dev, format, arg...) \
- ({ if (0) dev_printf((dev), format, ##arg); 0; })
-#endif
+ __dev_printf(7, (dev) , format , ## arg)
-#define pr_info(fmt, arg...) printk(fmt, ##arg)
-#define pr_notice(fmt, arg...) printk(fmt, ##arg)
-#define pr_err(fmt, arg...) printk(fmt, ##arg)
-#define pr_warning(fmt, arg...) printk(fmt, ##arg)
-#define pr_crit(fmt, arg...) printk(fmt, ##arg)
-#define pr_alert(fmt, arg...) printk(fmt, ##arg)
-#define pr_emerg(fmt, arg...) printk(fmt, ##arg)
+#define __pr_printk(level, format, args...) \
+ ({ \
+ int ret = 0; \
+ if (level <= LOGLEVEL) \
+ ret = printk(format, ##args); \
+ ret; \
+ })
-#ifdef DEBUG
-#define pr_debug(fmt, arg...) printk(fmt, ##arg)
-#define debug(fmt, arg...) printf(fmt, ##arg)
-#else
-#define pr_debug(fmt, arg...) do {} while(0)
-#define debug(fmt, arg...) do {} while(0)
-#endif
+#define pr_emerg(fmt, arg...) __pr_printk(0, fmt, ##arg)
+#define pr_alert(fmt, arg...) __pr_printk(1, fmt, ##arg)
+#define pr_crit(fmt, arg...) __pr_printk(2, fmt, ##arg)
+#define pr_warning(fmt, arg...) __pr_printk(3, fmt, ##arg)
+#define pr_err(fmt, arg...) __pr_printk(4, fmt, ##arg)
+#define pr_notice(fmt, arg...) __pr_printk(5, fmt, ##arg)
+#define pr_info(fmt, arg...) __pr_printk(6, fmt, ##arg)
+#define pr_debug(fmt, arg...) __pr_printk(7, fmt, ##arg)
+#define debug(fmt, arg...) __pr_printk(7, fmt, ##arg)
#endif
--
1.7.10.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2013-01-29 8:45 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-29 8:45 [PATCH] introduce compiletime loglevel Sascha Hauer
2013-01-29 8:45 ` [PATCH 01/12] consolidate print* in a single header Sascha Hauer
2013-01-29 8:45 ` [PATCH 02/12] mtd m25p80: consistenly switch to dev_* messages Sascha Hauer
2013-01-29 8:45 ` [PATCH 03/12] treewide: fix format specifiers Sascha Hauer
2013-01-29 8:45 ` [PATCH 04/12] nios2: Let readl return an unsigned int Sascha Hauer
2013-01-29 8:45 ` [PATCH 05/12] nios2: Use unsigned long for __kernel_size_t Sascha Hauer
2013-01-29 8:45 ` [PATCH 06/12] blackfin: " Sascha Hauer
2013-01-29 8:45 ` [PATCH 07/12] USB ehci: Use dev_* for messages Sascha Hauer
2013-01-29 8:45 ` Sascha Hauer [this message]
2013-01-29 8:45 ` [PATCH 09/12] introduce pr_fmt Sascha Hauer
2013-01-29 8:45 ` [PATCH 10/12] ARM mmu: Use pr_debug Sascha Hauer
2013-01-29 8:45 ` [PATCH 11/12] ARM pcm038: Specify pr_fmt and change messages to pr_* Sascha Hauer
2013-01-29 8:45 ` [PATCH 12/12] mtd nand: " Sascha Hauer
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=1359449147-30145-9-git-send-email-s.hauer@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