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 2001-11-25 "Linux 1.2.9" "Linux Programmer's Manual"
26 syslog, klogctl \- read and/or clear kernel message ring buffer; set console_loglevel
29 /* The glibc interface */
31 .B "#include <sys/klog.h>"
33 .BI "int klogctl(int " type ", char *" bufp ", int " len );
35 /* The handcrafted system call */
37 .B #include <unistd.h>
39 .B #include <linux/unistd.h>
41 .B _syscall3(int, syslog, int, type, char *, bufp, int, len)
43 .BI "int syslog(int " type ", char *" bufp ", int " len );
46 If you need the libc function
52 The system call of this name is about controlling the kernel
54 buffer, and the glibc version is called
57 The \fItype\fP argument determines the action taken by this function.
63 * Commands to sys_syslog:
65 * 0 -- Close the log. Currently a NOP.
66 * 1 -- Open the log. Currently a NOP.
67 * 2 -- Read from the log.
68 * 3 -- Read up to the last 4k of messages in the ring buffer.
69 * 4 -- Read and clear last 4k of messages in the ring buffer
70 * 5 -- Clear ring buffer.
71 * 6 -- Disable printk's to console
72 * 7 -- Enable printk's to console
73 * 8 -- Set level of messages printed to console
74 * 9 -- Return number of unread characters in the log buffer
78 Only function 3 is allowed to non-root processes.
79 (Function 9 was added in 2.4.10.)
81 .B The kernel log buffer
83 The kernel has a cyclic buffer of length LOG_BUF_LEN
84 (4096, since 1.3.54: 8192, since 2.1.113: 16384; in recent kernels
85 the size can be set at compile time) in which messages given as argument
86 to the kernel function \fIprintk\fP() are stored
87 (regardless of their loglevel).
92 waits until this kernel log buffer is nonempty, and then reads
93 at most \fIlen\fP bytes into the buffer \fIbuf\fP. It returns
94 the number of bytes read. Bytes read from the log disappear from
95 the log buffer: the information can only be read once.
96 This is the function executed by the kernel when a user program
103 will read the last \fIlen\fP bytes from the log buffer (nondestructively),
104 but will not read more than was written into the buffer since the
105 last `clear ring buffer' command (which does not clear the buffer at all).
106 It returns the number of bytes read.
111 does precisely the same, but also executes the `clear ring buffer' command.
115 .RI (5, dummy , idummy )
116 only executes the `clear ring buffer' command.
120 The kernel routine \fIprintk\fP() will only print a message on the
121 console, if it has a loglevel less than the value of the variable
123 (initially DEFAULT_CONSOLE_LOGLEVEL (7), but set to 10 if the
124 kernel commandline contains the word `debug', and to 15 in case
125 of a kernel fault - the 10 and 15 are just silly, and equivalent to 8).
126 This variable is set (to a value in the range 1-8) by the call
128 .RI (8, dummy , value ).
131 .RI ( type , dummy , idummy )
132 with \fItype\fP equal to 6 or 7, set it to 1 (kernel panics only)
133 or 7 (all except debugging messages), respectively.
135 Every text line in a message has its own loglevel. This level is
136 DEFAULT_MESSAGE_LOGLEVEL - 1 (6) unless the line starts with <d>
137 where \fId\fP is a digit in the range 1-7, in which case the level
138 is \fId\fP. The conventional meaning of the loglevel is defined in
143 #define KERN_EMERG "<0>" /* system is unusable */
144 #define KERN_ALERT "<1>" /* action must be taken immediately */
145 #define KERN_CRIT "<2>" /* critical conditions */
146 #define KERN_ERR "<3>" /* error conditions */
147 #define KERN_WARNING "<4>" /* warning conditions */
148 #define KERN_NOTICE "<5>" /* normal but significant condition */
149 #define KERN_INFO "<6>" /* informational */
150 #define KERN_DEBUG "<7>" /* debug-level messages */
154 In case of error, \-1 is returned, and \fIerrno\fP is set. Otherwise,
155 for \fItype\fP equal to 2, 3 or 4, \fBsyslog\fP() returns the number
156 of bytes read, and otherwise 0.
163 An attempt was made to change console_loglevel or clear the kernel
164 message ring buffer by a process without root permissions.
167 System call was interrupted by a signal - nothing was read.
168 (This can be seen only during a trace.)
170 This system call is Linux specific and should not be used in programs
171 intended to be portable.
173 From the very start people noted that it is unfortunate that
174 kernel call and library routine of the same name are entirely
176 In libc4 and libc5 the number of this call was defined by
178 In glibc 2.0 the syscall is baptised