2 .\" Copyright 1989 AT&T Copyright (c) 1997, Sun Microsystems, Inc. All Rights Reserved
3 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
4 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
5 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
6 .TH LOG 7D "Mar 11, 1998"
8 log \- interface to STREAMS error logging and event tracing
12 \fB#include <sys/strlog.h>\fR
17 \fB#include <sys/log.h>\fR
23 \fBlog\fR is a STREAMS software device driver that provides an interface for
24 console logging and for the STREAMS error logging and event tracing processes
25 (see \fBstrerr\fR(8), and \fBstrace\fR(8)). \fBlog\fR presents two separate
26 interfaces: a function call interface in the kernel through which STREAMS
27 drivers and modules submit \fBlog\fR messages; and a set of \fBioctl\fR(2)
28 requests and STREAMS messages for interaction with a user level console logger,
29 an error logger, a trace logger, or processes that need to submit their own
31 .SS "Kernel Interface"
34 \fBlog\fR messages are generated within the kernel by calls to the function
39 strlog(short \fImid\fR,
44 unsigned \fIarg1\fR\fB\|.\|.\|.\|
51 Required definitions are contained in \fB<sys/strlog.h>\fR, \fB<sys/log.h>\fR,
52 and \fB<sys/syslog.h>\fR\&. \fImid\fR is the STREAMS module id number for the
53 module or driver submitting the \fBlog\fR message. \fIsid\fR is an internal
54 sub-id number usually used to identify a particular minor device of a driver.
55 \fIlevel\fR is a tracing level that allows for selective screening out of low
56 priority messages from the tracer. \fIflags\fR are any combination of
57 \fBSL_ERROR\fR (the message is for the error logger), \fBSL_TRACE\fR (the
58 message is for the tracer), \fBSL_CONSOLE\fR (the message is for the console
59 logger), \fBSL_FATAL\fR (advisory notification of a fatal error), and
60 \fBSL_NOTIFY\fR (request that a copy of the message be mailed to the system
61 administrator). \fIfmt\fR is a \fBprintf\fR(3C) style format string, except
62 that \fB%s\fR, \fB%e\fR, \fB%E\fR, \fB%g\fR, and \fB%G\fR conversion
63 specifications are not handled. Up to \fBNLOGARGS\fR (in this release, three)
64 numeric or character arguments can be provided.
68 \fBlog\fR is implemented as a cloneable device, it clones itself without
69 intervention from the system clone device. Each open of \fB/dev/log\fR obtains
70 a separate stream to \fBlog\fR. In order to receive \fBlog\fR messages, a
71 process must first notify \fBlog\fR whether it is an error logger, trace
72 logger, or console logger using a STREAMS \fBI_STR ioctl\fR call (see below).
73 For the console logger, the \fBI_STR ioctl\fR has an \fBic_cmd\fR field of
74 \fBI_CONSLOG\fR, with no accompanying data. For the error logger, the \fBI_STR
75 ioctl\fR has an \fBic_cmd\fR field of \fBI_ERRLOG\fR, with no accompanying
76 data. For the trace logger, the \fBioctl\fR has an \fBic_cmd\fR field of
77 \fBI_TRCLOG\fR, and must be accompanied by a data buffer containing an array of
78 one or more struct \fBtrace_ids\fR elements.
92 Each \fBtrace_ids\fR structure specifies a \fImid\fR, \fIsid\fR, and
93 \fIlevel\fR from which messages will be accepted. \fBstrlog\fR(9F) will accept
94 messages whose \fImid\fR and \fIsid\fR exactly match those in the
95 \fBtrace_ids\fR structure, and whose level is less than or equal to the level
96 given in the \fBtrace_ids\fR structure. A value of \(mi1 in any of the fields
97 of the \fBtrace_ids\fR structure indicates that any value is accepted for that
101 Once the logger process has identified itself using the \fBioctl\fR call,
102 \fBlog\fR will begin sending up messages subject to the restrictions noted
103 above. These messages are obtained using the \fBgetmsg\fR(2) function. The
104 control part of this message contains a \fBlog_ctl\fR structure, which
105 specifies the \fImid\fR, \fIsid\fR, \fIlevel\fR, \fIflags\fR, time in ticks
106 since boot that the message was submitted, the corresponding time in seconds
107 since Jan. 1, 1970, a sequence number, and a priority. The time in seconds
108 since 1970 is provided so that the date and time of the message can be easily
109 computed, and the time in ticks since boot is provided so that the relative
110 timing of \fBlog\fR messages can be determined.
117 char level; /* level of message for tracing */
118 short flags; /* message disposition */
119 #if defined(_LP64) || defined(_I32LPx)
120 clock32_t ltime; /* time in machine ticks since boot */
121 time32_t ttime; /* time in seconds since 1970 */
126 int seq_no; /* sequence number */
127 int pri; /* priority = (facility|level) */
134 The priority consists of a priority code and a facility code, found in
135 \fB<sys/syslog.h>\fR\&. If \fBSL_CONSOLE\fR is set in \fIflags\fR, the priority
136 code is set as follows: If \fBSL_WARN\fR is set, the priority code is set to
137 \fBLOG_WARNING\fR; If \fBSL_FATAL\fR is set, the priority code is set to
138 \fBLOG_CRIT\fR; If \fBSL_ERROR\fR is set, the priority code is set to
139 \fBLOG_ERR\fR; If \fBSL_NOTE\fR is set, the priority code is set to
140 \fBLOG_NOTICE\fR; If \fBSL_TRACE\fR is set, the priority code is set to
141 \fBLOG_DEBUG\fR; If only \fBSL_CONSOLE\fR is set, the priority code is set to
142 \fBLOG_INFO\fR. Messages originating from the kernel have the facility code set
143 to \fBLOG_KERN\fR. Most messages originating from user processes will have the
144 facility code set to \fBLOG_USER\fR.
147 Different sequence numbers are maintained for the error and trace logging
148 streams, and are provided so that gaps in the sequence of messages can be
149 determined (during times of high message traffic some messages may not be
150 delivered by the logger to avoid hogging system resources). The data part of
151 the message contains the unexpanded text of the format string (null
152 terminated), followed by \fBNLOGARGS\fR words for the arguments to the format
153 string, aligned on the first word boundary following the format string.
156 A process may also send a message of the same structure to \fBlog\fR, even if
157 it is not an error or trace logger. The only fields of the \fBlog_ctl\fR
158 structure in the control part of the message that are accepted are the
159 \fIlevel\fR, \fIflags\fR, and \fIpri\fR fields; all other fields are filled in
160 by \fBlog\fR before being forwarded to the appropriate logger. The data portion
161 must contain a null terminated format string, and any arguments (up to
162 \fBNLOGARGS\fR) must be packed, 32-bits each, on the next 32-bit boundary
163 following the end of the format string.
166 \fBENXIO\fR is returned for \fBI_TRCLOG\fR ioctls without any \fBtrace_ids\fR
167 structures, or for any unrecognized \fBioctl\fR calls. The driver silently
168 ignores incorrectly formatted \fBlog\fR messages sent to the driver by a user
169 process (no error results).
172 Processes that wish to write a message to the console logger may direct their
173 output to \fB/dev/conslog\fR, using either \fBwrite\fR(2) or \fBputmsg\fR(2).
174 .SS "Driver Configuration"
177 The following driver configuration properties may be defined in the
185 If \fBmsgid=1\fR, each message will be preceded by a message ID as described in
195 If \fBmsgid=0\fR, message IDs will not be generated. This property is unstable
196 and may be removed in a future release.
201 \fBExample 1 \fR\fBI_ERRLOG\fR registration.
206 ioc.ic_cmd = I_ERRLOG;
207 ioc.ic_timout = 0; /* default timeout (15 secs.) */
210 ioctl(log, I_STR, &ioc);
215 \fBExample 2 \fR\fBI_TRCLOG\fR registration.
219 struct trace_ids tid[2];
223 tid[1].ti_mid = 1002;
224 tid[1].ti_sid = \(mi1; /* any sub-id will be allowed */
225 tid[1].ti_level = \(mi1; /* any level will be allowed */
226 ioc.ic_cmd = I_TRCLOG;
228 ioc.ic_len = 2 * sizeof(struct trace_ids);
229 ioc.ic_dp = (char *)tid;
230 ioctl(log, I_STR, &ioc);
236 Example of submitting a \fBlog\fR message (no arguments):
241 struct strbuf ctl, dat;
243 char *message = "Don't forget to pick up some milk
245 ctl.len = ctl.maxlen = sizeof(lc);
246 ctl.buf = (char *)&lc;
247 dat.len = dat.maxlen = strlen(message);
250 lc.flags = SL_ERROR|SL_NOTIFY;
251 putmsg(log, &ctl, &dat, 0);
268 \fB\fB/dev/conslog\fR\fR
271 Write only instance of the log driver, for console logging.
277 \fB\fB/kernel/drv/log.conf\fR\fR
280 Log configuration file.
286 \fBstrace\fR(8), \fBstrerr\fR(8), \fBIntro\fR(3), \fBgetmsg\fR(2),
287 \fBioctl\fR(2), \fBputmsg\fR(2), \fBwrite\fR(2), \fBprintf\fR(3C),
291 \fISTREAMS Programming Guide\fR