Is there a way to create kernel log messages via Python?

Andrew Cooper andrew at nospam.example.com
Tue Oct 16 21:25:09 EDT 2012


On 16/10/2012 04:43, J wrote:
> Hi...
> 
<snip>
> 
> So, what I REALLY want is to inject my start/stop markers into klogd
> rather than syslogd.  This will, I hope, give my markers kernel
> timestamps rather than syslog timestamps which are not as accurate.
> 
> So does anyone know of a way to do this?  Unfortunately, I've tried
> some searching but google doesn't like the term klog, and most of the
> hits involved injecting code or other things that are not related at
> all.
> 
> Or, if there's a better way to get accurate timestamps, what would that be?
> 

It is very easy (about 40 lines of C) to write a kernel module which
opens up an easy interface to use.

I wrote a kernel module (unimaginatively called uklog, for user-klog)
which exports /proc/printk/{alert thru debug}.  With this in place, any
(root, although this can be changed) userspace process can issue
messages into the kernel by opening the relevant file and writing to it.

Sadly, this is not useful on any system which is not your own, and is
also unlikely to be accepted upstream (although it is fantastically
useful for micro-vms with no root filesystems, where the kernel log is
the only form of logging, and the serial console is the only useful
method of communication.)

~Andrew



More information about the Python-list mailing list