by
gdt » Sat Jul 21, 2012 3:02 pm
(Note to moderators: it would be nice if the configuration below became the default on the RPi's images, as it will make people's SD cards last longer. If you could bring it to the attention of the person responsible for such things, then that would be appreciated).
I've just had a play, and you can make rsyslog send to /dev/kmsg (which is readable by dmesg).
Edit /etc/rsyslog.conf
Remove "$ModLoad imklog" since we don't want to log kernel messages back to the kernel, and thus loop infinitely.
Similarly, alter the line starting "kern.*" to be "kern.* ~" (ie, discard kernel messages, don't fret as they are still in the kernel's message ring buffer).
Now for every line that writes to a file, replace the filename with "|/dev/kmsg". For example, the line
daemon.* -/var/log/daemon.log
becomes
daemon.* |/dev/kmsg
Restart rsyslog with
/etc/init.d/rsyslog restart
Now there should be no syslog messages written to /var/log.
To see the most recent syslogged messages enter the command
dmesg
When cleaning up, do not delete files in /var/syslog. Rather say "echo -n > /var/log/syslog". This removes the contents of the file, but keeps the file's ownership and permissions, which can be important if it is something other than rsyslog which was writing to the file.
Note that this isn't the best way to write to the kernel's log buffer (the kernel isn't told the message's attributes, such as "facility" or "priority" and it incorrectly classifies the message as kernel space rather than user space). To do it properly a rsyslog output module should be written. Also this isn't the most efficient approach -- having the kernel maintain the log is necessarily less efficient than doing it from user space. But it's not like the RPi writes enough messages that we overly care about the message's metadata or its efficiency. We rather take the reduced writes to the SD card, both so that the RPi runs more quickly and so the SD card lasts longer.