linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* RFC - pr_info,warn,dbg,err and PREFIX
@ 2007-07-20  0:42 Joe Perches
  0 siblings, 0 replies; only message in thread
From: Joe Perches @ 2007-07-20  0:42 UTC (permalink / raw)
  To: linux-kernel

A number of local #defines or functions exist which merely
add a constant prefix to printks.  Perhaps it is better
to have these functions standardized.

Thoughts?

A method to prefix pr_info messages with an arbitrary prefix
(#define PREFIX "foo") could be:

--------------------------------

#define PRINTK_stringify_1(x) #x
#define PRINTK_stringify(x) PRINTK_stringify_1(x)

#define PRINTK_USEPREFIX (strcmp(PRINTK_stringify(PREFIX), "PREFIX"))

#define PRINTK_PREFIX(PREFIX) \
({const char *p = PRINTK_USEPREFIX(PREFIX) ? PRINTK_stringify(PREFIX) + 1 : ""; p;})

#define PRINTK_PREFIXLEN(PREFIX) \
({int len = PRINTK_USEPREFIX(PREFIX) ? strlen(PRINTK_stringify(PREFIX)) - 2 : 0; len;})

#define PRINTK_PREFIXSEPARATOR(PREFIX) \
({const char *p = PRINTK_USEPREFIX(PREFIX) ? ": " : ""; p;})

#define PRINTK_PREFIXFMT "%.*s%s"
#define PRINTK_PREFIXARG PRINTK_PREFIXLEN(PREFIX), PRINTK_PREFIX(PREFIX), PRINTK_PREFIXSEPARATOR(PREFIX)

#define pr_info(fmt, arg...) printk(KERN_INFO PRINTK_PREFIXFMT fmt, PRINTK_PREFIXARG, ##arg)
#define pr_warn(fmt, arg...) printk(KERN_WARNING PRINTK_PREFIXFMT fmt, PRINTK_PREFIXARG, ##arg)
#define pr_err(fmt, arg...) printk(KERN_ERR PRINTK_PREFIXFMT fmt, PRINTK_PREFIXARG, ##arg)

---------------

With a #define of PREFIX:
	#define PREFIX "abc"
	pr_info("msg\n")
output:
	<6>abc: msg

without a #define of PREFIX:
	pr_info("msg\n")
output:
	<6>msg

---------------



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2007-07-20  0:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-20  0:42 RFC - pr_info,warn,dbg,err and PREFIX Joe Perches

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).