<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.koansoftware.com/index.php?action=history&amp;feed=atom&amp;title=Kernel_message_logging_with_printk</id>
	<title>Kernel message logging with printk - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.koansoftware.com/index.php?action=history&amp;feed=atom&amp;title=Kernel_message_logging_with_printk"/>
	<link rel="alternate" type="text/html" href="https://wiki.koansoftware.com/index.php?title=Kernel_message_logging_with_printk&amp;action=history"/>
	<updated>2026-04-17T18:00:11Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.15</generator>
	<entry>
		<id>https://wiki.koansoftware.com/index.php?title=Kernel_message_logging_with_printk&amp;diff=294&amp;oldid=prev</id>
		<title>Koan: Created page with &quot;== Kernel message logging with printk ==  printk() is one of the most widely known functions in the Linux kernel. It&#039;s the standard tool we have for printing messages and usua...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.koansoftware.com/index.php?title=Kernel_message_logging_with_printk&amp;diff=294&amp;oldid=prev"/>
		<updated>2021-07-11T10:00:17Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;== Kernel message logging with printk ==  printk() is one of the most widely known functions in the Linux kernel. It&amp;#039;s the standard tool we have for printing messages and usua...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Kernel message logging with printk ==&lt;br /&gt;
&lt;br /&gt;
printk() is one of the most widely known functions in the Linux kernel. It&amp;#039;s the&lt;br /&gt;
standard tool we have for printing messages and usually the most basic way of&lt;br /&gt;
tracing and debugging. If you&amp;#039;re familiar with printf(3) you can tell printk()&lt;br /&gt;
is based on it, although it has some functional differences:&lt;br /&gt;
&lt;br /&gt;
* printk() messages can specify a log level.&lt;br /&gt;
&lt;br /&gt;
* the format string, while largely compatible with C99, doesn&amp;#039;t follow the exact same specification. It has some extensions and a few limitations (no ``%n`` or floating point conversion specifiers). See :ref:`How to get printk format specifiers right &amp;lt;printk-specifiers&amp;gt;`.&lt;br /&gt;
&lt;br /&gt;
All printk() messages are printed to the kernel log buffer, which is a ring&lt;br /&gt;
buffer exported to userspace through /dev/kmsg. The usual way to read it is&lt;br /&gt;
using ``dmesg``.&lt;br /&gt;
&lt;br /&gt;
printk() is typically used like this::&lt;br /&gt;
&lt;br /&gt;
  printk(KERN_INFO &amp;quot;Message: %s\n&amp;quot;, arg);&lt;br /&gt;
&lt;br /&gt;
where ``KERN_INFO`` is the log level (note that it&amp;#039;s concatenated to the format&lt;br /&gt;
string, the log level is not a separate argument). The available log levels are:&lt;br /&gt;
&lt;br /&gt;
 +----------------+--------+-----------------------------------------------+&lt;br /&gt;
 | Name           | String |  Alias function                               |&lt;br /&gt;
 +================+========+===============================================+&lt;br /&gt;
 | KERN_EMERG     | &amp;quot;0&amp;quot;    | pr_emerg()                                    |&lt;br /&gt;
 +----------------+--------+-----------------------------------------------+&lt;br /&gt;
 | KERN_ALERT     | &amp;quot;1&amp;quot;    | pr_alert()                                    |&lt;br /&gt;
 +----------------+--------+-----------------------------------------------+&lt;br /&gt;
 | KERN_CRIT      | &amp;quot;2&amp;quot;    | pr_crit()                                     |&lt;br /&gt;
 +----------------+--------+-----------------------------------------------+&lt;br /&gt;
 | KERN_ERR       | &amp;quot;3&amp;quot;    | pr_err()                                      |&lt;br /&gt;
 +----------------+--------+-----------------------------------------------+&lt;br /&gt;
 | KERN_WARNING   | &amp;quot;4&amp;quot;    | pr_warn()                                     |&lt;br /&gt;
 +----------------+--------+-----------------------------------------------+&lt;br /&gt;
 | KERN_NOTICE    | &amp;quot;5&amp;quot;    | pr_notice()                                   |&lt;br /&gt;
 +----------------+--------+-----------------------------------------------+&lt;br /&gt;
 | KERN_INFO      | &amp;quot;6&amp;quot;    | pr_info()                                     |&lt;br /&gt;
 +----------------+--------+-----------------------------------------------+&lt;br /&gt;
 | KERN_DEBUG     | &amp;quot;7&amp;quot;    | pr_debug() and pr_devel() if DEBUG is defined |&lt;br /&gt;
 +----------------+--------+-----------------------------------------------+&lt;br /&gt;
 | KERN_DEFAULT   | &amp;quot;&amp;quot;     |                                               |&lt;br /&gt;
 +----------------+--------+-----------------------------------------------+&lt;br /&gt;
 | KERN_CONT      | &amp;quot;c&amp;quot;    | pr_cont()                                     |&lt;br /&gt;
 +----------------+--------+-----------------------------------------------+ &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can check the current console_loglevel with:&lt;br /&gt;
&lt;br /&gt;
 $ cat /proc/sys/kernel/printk&lt;br /&gt;
 4        4        1        7&lt;br /&gt;
&lt;br /&gt;
The result shows the current, default, minimum and boot-time-default log levels.&lt;br /&gt;
&lt;br /&gt;
To change the current console_loglevel simply write the desired level to /proc/sys/kernel/printk. &lt;br /&gt;
&lt;br /&gt;
For example, to print all messages to the console:&lt;br /&gt;
&lt;br /&gt;
 # echo 8 &amp;gt; /proc/sys/kernel/printk&lt;br /&gt;
&lt;br /&gt;
Another way, using dmesg:&lt;br /&gt;
&lt;br /&gt;
 # dmesg -n 5&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Reference: https://www.kernel.org/doc/html/v5.12-rc3/core-api/printk-basics.html&lt;/div&gt;</summary>
		<author><name>Koan</name></author>
	</entry>
</feed>