User: Password:
|
|
Subscribe / Log in / New account

Toward more reliable logging

Toward more reliable logging

Posted Apr 13, 2012 21:06 UTC (Fri) by slashdot (guest, #22014)
Parent article: Toward more reliable logging

The dictionary API seems a totally wrong design, because it has redundant information, is incredibly cumbersome to use and thus is not likely to be used by anyone.

MUCH better API:
printk(KERN_EMERG "%[subsys]s: %[dev]s: device caught fire", subsys_name, dev_name);

Then just output the format string and arguments separately instead of doing formatting in the kernel (and of course, emulate the old interface by doing it in the kernel on demand).

For info that shouldn't be in the human-readable output, add a special syntax such as %{subsys}s that doesn't output anything.


(Log in to post comments)

Toward more reliable logging

Posted Apr 14, 2012 18:48 UTC (Sat) by smurf (subscriber, #17840) [Link]

This work until you happen to come across a substituted string which happens to contain a colon.
Your proposal also is much more complicated, for no tangible gain AFAICS.

Toward more reliable logging

Posted Apr 15, 2012 0:40 UTC (Sun) by slashdot (guest, #22014) [Link]

You don't parse the colons...

The kernel sees "%[subsys]s" and adds the argument as the value of the "subsys" key, using the same format (or alternatively, just prints the unformatted format string, and userspace does the work).

This would make the API easy to use, compared to the patch which requires horrible code like this:

char* buf = kmalloc(64 + strlen(subsys_name) + strlen(dev_name));
sprintf(buf, "SUBSYS=%s\nDEVICE=%s\n", subsys_name, dev_name);
printk_emit(buf, strlen(buf), KERN_EMERG "%s: %s: device caught fire", subsys_name, dev_name);
kfree(buf);

Compare that to just:
printk(KERN_EMERG "%[subsys]s: %[device]s: device caught fire", subsys_name, dev_name);

It's clear that the API in the patch is totally inferior and that almost nobody will use it except dev_printk.

Toward more reliable logging

Posted Apr 15, 2012 14:56 UTC (Sun) by abacus (guest, #49001) [Link]

Does that mean that you're not familiar with kasprintf() ?


Copyright © 2017, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds