1 .\" Copyright (C) 1995 Andries Brouwer (aeb@cwi.nl)
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" Written 11 June 1995 by Andries Brouwer <aeb@cwi.nl>
26 .\" 2008-02-15, Jeremy Kerr <jk@ozlabs.org>
27 .\" Add info on command type 10; add details on types 6, 7, 8, & 9.
28 .\" 2008-02-15, Michael Kerrisk <mtk.manpages@gmail.com>
29 .\" Update LOG_BUF_LEN details; update RETURN VALUE section.
31 .TH SYSLOG 2 2012-11-29 "Linux" "Linux Programmer's Manual"
33 syslog, klogctl \- read and/or clear kernel message ring buffer;
37 .BI "int syslog(int " type ", char *" bufp ", int " len );
38 .B " /* No wrapper provided in glibc */"
40 /* The glibc interface */
42 .B "#include <sys/klog.h>"
44 .BI "int klogctl(int " type ", char *" bufp ", int " len );
47 If you need the C library function
53 The system call of this name is about controlling the kernel
55 buffer, and the glibc wrapper function is called
57 .SS The kernel log buffer
58 The kernel has a cyclic buffer of length
60 in which messages given as arguments to the kernel function
62 are stored (regardless of their loglevel).
66 from kernel 1.3.54, it was 8192;
67 from kernel 2.1.113 it was 16384;
68 since 2.4.23/2.6 the value is a kernel configuration option
69 .RB ( CONFIG_LOG_BUF_SHIFT ).
70 .\" Under "General setup" ==> "Kernel log buffer size"
71 .\" For 2.6, precisely the option seems to have appeared in 2.5.55.
72 In recent kernels the size can be queried with command type 10 (see below).
74 The \fItype\fP argument determines the action taken by this function.
75 The list below specifies the values for
77 The symbolic names are defined in the kernel source,
78 but are not exported to user space;
79 you will either need to use the numbers, or define the names yourself.
81 .BR SYSLOG_ACTION_CLOSE " (0)"
85 .BR SYSLOG_ACTION_OPEN " (1)"
89 .BR SYSLOG_ACTION_READ " (2)"
92 waits until the kernel log buffer is nonempty, and then reads
93 at most \fIlen\fP bytes into the buffer pointed to by
95 The call returns the number of bytes read.
96 Bytes read from the log disappear from the log buffer:
97 the information can be read only once.
98 This is the function executed by the kernel when a user program reads
101 .BR SYSLOG_ACTION_READ_ALL " (3)"
102 Read all messages remaining in the ring buffer,
103 placing then in the buffer pointed to by
105 The call reads the last \fIlen\fP
106 bytes from the log buffer (nondestructively),
107 but will not read more than was written into the buffer since the
108 last "clear ring buffer" command (see command 5 below)).
109 The call returns the number of bytes read.
111 .BR SYSLOG_ACTION_READ_CLEAR " (4)"
112 Read and clear all messages remaining in the ring buffer.
113 The call does precisely the same as for a
115 of 3, but also executes the "clear ring buffer" command.
117 .BR SYSLOG_ACTION_CLEAR " (5)"
118 The call executes just the "clear ring buffer" command.
123 arguments are ignored.
125 This command does not really clear the ring buffer.
126 Rather, it sets a kernel bookkeeping variable that
127 determines the results returned by commands 3
128 .RB ( SYSLOG_ACTION_READ_ALL )
130 .RB ( SYSLOG_ACTION_READ_CLEAR ).
131 This command has no effect on commands 2
132 .RB ( SYSLOG_ACTION_READ )
134 .RB ( SYSLOG_ACTION_SIZE_UNREAD ).
136 .BR SYSLOG_ACTION_CONSOLE_OFF " (6)"
137 Disable printk to console.
138 The call sets the console log level to the minimum,
139 so that no messages are printed to the console.
144 arguments are ignored.
146 .BR SYSLOG_ACTION_CONSOLE_ON " (7)"
147 The call sets the console log level to the default,
148 so that messages are printed to the console.
153 arguments are ignored.
155 .BR SYSLOG_ACTION_CONSOLE_LEVEL " (8)"
156 The call sets the console log level to the value given in
158 which must be an integer between 1 and 8 (inclusive).
166 .BR SYSLOG_ACTION_SIZE_UNREAD " (9) (since Linux 2.4.10)"
168 returns the number of bytes currently available to be read
169 from the kernel log buffer via command 2
170 .RB ( SYSLOG_ACTION_READ ).
175 arguments are ignored.
177 .BR SYSLOG_ACTION_SIZE_BUFFER " (10) (since Linux 2.6.6)"
178 This command returns the total size of the kernel log buffer.
183 arguments are ignored.
185 All commands except 3 and 10 require privilege.
186 In Linux kernels before 2.6.37,
187 command types 3 and 10 are allowed to unprivileged processes;
189 these commands are allowed to unprivileged processes only if
190 .IR /proc/sys/kernel/dmesg_restrict
192 Before Linux 2.6.37, "privileged" means that the caller has the
196 "privileged" means that the caller has either the
198 capability (now deprecated for this purpose) or the (new)
204 will only print a message on the
205 console, if it has a loglevel less than the value of the variable
206 .IR console_loglevel .
207 This variable initially has the value
208 .B DEFAULT_CONSOLE_LOGLEVEL
209 (7), but is set to 10 if the
210 kernel command line contains the word "debug", and to 15 in case
211 of a kernel fault (the 10 and 15 are just silly, and equivalent to 8).
212 This variable is set (to a value in the range 1-8) by a
221 equal to 6 or 7 set the variable to 1 (kernel panics only)
222 or 7 (all except debugging messages), respectively.
224 Every text line in a message has its own loglevel.
226 .I "DEFAULT_MESSAGE_LOGLEVEL \- 1"
227 (6) unless the line starts with <d>
228 where \fId\fP is a digit in the range 1-7, in which case the level
230 The conventional meaning of the loglevel is defined in
235 #define KERN_EMERG "<0>" /* system is unusable */
236 #define KERN_ALERT "<1>" /* action must be taken immediately */
237 #define KERN_CRIT "<2>" /* critical conditions */
238 #define KERN_ERR "<3>" /* error conditions */
239 #define KERN_WARNING "<4>" /* warning conditions */
240 #define KERN_NOTICE "<5>" /* normal but significant condition */
241 #define KERN_INFO "<6>" /* informational */
242 #define KERN_DEBUG "<7>" /* debug-level messages */
245 For \fItype\fP equal to 2, 3, or 4, a successful call to
251 returns the number of bytes currently
252 available to be read on the kernel log buffer.
255 returns the total size of the kernel log buffer.
256 For other values of \fItype\fP, 0 is returned on success.
258 In case of error, \-1 is returned,
259 and \fIerrno\fP is set to indicate the error.
273 is less than zero; or for
277 is outside the range 1 to 8).
282 system call is not available, because the kernel was compiled with the
284 kernel-configuration option disabled.
287 An attempt was made to change console_loglevel or clear the kernel
288 message ring buffer by a process without sufficient privilege
289 (more precisely: without the
296 System call was interrupted by a signal; nothing was read.
297 (This can be seen only during a trace.)
299 This system call is Linux-specific and should not be used in programs
300 intended to be portable.
302 From the very start people noted that it is unfortunate that
303 a system call and a library routine of the same name are entirely
305 .\" In libc4 and libc5 the number of this call was defined by
307 .\" In glibc 2.0 the syscall is baptized
313 This page is part of release 3.67 of the Linux
316 A description of the project,
317 information about reporting bugs,
318 and the latest version of this page,
320 \%http://www.kernel.org/doc/man\-pages/.