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 .TH SYSLOG 2 2007-06-01 "Linux" "Linux Programmer's Manual"
26 syslog, klogctl \- read and/or clear kernel message ring buffer;
30 .BI "int syslog(int " type ", char *" bufp ", int " len );
31 .B " /* No wrapper provided in glibc */
33 /* The glibc interface */
35 .B "#include <sys/klog.h>"
37 .BI "int klogctl(int " type ", char *" bufp ", int " len );
40 If you need the libc function
46 The system call of this name is about controlling the kernel
48 buffer, and the glibc version is called
51 The \fItype\fP argument determines the action taken by this function.
57 * Commands to sys_syslog:
59 * 0 \-\- Close the log. Currently a NOP.
60 * 1 \-\- Open the log. Currently a NOP.
61 * 2 \-\- Read from the log.
62 * 3 \-\- Read up to the last 4k of messages in the ring buffer.
63 * 4 \-\- Read and clear last 4k of messages in the ring buffer
64 * 5 \-\- Clear ring buffer.
65 * 6 \-\- Disable printk's to console
66 * 7 \-\- Enable printk's to console
67 * 8 \-\- Set level of messages printed to console
68 * 9 \-\- Return number of unread characters in the log buffer
72 Only function 3 is allowed to non-root processes.
73 (Function 9 was added in 2.4.10.)
75 .B The kernel log buffer
77 The kernel has a cyclic buffer of length LOG_BUF_LEN
78 (4096, since 1.3.54: 8192, since 2.1.113: 16384; in recent kernels
79 the size can be set at compile time) in which messages given as argument
80 to the kernel function
83 (regardless of their loglevel).
88 waits until this kernel log buffer is nonempty, and then reads
89 at most \fIlen\fP bytes into the buffer \fIbuf\fP.
91 the number of bytes read.
92 Bytes read from the log disappear from
93 the log buffer: the information can only be read once.
94 This is the function executed by the kernel when a user program
101 will read the last \fIlen\fP bytes from the log buffer (nondestructively),
102 but will not read more than was written into the buffer since the
103 last `clear ring buffer' command (which does not clear the buffer at all).
104 It returns the number of bytes read.
109 does precisely the same, but also executes the `clear ring buffer' command.
113 .RI (5, dummy , idummy )
114 only executes the `clear ring buffer' command.
120 will only print a message on the
121 console, if it has a loglevel less than the value of the variable
122 .IR console_loglevel .
123 This variable initially has the value DEFAULT_CONSOLE_LOGLEVEL (7),
124 but is set to 10 if the
125 kernel command line contains the word `debug', and to 15 in case
126 of a kernel fault (the 10 and 15 are just silly, and equivalent to 8).
127 This variable is set (to a value in the range 1-8) by the call
129 .RI (8, dummy , value ).
132 .RI ( type , dummy , idummy )
133 with \fItype\fP equal to 6 or 7, set it to 1 (kernel panics only)
134 or 7 (all except debugging messages), respectively.
136 Every text line in a message has its own loglevel.
138 DEFAULT_MESSAGE_LOGLEVEL \- 1 (6) unless the line starts with <d>
139 where \fId\fP is a digit in the range 1-7, in which case the level
141 The conventional meaning of the loglevel is defined in
146 #define KERN_EMERG "<0>" /* system is unusable */
147 #define KERN_ALERT "<1>" /* action must be taken immediately */
148 #define KERN_CRIT "<2>" /* critical conditions */
149 #define KERN_ERR "<3>" /* error conditions */
150 #define KERN_WARNING "<4>" /* warning conditions */
151 #define KERN_NOTICE "<5>" /* normal but significant condition */
152 #define KERN_INFO "<6>" /* informational */
153 #define KERN_DEBUG "<7>" /* debug-level messages */
156 In case of error, \-1 is returned, and \fIerrno\fP is set.
158 for \fItype\fP equal to 2, 3 or 4,
161 of bytes read, and otherwise 0.
168 An attempt was made to change console_loglevel or clear the kernel
169 message ring buffer by a process without root permissions.
172 System call was interrupted by a signal; nothing was read.
173 (This can be seen only during a trace.)
175 This system call is Linux specific and should not be used in programs
176 intended to be portable.
178 From the very start people noted that it is unfortunate that
179 kernel call and library routine of the same name are entirely
181 In libc4 and libc5 the number of this call was defined by
183 In glibc 2.0 the syscall is baptized