1SYSLOG(2)                  Linux Programmer's Manual                 SYSLOG(2)
2
3
4

NAME

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

SYNOPSIS

10       int syslog(int type, char *bufp, int len);
11                       /* No wrapper provided in glibc */
12
13       /* The glibc interface */
14       #include <sys/klog.h>
15
16       int klogctl(int type, char *bufp, int len);
17

DESCRIPTION

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

RETURN VALUE

173       For type equal to 2, 3, or 4, a successful call to syslog() returns the
174       number of bytes read.  For type 9, syslog() returns the number of bytes
175       currently available to be read on the kernel log buffer.  For type  10,
176       syslog()  returns  the  total size of the kernel log buffer.  For other
177       values of type, 0 is returned on success.
178
179       In case of error, -1 is returned, and errno  is  set  to  indicate  the
180       error.
181

ERRORS

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

CONFORMING TO

201       This  system  call is Linux-specific and should not be used in programs
202       intended to be portable.
203

NOTES

205       From the very start, people noted that it is unfortunate that a  system
206       call and a library routine of the same name are entirely different ani‐
207       mals.
208

SEE ALSO

210       dmesg(1), syslog(3), capabilities(7)
211

COLOPHON

213       This page is part of release 5.02 of the Linux  man-pages  project.   A
214       description  of  the project, information about reporting bugs, and the
215       latest    version    of    this    page,    can     be     found     at
216       https://www.kernel.org/doc/man-pages/.
217
218
219
220Linux                             2017-09-15                         SYSLOG(2)
Impressum