1syslog(2)                     System Calls Manual                    syslog(2)
2
3
4

NAME

6       syslog,  klogctl  -  read  and/or clear kernel message ring buffer; set
7       console_loglevel
8

LIBRARY

10       Standard C library (libc, -lc)
11

SYNOPSIS

13       #include <sys/klog.h>        /* Definition of SYSLOG_* constants */
14       #include <sys/syscall.h>     /* Definition of SYS_* constants */
15       #include <unistd.h>
16
17       int syscall(SYS_syslog, int type, char *bufp, int len);
18
19       /* The glibc interface */
20       #include <sys/klog.h>
21
22       int klogctl(int type, char *bufp, int len);
23

DESCRIPTION

25       Note: Probably, you are looking for the C  library  function  syslog(),
26       which talks to syslogd(8); see syslog(3) for details.
27
28       This  page  describes the kernel syslog() system call, which is used to
29       control the kernel printk() buffer; the glibc wrapper function for  the
30       system call is called klogctl().
31
32   The kernel log buffer
33       The  kernel has a cyclic buffer of length LOG_BUF_LEN in which messages
34       given as arguments to the kernel function printk() are stored  (regard‐
35       less  of their log level).  In early kernels, LOG_BUF_LEN had the value
36       4096; from Linux 1.3.54, it was 8192; from Linux 2.1.113, it was 16384;
37       since  Linux  2.4.23/2.6,  the  value  is a kernel configuration option
38       (CONFIG_LOG_BUF_SHIFT, default value dependent  on  the  architecture).
39       Since  Linux  2.6.6,  the size can be queried with command type 10 (see
40       below).
41
42   Commands
43       The type argument determines the action taken by  this  function.   The
44       list  below  specifies the values for type.  The symbolic names are de‐
45       fined in the kernel source, but are not exported  to  user  space;  you
46       will either need to use the numbers, or define the names yourself.
47
48       SYSLOG_ACTION_CLOSE (0)
49              Close the log.  Currently a NOP.
50
51       SYSLOG_ACTION_OPEN (1)
52              Open the log.  Currently a NOP.
53
54       SYSLOG_ACTION_READ (2)
55              Read  from  the log.  The call waits until the kernel log buffer
56              is nonempty, and then reads at most len bytes  into  the  buffer
57              pointed  to by bufp.  The call returns the number of bytes read.
58              Bytes read from the log disappear from the log buffer:  the  in‐
59              formation  can be read only once.  This is the function executed
60              by the kernel when a user program reads /proc/kmsg.
61
62       SYSLOG_ACTION_READ_ALL (3)
63              Read all messages remaining in the ring buffer, placing them  in
64              the  buffer  pointed  to  by  bufp.  The call reads the last len
65              bytes from the log buffer (nondestructively), but will not  read
66              more than was written into the buffer since the last "clear ring
67              buffer" command (see command 5 below)).  The  call  returns  the
68              number of bytes read.
69
70       SYSLOG_ACTION_READ_CLEAR (4)
71              Read  and  clear all messages remaining in the ring buffer.  The
72              call does precisely the same as for a type of 3, but  also  exe‐
73              cutes the "clear ring buffer" command.
74
75       SYSLOG_ACTION_CLEAR (5)
76              The  call  executes  just  the "clear ring buffer" command.  The
77              bufp and len arguments are ignored.
78
79              This command does not really clear the ring buffer.  Rather,  it
80              sets  a  kernel bookkeeping variable that determines the results
81              returned by commands  3  (SYSLOG_ACTION_READ_ALL)  and  4  (SYS‐
82              LOG_ACTION_READ_CLEAR).   This command has no effect on commands
83              2 (SYSLOG_ACTION_READ) and 9 (SYSLOG_ACTION_SIZE_UNREAD).
84
85       SYSLOG_ACTION_CONSOLE_OFF (6)
86              The command saves the current value of console_loglevel and then
87              sets  console_loglevel  to  minimum_console_loglevel, so that no
88              messages are printed to the console.  Before Linux  2.6.32,  the
89              command    simply    sets   console_loglevel   to   minimum_con‐
90              sole_loglevel.  See the discussion  of  /proc/sys/kernel/printk,
91              below.
92
93              The bufp and len arguments are ignored.
94
95       SYSLOG_ACTION_CONSOLE_ON (7)
96              If  a  previous  SYSLOG_ACTION_CONSOLE_OFF command has been per‐
97              formed, this command restores console_loglevel to the value that
98              was  saved  by  that command.  Before Linux 2.6.32, this command
99              simply sets console_loglevel to  default_console_loglevel.   See
100              the discussion of /proc/sys/kernel/printk, below.
101
102              The bufp and len arguments are ignored.
103
104       SYSLOG_ACTION_CONSOLE_LEVEL (8)
105              The  call sets console_loglevel to the value given in len, which
106              must be an integer between 1  and  8  (inclusive).   The  kernel
107              silently  enforces  a  minimum value of minimum_console_loglevel
108              for len.  See the log level section for details.  The bufp argu‐
109              ment is ignored.
110
111       SYSLOG_ACTION_SIZE_UNREAD (9) (since Linux 2.4.10)
112              The  call  returns the number of bytes currently available to be
113              read from the  kernel  log  buffer  via  command  2  (SYSLOG_AC‐
114              TION_READ).  The bufp and len arguments are ignored.
115
116       SYSLOG_ACTION_SIZE_BUFFER (10) (since Linux 2.6.6)
117              This  command  returns  the total size of the kernel log buffer.
118              The bufp and len arguments are ignored.
119
120       All commands except 3 and 10 require privilege.  In Linux  kernels  be‐
121       fore  Linux  2.6.37, command types 3 and 10 are allowed to unprivileged
122       processes; since Linux 2.6.37, these commands are allowed  to  unprivi‐
123       leged  processes  only if /proc/sys/kernel/dmesg_restrict has the value
124       0.  Before Linux 2.6.37, "privileged" means that  the  caller  has  the
125       CAP_SYS_ADMIN  capability.  Since Linux 2.6.37, "privileged" means that
126       the caller has either the CAP_SYS_ADMIN capability (now deprecated  for
127       this purpose) or the (new) CAP_SYSLOG capability.
128
129   /proc/sys/kernel/printk
130       /proc/sys/kernel/printk is a writable file containing four integer val‐
131       ues that influence kernel printk() behavior when  printing  or  logging
132       error messages.  The four values are:
133
134       console_loglevel
135              Only  messages  with  a  log level lower than this value will be
136              printed to the console.  The default value for this field is DE‐
137              FAULT_CONSOLE_LOGLEVEL  (7),  but  it  is set to 4 if the kernel
138              command line contains the word "quiet", 10 if the kernel command
139              line  contains  the  word "debug", and to 15 in case of a kernel
140              fault (the 10 and 15 are just silly, and equivalent to 8).   The
141              value  of  console_loglevel  can be set (to a value in the range
142              1–8) by a syslog() call with a type of 8.
143
144       default_message_loglevel
145              This value will be used as the log level for  printk()  messages
146              that  do  not have an explicit level.  Up to and including Linux
147              2.6.38, the hard-coded  default  value  for  this  field  was  4
148              (KERN_WARNING); since Linux 2.6.39, the default value is defined
149              by   the   kernel   configuration   option   CONFIG_DEFAULT_MES‐
150              SAGE_LOGLEVEL, which defaults to 4.
151
152       minimum_console_loglevel
153              The  value  in  this  field  is  the minimum value to which con‐
154              sole_loglevel can be set.
155
156       default_console_loglevel
157              This is the default value for console_loglevel.
158
159   The log level
160       Every printk() message has its own log level.  If the log level is  not
161       explicitly  specified  as  part  of  the  message,  it  defaults to de‐
162       fault_message_loglevel.  The conventional meaning of the log  level  is
163       as follows:
164
165       Kernel constant   Level value   Meaning
166       KERN_EMERG             0        System is unusable
167       KERN_ALERT             1        Action must be taken
168                                       immediately
169       KERN_CRIT              2        Critical conditions
170       KERN_ERR               3        Error conditions
171       KERN_WARNING           4        Warning conditions
172       KERN_NOTICE            5        Normal but  signifi‐
173                                       cant condition
174       KERN_INFO              6        Informational
175       KERN_DEBUG             7        Debug-level messages
176
177       The kernel printk() routine will print a message on the console only if
178       it has a log level less than the value of console_loglevel.
179

RETURN VALUE

181       For type equal to 2, 3, or 4, a successful call to syslog() returns the
182       number of bytes read.  For type 9, syslog() returns the number of bytes
183       currently available to be read on the kernel log buffer.  For type  10,
184       syslog()  returns  the  total size of the kernel log buffer.  For other
185       values of type, 0 is returned on success.
186
187       In case of error, -1 is returned, and errno is set to indicate the  er‐
188       ror.
189

ERRORS

191       EINVAL Bad  arguments  (e.g.,  bad type; or for type 2, 3, or 4, buf is
192              NULL, or len is less than zero; or for type 8, the level is out‐
193              side the range 1 to 8).
194
195       ENOSYS This  syslog()  system call is not available, because the kernel
196              was compiled with the CONFIG_PRINTK kernel-configuration  option
197              disabled.
198
199       EPERM  An attempt was made to change console_loglevel or clear the ker‐
200              nel message ring buffer by a process without  sufficient  privi‐
201              lege  (more  precisely:  without the CAP_SYS_ADMIN or CAP_SYSLOG
202              capability).
203
204       ERESTARTSYS
205              System call was interrupted  by  a  signal;  nothing  was  read.
206              (This can be seen only during a trace.)
207

STANDARDS

209       Linux.
210

HISTORY

212       From  the very start, people noted that it is unfortunate that a system
213       call and a library routine of the same name are entirely different ani‐
214       mals.
215

SEE ALSO

217       dmesg(1), syslog(3), capabilities(7)
218
219
220
221Linux man-pages 6.04              2023-03-30                         syslog(2)
Impressum