What are Linux warning levels?

Linux kernel logs help system administrators fix critical issues by providing information about the state of the system or the daemons that are running. Log levels are used as filters so that any log messages with a lower level and a higher severity are displayed. There are eight log levels based on their severity.

  1. KERN_EMERG (0)

    The highest severity level warning. It is used when the system is unstable.

  2. KERN_ALERT (1)

    This log level is used when the error requires immediate user attention.

  3. KERN_CRIT (2)

    A log level of 2 is used to inform the user of critical software or hardware issues.

  4. KERN_ERR (3)

    Messages pertaining to a log level of 3 are usually used to inform the user of noncritical errors.

  5. KERN_WARNING (4)

    The default log level in many Linux distributions. It is used to display warnings about non-important errors.

  6. KERN_NOTICE (5)

    A log level of 5 is used to represent normal but significant conditions.

  7. KERN_INFO (6)

    KERN_INFO is used to display informational messages.

  8. KERN_DEBUG (7)

    KERN_DEBUG is used when the system is in debug mode. These messages contain information that is normally only useful when debugging a program.

Checking the log level of your system

Checking the log level of your system is a simple and straightforward process. The following command outputs the log level:

$ cat /proc/sys/kernel/printk

This command will output something like this:

 4	4	1	7
Terminal 1
Terminal
Loading...

Here, the first value represents console_loglevel. This is the current log level used by the system.

The second value represents default_message_loglevel. When a log level is not specified with a message, this is the value that is used.

The third value represents the minimum_console_loglevel. This is the minimum log level value that can be used for console_loglevel, which is usually 1.

The last value is default_console_loglevel, which is the default value of the log level used at boot.

Changing the log level

The log level can be changed using the following command:

$ echo <"loglevel"> | sudo tee /proc/sys/kernel/printk

Or, with root privileges, you can simply run the following command:

echo "3" > /proc/sys/kernel/printk

However, these are temporary ways of changing the log level. When the system restarts, the log will be reset. To change the log level in a persistent way, you have to change the log level from the GRUB boot loader at boot time.

Copyright ©2024 Educative, Inc. All rights reserved