Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>yes, you can. All kernel messages can hold syslog-ng daemon. For this daemon you can write custom rules and put all messages from your module to specific file. Take first look at /etc/syslog-ng/syslog-ng.conf</p> <p><strong>update</strong></p> <p>By default, all kernel print and printk functions put messages to kernel ring buffer. Userspace programs can access to this ring buffer thought /proc/kmsg file. </p> <p>Syslog-ng will read data from /proc/kmsg, then, via filter (filter is just special pattern) grep output and put data in different output (in this example it will be just text files). If in output buffer we will find output from kernel module "hello", syslog-ng will put messages to /var/log/hello, all other messages will go to /var/log/messages</p> <p>Module source</p> <pre><code>#include &lt;linux/module.h&gt; #include &lt;linux/kernel.h&gt; #define MODNAME "[hello]" int init_module(void) { printk(KERN_WARNING MODNAME "Hello world 1.\n"); return 1; } void cleanup_module(void) { printk(KERN_ALERT "Goodbye world 1.\n"); } </code></pre> <p>After insmod</p> <blockquote> <p>insmod hello-1.ko</p> </blockquote> <p>in /var/log/messages you can find:</p> <blockquote> <p>Sep 20 17:46:20 ns1 kernel: [96643.968650] [hello]Hello world 1.</p> </blockquote> <p>ok, lets configure syslog-ng to catch grep log message (by using pattern [hello])</p> <p>$cat /etc/syslog-ng/syslog-ng.conf</p> <pre><code>@version: 3.2 # $Header: /var/cvsroot/gentoo-x86/app-admin/syslog-ng/files/syslog-ng.conf.gentoo.3.2,v 1.1 2011/01/18 17:44:14 mr_bones_ Exp $ # # Syslog-ng default configuration file for Gentoo Linux options { chain_hostnames(no); stats_freq(43200); mark_freq(3600); }; source src { unix-stream("/dev/log" max-connections(256)); internal(); file("/proc/kmsg"); }; destination messages { file("/var/log/messages"); }; # output file for ower module destination hello_messages { file("/var/log/hello"); }; # grep patterns for ower module filter f_hello { match("hello" value("MESSAGE")); }; filter f_kernel { facility(kern); }; log { source(src); destination(messages); }; log { source(src); destination(console_all); }; # target for logging log { source(src); filter(f_hello); filter(f_kernel); destination(hello_messages); }; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload