2 .\" Copyright (C) 1995 Andries Brouwer (aeb@cwi.nl)
3 .\" and Copyright (C) 2012, 2014 Michael Kerrisk <mtk.manpages@gmail.com>
5 .\" %%%LICENSE_START(VERBATIM)
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date. The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein. The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
27 .\" Written 11 June 1995 by Andries Brouwer <aeb@cwi.nl>
28 .\" 2008-02-15, Jeremy Kerr <jk@ozlabs.org>
29 .\" Add info on command type 10; add details on types 6, 7, 8, & 9.
30 .\" 2008-02-15, Michael Kerrisk <mtk.manpages@gmail.com>
31 .\" Update LOG_BUF_LEN details; update RETURN VALUE section.
33 .TH SYSLOG 2 2015-05-07 "Linux" "Linux Programmer's Manual"
35 syslog, klogctl \- read and/or clear kernel message ring buffer;
39 .BI "int syslog(int " type ", char *" bufp ", int " len );
40 .B " /* No wrapper provided in glibc */"
42 /* The glibc interface */
44 .B "#include <sys/klog.h>"
46 .BI "int klogctl(int " type ", char *" bufp ", int " len );
50 Probably, you are looking for the C library function
58 This page describes the kernel
60 system call, which is used to control the kernel
62 buffer; the glibc wrapper function for the system call is called
64 .SS The kernel log buffer
65 The kernel has a cyclic buffer of length
67 in which messages given as arguments to the kernel function
69 are stored (regardless of their log level).
73 from kernel 1.3.54, it was 8192;
74 from kernel 2.1.113, it was 16384;
75 since kernel 2.4.23/2.6, the value is a kernel configuration option
76 .RB ( CONFIG_LOG_BUF_SHIFT ,
77 default value dependent on the architecture).
78 .\" Under "General setup" ==> "Kernel log buffer size"
79 .\" For 2.6, precisely the option seems to have appeared in 2.5.55.
80 Since Linux 2.6.6, the size can be queried with command type 10 (see below).
82 The \fItype\fP argument determines the action taken by this function.
83 The list below specifies the values for
85 The symbolic names are defined in the kernel source,
86 but are not exported to user space;
87 you will either need to use the numbers, or define the names yourself.
89 .BR SYSLOG_ACTION_CLOSE " (0)"
93 .BR SYSLOG_ACTION_OPEN " (1)"
97 .BR SYSLOG_ACTION_READ " (2)"
100 waits until the kernel log buffer is nonempty, and then reads
101 at most \fIlen\fP bytes into the buffer pointed to by
103 The call returns the number of bytes read.
104 Bytes read from the log disappear from the log buffer:
105 the information can be read only once.
106 This is the function executed by the kernel when a user program reads
109 .BR SYSLOG_ACTION_READ_ALL " (3)"
110 Read all messages remaining in the ring buffer,
111 placing them in the buffer pointed to by
113 The call reads the last \fIlen\fP
114 bytes from the log buffer (nondestructively),
115 but will not read more than was written into the buffer since the
116 last "clear ring buffer" command (see command 5 below)).
117 The call returns the number of bytes read.
119 .BR SYSLOG_ACTION_READ_CLEAR " (4)"
120 Read and clear all messages remaining in the ring buffer.
121 The call does precisely the same as for a
123 of 3, but also executes the "clear ring buffer" command.
125 .BR SYSLOG_ACTION_CLEAR " (5)"
126 The call executes just the "clear ring buffer" command.
131 arguments are ignored.
133 This command does not really clear the ring buffer.
134 Rather, it sets a kernel bookkeeping variable that
135 determines the results returned by commands 3
136 .RB ( SYSLOG_ACTION_READ_ALL )
138 .RB ( SYSLOG_ACTION_READ_CLEAR ).
139 This command has no effect on commands 2
140 .RB ( SYSLOG_ACTION_READ )
142 .RB ( SYSLOG_ACTION_SIZE_UNREAD ).
144 .BR SYSLOG_ACTION_CONSOLE_OFF " (6)"
145 The command saves the current value of
150 .IR minimum_console_loglevel ,
151 so that no messages are printed to the console.
153 .\" commit 1aaad49e856ce41adc07d8ae0c8ef35fc4483245
154 the command simply sets
157 .IR minimum_console_loglevel .
158 See the discussion of
159 .IR /proc/sys/kernel/printk ,
166 arguments are ignored.
168 .BR SYSLOG_ACTION_CONSOLE_ON " (7)"
170 .B SYSLOG_ACTION_CONSOLE_OFF
171 command has been performed,
172 this command restores
174 to the value that was saved by that command.
176 .\" commit 1aaad49e856ce41adc07d8ae0c8ef35fc4483245
177 this command simply sets
180 .IR default_console_loglevel .
181 See the discussion of
182 .IR /proc/sys/kernel/printk ,
189 arguments are ignored.
191 .BR SYSLOG_ACTION_CONSOLE_LEVEL " (8)"
194 to the value given in
196 which must be an integer between 1 and 8 (inclusive).
197 The kernel silently enforces a minimum value of
198 .IR minimum_console_loglevel
208 .BR SYSLOG_ACTION_SIZE_UNREAD " (9) (since Linux 2.4.10)"
210 returns the number of bytes currently available to be read
211 from the kernel log buffer via command 2
212 .RB ( SYSLOG_ACTION_READ ).
217 arguments are ignored.
219 .BR SYSLOG_ACTION_SIZE_BUFFER " (10) (since Linux 2.6.6)"
220 This command returns the total size of the kernel log buffer.
225 arguments are ignored.
227 All commands except 3 and 10 require privilege.
228 In Linux kernels before 2.6.37,
229 command types 3 and 10 are allowed to unprivileged processes;
231 these commands are allowed to unprivileged processes only if
232 .IR /proc/sys/kernel/dmesg_restrict
234 Before Linux 2.6.37, "privileged" means that the caller has the
238 "privileged" means that the caller has either the
240 capability (now deprecated for this purpose) or the (new)
245 .SS /proc/sys/kernel/printk
246 .I /proc/sys/kernel/printk
247 is a writable file containing four integer values that influence kernel
249 behavior when printing or logging error messages.
253 Only messages with a log level lower than this value will
254 be printed to the console.
255 The default value for this field is
256 .B DEFAULT_CONSOLE_LOGLEVEL
257 (7), but it is set to
258 4 if the kernel command line contains the word "quiet", \" since Linux 2.4
259 10 if the kernel command line contains the word "debug",
261 of a kernel fault (the 10 and 15 are just silly, and equivalent to 8).
264 can be set (to a value in the range 1\(en8) by a
270 .I default_message_loglevel
271 This value will be used as the log level for
273 messages that do not have an explicit level.
274 Up to and including Linux 2.6.38,
275 the hard-coded default value for this field was 4
276 .RB ( KERN_WARNING );
278 .\" commit 5af5bcb8d37f99ba415a1adc6da71051b84f93a5
279 the default value is a defined by the kernel configuration option
280 .BR CONFIG_DEFAULT_MESSAGE_LOGLEVEL ,
283 .I minimum_console_loglevel
284 The value in this field is the minimum value to which
288 .I default_console_loglevel
289 This is the default value for
290 .IR console_loglevel .
296 message has its own log level.
297 If the log level is not explicitly specified as part of the message,
299 .IR default_message_loglevel .
300 The conventional meaning of the log level is as follows:
304 Kernel constant Level value Meaning
305 KERN_EMERG 0 System is unusable
306 KERN_ALERT 1 Action must be taken immediately
307 KERN_CRIT 2 Critical conditions
308 KERN_ERR 3 Error conditions
309 KERN_WARNING 4 Warning conditions
310 KERN_NOTICE 5 Normal but significant condition
311 KERN_INFO 6 Informational
312 KERN_DEBUG 7 Debug-level messages
317 routine will print a message on the
318 console only if it has a log level less than the value of
319 .IR console_loglevel .
321 For \fItype\fP equal to 2, 3, or 4, a successful call to
327 returns the number of bytes currently
328 available to be read on the kernel log buffer.
331 returns the total size of the kernel log buffer.
332 For other values of \fItype\fP, 0 is returned on success.
334 In case of error, \-1 is returned,
335 and \fIerrno\fP is set to indicate the error.
349 is less than zero; or for
353 is outside the range 1 to 8).
358 system call is not available, because the kernel was compiled with the
360 kernel-configuration option disabled.
363 An attempt was made to change
366 message ring buffer by a process without sufficient privilege
367 (more precisely: without the
374 System call was interrupted by a signal; nothing was read.
375 (This can be seen only during a trace.)
377 This system call is Linux-specific and should not be used in programs
378 intended to be portable.
380 From the very start, people noted that it is unfortunate that
381 a system call and a library routine of the same name are entirely
383 .\" In libc4 and libc5 the number of this call was defined by
385 .\" In glibc 2.0 the syscall is baptized