1 .\" Copyright (C) 1995 Andries Brouwer (aeb@cwi.nl)
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein. The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" Written 11 June 1995 by Andries Brouwer <aeb@cwi.nl>
24 .\" 2008-02-15, Jeremy Kerr <jk@ozlabs.org>
25 .\" Add info on command type 10; add details on types 6, 7, 8, & 9.
26 .\" 2008-02-15, Michael Kerrisk <mtk.manpages@gmail.com>
27 .\" Update LOG_BUF_LEN details; update RETURN VALUE section.
29 .TH SYSLOG 2 2008-06-20 "Linux" "Linux Programmer's Manual"
31 syslog, klogctl \- read and/or clear kernel message ring buffer;
35 .BI "int syslog(int " type ", char *" bufp ", int " len );
36 .B " /* No wrapper provided in glibc */"
38 /* The glibc interface */
40 .B "#include <sys/klog.h>"
42 .BI "int klogctl(int " type ", char *" bufp ", int " len );
45 If you need the C library function
51 The system call of this name is about controlling the kernel
53 buffer, and the glibc version is called
56 The \fItype\fP argument determines the action taken by this function.
62 * Commands to sys_syslog:
64 * 0 \-\- Close the log. Currently a NOP.
65 * 1 \-\- Open the log. Currently a NOP.
66 * 2 \-\- Read from the log.
67 * 3 \-\- Read all messages remaining in the ring buffer.
68 * 4 \-\- Read and clear all messages remaining in the ring buffer
69 * 5 \-\- Clear ring buffer.
70 * 6 \-\- Disable printk to console
71 * 7 \-\- Enable printk to console
72 * 8 \-\- Set level of messages printed to console
73 * 9 \-\- Return number of unread characters in the log buffer
74 * 10 \-\- Return size of the log buffer
78 Only command types 3 and 10 are allowed to unprivileged processes.
79 Type 9 was added in 2.4.10; type 10 in 2.6.6.
80 .SS The kernel log buffer
81 The kernel has a cyclic buffer of length
83 in which messages given as arguments to the kernel function
85 are stored (regardless of their loglevel).
89 from kernel 1.3.54, it was 8192;
90 from kernel 2.1.113 it was 16384;
91 since 2.4.23/2.6 the value is a kernel configuration option.
92 .\" Under "General setup" ==> "Kernel log buffer size"
93 .\" For 2.6, precisely the option seems to have appeared in 2.5.55.
94 In recent kernels the size can be queried with command type 10.
97 .I "syslog(2,buf,len)"
98 waits until this kernel log buffer is nonempty, and then reads
99 at most \fIlen\fP bytes into the buffer \fIbuf\fP.
101 the number of bytes read.
102 Bytes read from the log disappear from
103 the log buffer: the information can only be read once.
104 This is the function executed by the kernel when a user program
110 will read the last \fIlen\fP bytes from the log buffer (nondestructively),
111 but will not read more than was written into the buffer since the
112 last "clear ring buffer" command (which does not clear the buffer at all).
113 It returns the number of bytes read.
117 does precisely the same, but also executes the "clear ring buffer" command.
120 .I syslog(5,dummy,dummy)
121 executes just the "clear ring buffer" command.
126 is shown as "dummy", the value of the argument is ignored by the call.)
129 .I syslog(6,dummy,dummy)
130 sets the console log level to minimum, so that no messages are printed
134 .I syslog(7,dummy,dummy)
135 sets the console log level to default, so that messages are printed
139 .I syslog(8,dummy,level)
140 sets the console log level to
142 which must be an integer between 1 and 8 (inclusive).
148 .I syslog(9,dummy,dummy)
149 returns the number of bytes currently available to be read
150 on the kernel log buffer.
153 .I syslog(10,dummy,dummy)
154 returns the total size of the kernel log buffer.
158 will only print a message on the
159 console, if it has a loglevel less than the value of the variable
160 .IR console_loglevel .
161 This variable initially has the value
162 .B DEFAULT_CONSOLE_LOGLEVEL
163 (7), but is set to 10 if the
164 kernel command line contains the word "debug", and to 15 in case
165 of a kernel fault (the 10 and 15 are just silly, and equivalent to 8).
166 This variable is set (to a value in the range 1-8) by the call
167 .IR syslog(8,dummy,value) .
169 .I syslog(type,dummy,dummy)
170 with \fItype\fP equal to 6 or 7, set it to 1 (kernel panics only)
171 or 7 (all except debugging messages), respectively.
173 Every text line in a message has its own loglevel.
175 .I "DEFAULT_MESSAGE_LOGLEVEL \- 1"
176 (6) unless the line starts with <d>
177 where \fId\fP is a digit in the range 1-7, in which case the level
179 The conventional meaning of the loglevel is defined in
184 #define KERN_EMERG "<0>" /* system is unusable */
185 #define KERN_ALERT "<1>" /* action must be taken immediately */
186 #define KERN_CRIT "<2>" /* critical conditions */
187 #define KERN_ERR "<3>" /* error conditions */
188 #define KERN_WARNING "<4>" /* warning conditions */
189 #define KERN_NOTICE "<5>" /* normal but significant condition */
190 #define KERN_INFO "<6>" /* informational */
191 #define KERN_DEBUG "<7>" /* debug-level messages */
194 For \fItype\fP equal to 2, 3, or 4, a successful call to
200 returns the number of bytes currently
201 available to be read on the kernel log buffer.
204 returns the total size of the kernel log buffer.
205 For other values of \fItype\fP, 0 is returned on success.
207 In case of error, \-1 is returned,
208 and \fIerrno\fP is set to indicate the error.
222 is less than zero; or for
226 is outside the range 1 to 8).
231 system call is not available, because the kernel was compiled with the
233 kernel-configuration option disabled.
236 An attempt was made to change console_loglevel or clear the kernel
237 message ring buffer by a process without sufficient privilege
238 (more precisely: without the
243 System call was interrupted by a signal; nothing was read.
244 (This can be seen only during a trace.)
246 This system call is Linux-specific and should not be used in programs
247 intended to be portable.
249 From the very start people noted that it is unfortunate that
250 a system call and a library routine of the same name are entirely
252 In libc4 and libc5 the number of this call was defined by
254 In glibc 2.0 the syscall is baptized