From: Joe Perches <joe@perches.com>
To: linux-kernel@vger.kernel.org
Subject: RFC - pr_info,warn,dbg,err and PREFIX
Date: Thu, 19 Jul 2007 17:42:38 -0700 [thread overview]
Message-ID: <1184892158.26827.41.camel@localhost> (raw)
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
---------------
reply other threads:[~2007-07-20 0:52 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=1184892158.26827.41.camel@localhost \
--to=joe@perches.com \
--cc=linux-kernel@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.