3

I wrote a hello word module that performs a printk when it is loaded in level ALERT and another printk when it is released with level INFO:

#include <linux/module.h>
#include <linux/kernel.h>

MODULE_LICENSE("GPL");

static int init_hello(void)
{
    printk(KERN_ALERT "init called in hello\n");
    return 0;
}

static void cleanup_hello(void)
{
    printk(KERN_INFO "cleanup called in hello\n");
}

module_init(init_hello);
module_exit(cleanup_hello);

Then I was trying to filter the kernel messages by its level, I did that using dmesg -l , but I want to see the messages as they appear, so I was using

tail -f /var/log/kern.log

Using this command I can see the messages, but how can I filter the messages by level?

I am using Ubuntu 14.04 with kernel 3.16.4

I then tried to print the messages to the console using:

echo 7 7 7 7 > /proc/sys/kernel/printk

But it doesn't print any message to the console. I tried to set the console-level using dmesg -n alert, but it doesn't work either, thus I am not sure what setting the console-level by dmesg or /proc/sys/kernel/printk does.

How can I use these levels efficiently?

Thanks for your help

  • The items in /proc are device pointers and setters. They are not files. Welcome!!! – eyoung100 Oct 9 '14 at 20:46
  • Yes, of course, I will change the text, but you got what I meant :) – Lilás Oct 9 '14 at 20:56
1

On Ubuntu 16.04, util-linux 2.27.1, you can do:

dmesg --level err,warn --raw -w

where:

  • -w follows the messages as they come
  • --level restricts which levels will show
  • --raw shows the level at the beginning of the message e.g. as <3>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.