I have created a set of shortcut Macros for Linux Kernel printk to prefix with the module name and to have a set of aliases for severity.
#define _pp(severity, format, args...) printk(severity "%s: " #format "n", THIS_MODULE->name, ##args) #define pp_warn(args...) _pp(KERN_WARNING, args) #define pp_note(args...) _pp(KERN_NOTICE, args) #define pp_info(args...) _pp(KERN_INFO, args)
Using those Macros like this:
static int __init pretty_printk_demo_init(void) { pp_warn("Warning severity"); pp_warn("Warning, checking arguments, %s and %i", "DDD", 44); }
Now the issue is that the final output in the Kernel Ring Buffer get quoted in the following way:
[ 470.819436] pp_demo_module: "Warning severity" [ 470.819438] pp_demo_module: "Warning, checking arguments, DDD and 44"
Do you have any idea of how to avoid having this extra quotes?
For the full files please take a look at the Header and the Source File.
Thank you very much for your time and looking forward to a possible solution.
Advertisement
Answer
You have an additional #
in the macro replacement. Just remove it – format
is supposed to be a string already:
#define _pp(severity, format, args...) printk(severity "%s: " format "n", THIS_MODULE->name, ##args)
For prepending some values in kernel the pr_fmt
macro was meant to be used, like here or here or basically examples everywhere.