1 .\"
2 .\" The contents of this file are subject to the terms of the
3 .\" Common Development and Distribution License (the "License").
4 .\" You may not use this file except in compliance with the License.
5 .\"
6 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
7 .\" or http://www.opensolaris.org/os/licensing.
8 .\" See the License for the specific language governing permissions
9 .\" and limitations under the License.
10 .\"
11 .\" When distributing Covered Code, include this CDDL HEADER in each
12 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
13 .\" If applicable, add the following below this CDDL HEADER, with the
14 .\" fields enclosed by brackets "[]" replaced with your own identifying
15 .\" information: Portions Copyright [yyyy] [name of copyright owner]
16 .\"
17 .\"
18 .\" Copyright 1989 AT&T
19 .\" Copyright (c) 1997, Sun Microsystems, Inc. All Rights Reserved
20 .\" Copyright 2018 Nexenta Systems, Inc.
21 .\"
22 .Dd January 20, 2018
23 .Dt LOG 7D
24 .Os
25 .Sh NAME
26 .Nm log
27 .Nd interface to STREAMS error logging and event tracing
28 .Sh SYNOPSIS
29 .In sys/strlog.h
30 .In sys/log.h
31 .Sh DESCRIPTION
32 .Nm
33 is a STREAMS software device driver that provides an interface for console
34 logging and for the STREAMS error logging and event tracing processes
35 .Po see
36 .Xr strerr 1M ,
37 and
38 .Xr strace 1M
39 .Pc .
40 .Nm
41 presents two separate interfaces: a function call interface in the kernel
42 through which STREAMS drivers and modules submit log messages; and a set of
43 .Xr ioctl 2
44 requests and STREAMS messages for interaction with a user level console logger,
45 an error logger, a trace logger, or processes that need to submit their own
46 log messages.
47 .Ss Kernel Interface
48 Log messages are generated within the kernel by calls to the function
49 .Xr strlog 9F .
50 .Ss User Interface
51 .Nm
52 is implemented as a cloneable device, it clones itself without intervention from
53 the system clone device.
54 Each open of
55 .Pa /dev/log
56 obtains a separate stream to
57 .Nm .
58 In order to receive log messages, a process must first notify
59 .Nm
60 whether it is an error logger, trace logger, or console logger using a STREAMS
61 .Dv I_STR
62 .Xr ioctl 2
63 call (see below).
64 For the console logger, the
65 .Dv I_STR
66 .Xr ioctl 2
67 has an
68 .Va ic_cmd
69 field of
70 .Dv I_CONSLOG ,
71 with no accompanying data.
72 For the error logger, the
73 .Dv I_STR
74 .Xr ioctl 2
75 has an
76 .Va ic_cmd
77 field of
78 .Dv I_ERRLOG ,
79 with no accompanying data.
80 For the trace logger, the
81 .Xr ioctl 2
82 has an
83 .Va ic_cmd
84 field of
85 .Dv I_TRCLOG ,
86 and must be accompanied by a data buffer containing an array of one or more
87 struct
88 .Vt trace_ids
89 elements.
90 .Bd -literal -offset indent
91 struct trace_ids {
92 short ti_mid;
93 short ti_sid;
94 char ti_level;
95 };
96 .Ed
97 .Pp
98 Each
99 .Va trace_ids
100 structure specifies a
101 .Va mid ,
102 .Va sid ,
103 and
104 .Va level
105 from which messages will be accepted.
106 .Xr strlog 9F
107 will accept messages whose
108 .Fa mid
109 and
110 .Fa sid
111 exactly match those in the
112 .Va trace_ids
113 structure, and whose level is less than or equal to the level given in the
114 .Va trace_ids
115 structure.
116 A value of -1 in any of the fields of the
117 .Va trace_ids
118 structure indicates that any value is accepted for that field.
119 .Pp
120 Once the logger process has identified itself using the
121 .Xr ioctl 2
122 call,
123 .Nm
124 will begin sending up messages subject to the restrictions noted above.
125 These messages are obtained using the
126 .Xr getmsg 2
127 function.
128 The control part of this message contains a
129 .Va log_ctl
130 structure, which specifies the
131 .Va mid ,
132 .Va sid ,
133 .Va level ,
134 .Va flags ,
135 time in ticks since boot that the message was submitted, the corresponding time
136 in seconds since Jan. 1, 1970, a sequence number, and a priority.
137 The time in seconds since 1970 is provided so that the date and time of the
138 message can be easily computed, and the time in ticks since boot is provided so
139 that the relative timing of log messages can be determined.
140 .Bd -literal -offset indent
141 struct log_ctl {
142 short mid;
143 short sid;
144 char level; /* level of message for tracing */
145 short flags; /* message disposition */
146 #if defined(_LP64) || defined(_I32LPx)
147 clock32_t ltime; /* time in machine ticks since boot */
148 time32_t ttime; /* time in seconds since 1970 */
149 #else
150 clock_t ltime;
151 time_t ttime;
152 #endif
153 int seq_no; /* sequence number */
154 int pri; /* priority = (facility|level) */
155 };
156 .Ed
157 .Pp
158 The priority consists of a priority code and a facility code, found in
159 .In sys/syslog.h .
160 If
161 .Dv SL_CONSOLE
162 is set in
163 .Va flags ,
164 the priority code is set as follows:
165 .Pp
166 .Bl -bullet -compact
167 .It
168 If
169 .Dv SL_WARN
170 is set, the priority code is set to
171 .Dv LOG_WARNING
172 .It
173 If
174 .Dv SL_FATAL
175 is set, the priority code is set to
176 .Dv LOG_CRIT
177 .It
178 If
179 .Dv SL_ERROR
180 is set, the priority code is set to
181 .Dv LOG_ERR
182 .It
183 If
184 .Dv SL_NOTE
185 is set, the priority code is set to
186 .Dv LOG_NOTICE
187 .It
188 If
189 .Dv SL_TRACE
190 is set, the priority code is set to
191 .Dv LOG_DEBUG
192 .It
193 If only
194 .Dv SL_CONSOLE
195 is set, the priority code is set to
196 .Dv LOG_INFO
197 .El
198 .Pp
199 Messages originating from the kernel have the facility code set to
200 .Dv LOG_KERN .
201 Most messages originating from user processes will have the facility code set to
202 .Dv LOG_USER .
203 .Pp
204 Different sequence numbers are maintained for the error and trace logging
205 streams, and are provided so that gaps in the sequence of messages can be
206 determined (during times of high message traffic some messages may not be
207 delivered by the logger to avoid hogging system resources).
208 The data part of the message contains the unexpanded text of the format string
209 (null terminated), followed by
210 .Dv NLOGARGS
211 words for the arguments to the format string, aligned on the first word boundary
212 following the format string.
213 .Pp
214 A process may also send a message of the same structure to
215 .Nm ,
216 even if it is not an error or trace logger.
217 The only fields of the
218 .Va log_ctl
219 structure in the control part of the message that are accepted are the
220 .Va level ,
221 .Va flags ,
222 and
223 .Va pri
224 fields; all other fields are filled in by
225 .Nm
226 before being forwarded to the appropriate logger.
227 The data portion must contain a null terminated format string, and any arguments
228 .Po up to
229 .Dv NLOGARGS
230 .Pc
231 must be packed, 32-bits each, on the next 32-bit boundary following the end of
232 the format string.
233 .Pp
234 .Er ENXIO
235 is returned for
236 .Dv I_TRCLOG
237 .Xr ioctl 2
238 without any
239 .Va trace_ids
240 structures, or for any unrecognized
241 .Xr ioctl 2
242 calls.
243 The driver silently ignores incorrectly formatted log messages sent to the
244 driver by a user process (no error results).
245 .Pp
246 Processes that wish to write a message to the console logger may direct their
247 output to
248 .Pa /dev/conslog ,
249 using either
250 .Xr write 2
251 or
252 .Xr putmsg 2 .
253 .Ss Driver Configuration
254 The following driver configuration properties may be defined in the
255 .Pa log.conf
256 file:
257 .Bl -tag -width "msgid=1"
258 .It Cm msgid Ns = Ns Cm 1
259 Each message will be preceded by a message ID as described in
260 .Xr syslogd 1M .
261 .It Cm msgid Ns = Ns Cm 0
262 Message IDs will not be generated.
263 .El
264 .Sh FILES
265 .Bl -tag -width "/kernel/drv/log.conf"
266 .It Pa /dev/log
267 Log driver.
268 .It Pa /dev/conslog
269 Write only instance of the log driver, for console logging.
270 .It Pa /kernel/drv/log.conf
271 Log configuration file.
272 .El
273 .Sh EXAMPLES
274 .Bl -tag -width Ds
275 .It Sy Example 1 Dv I_ERRLOG No registration.
276 .Bd -literal
277 struct strioctl ioc;
278 ioc.ic_cmd = I_ERRLOG;
279 ioc.ic_timout = 0; /* default timeout (15 secs.) */
280 ioc.ic_len = 0;
281 ioc.ic_dp = NULL;
282 ioctl(log, I_STR, &ioc);
283 .Ed
284 .It Sy Example 2 Dv I_TRCLOG No registration.
285 .Bd -literal
286 struct trace_ids tid[2];
287 tid[0].ti_mid = 2;
288 tid[0].ti_sid = 0;
289 tid[0].ti_level = 1;
290 tid[1].ti_mid = 1002;
291 tid[1].ti_sid = -1; /* any sub-id will be allowed */
292 tid[1].ti_level = -1; /* any level will be allowed */
293 ioc.ic_cmd = I_TRCLOG;
294 ioc.ic_timout = 0;
295 ioc.ic_len = 2 * sizeof(struct trace_ids);
296 ioc.ic_dp = (char *)tid;
297 ioctl(log, I_STR, &ioc);
298 .Ed
299 .It Sy Example 3 No Submitting a log message (no arguments)
300 .Bd -literal
301 struct strbuf ctl, dat;
302 struct log_ctl lc;
303 char *message = "Don't forget to pick up some milk "
304 "on the way home";
305 ctl.len = ctl.maxlen = sizeof(lc);
306 ctl.buf = (char *)&lc;
307 dat.len = dat.maxlen = strlen(message);
308 dat.buf = message;
309 lc.level = 0;
310 lc.flags = SL_ERROR|SL_NOTIFY;
311 putmsg(log, &ctl, &dat, 0);
312 .Ed
313 .El
314 .Sh SEE ALSO
315 .Xr strace 1M ,
316 .Xr strerr 1M ,
317 .Xr getmsg 2 ,
318 .Xr ioctl 2 ,
319 .Xr putmsg 2 ,
320 .Xr write 2 ,
321 .Xr strlog 9F
322 .Pp
323 .Em STREAMS Programming Guide