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
---------------
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[Index of Archives]
[Kernel Newbies]
[Netfilter]
[Bugtraq]
[Photo]
[Stuff]
[Gimp]
[Yosemite News]
[MIPS Linux]
[ARM Linux]
[Linux Security]
[Linux RAID]
[Video 4 Linux]
[Linux for the blind]
[Linux Resources]