'\" te .\" Copyright 1989 AT&T Copyright (c) 1997, Sun Microsystems, Inc. All Rights Reserved .\" 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. .\" 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. .\" 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] .TH log 7D "11 Mar 1998" "SunOS 5.11" "Devices" .SH NAME log \- interface to STREAMS error logging and event tracing .SH SYNOPSIS .LP .nf \fB#include \fR .fi .LP .nf \fB#include \fR .fi .SH DESCRIPTION .sp .LP \fBlog\fR is a STREAMS software device driver that provides an interface for console logging and for the STREAMS error logging and event tracing processes (see \fBstrerr\fR(1M), and \fBstrace\fR(1M)). \fBlog\fR presents two separate interfaces: a function call interface in the kernel through which STREAMS drivers and modules submit \fBlog\fR messages; and a set of \fBioctl\fR(2) requests and STREAMS messages for interaction with a user level console logger, an error logger, a trace logger, or processes that need to submit their own \fBlog\fR messages. .SS "Kernel Interface" .sp .LP \fBlog\fR messages are generated within the kernel by calls to the function \fBstrlog()\fR: .sp .in +2 .nf strlog(short \fImid\fR, short \fIsid\fR, char \fIlevel\fR, ushort_t \fIflags\fR, char *\fBfmt\fR, unsigned \fIarg1\fR\fB\|.\|.\|.\| );\fR .fi .in -2 .sp .LP Required definitions are contained in \fB\fR, \fB\fR, and \fB\fR\&. \fImid\fR is the STREAMS module id number for the module or driver submitting the \fBlog\fR message. \fIsid\fR is an internal sub-id number usually used to identify a particular minor device of a driver. \fIlevel\fR is a tracing level that allows for selective screening out of low priority messages from the tracer. \fIflags\fR are any combination of \fBSL_ERROR\fR (the message is for the error logger), \fBSL_TRACE\fR (the message is for the tracer), \fBSL_CONSOLE\fR (the message is for the console logger), \fBSL_FATAL\fR (advisory notification of a fatal error), and \fBSL_NOTIFY\fR (request that a copy of the message be mailed to the system administrator). \fIfmt\fR is a \fBprintf\fR(3C) style format string, except that \fB%s\fR, \fB%e\fR, \fB%E\fR, \fB%g\fR, and \fB%G\fR conversion specifications are not handled. Up to \fBNLOGARGS\fR (in this release, three) numeric or character arguments can be provided. .SS "User Interface" .sp .LP \fBlog\fR is implemented as a cloneable device, it clones itself without intervention from the system clone device. Each open of \fB/dev/log\fR obtains a separate stream to \fBlog\fR. In order to receive \fBlog\fR messages, a process must first notify \fBlog\fR whether it is an error logger, trace logger, or console logger using a STREAMS \fBI_STR ioctl\fR call (see below). For the console logger, the \fBI_STR ioctl\fR has an \fBic_cmd\fR field of \fBI_CONSLOG\fR, with no accompanying data. For the error logger, the \fBI_STR ioctl\fR has an \fBic_cmd\fR field of \fBI_ERRLOG\fR, with no accompanying data. For the trace logger, the \fBioctl\fR has an \fBic_cmd\fR field of \fBI_TRCLOG\fR, and must be accompanied by a data buffer containing an array of one or more struct \fBtrace_ids\fR elements. .sp .in +2 .nf struct trace_ids { short ti_mid; short ti_sid; char ti_level; }; .fi .in -2 .sp .LP Each \fBtrace_ids\fR structure specifies a \fImid\fR, \fIsid\fR, and \fIlevel\fR from which messages will be accepted. \fBstrlog\fR(9F) will accept messages whose \fImid\fR and \fIsid\fR exactly match those in the \fBtrace_ids\fR structure, and whose level is less than or equal to the level given in the \fBtrace_ids\fR structure. A value of \(mi1 in any of the fields of the \fBtrace_ids\fR structure indicates that any value is accepted for that field. .sp .LP Once the logger process has identified itself using the \fBioctl\fR call, \fBlog\fR will begin sending up messages subject to the restrictions noted above. These messages are obtained using the \fBgetmsg\fR(2) function. The control part of this message contains a \fBlog_ctl\fR structure, which specifies the \fImid\fR, \fIsid\fR, \fIlevel\fR, \fIflags\fR, time in ticks since boot that the message was submitted, the corresponding time in seconds since Jan. 1, 1970, a sequence number, and a priority. The time in seconds since 1970 is provided so that the date and time of the message can be easily computed, and the time in ticks since boot is provided so that the relative timing of \fBlog\fR messages can be determined. .sp .in +2 .nf struct log_ctl { short mid; short sid; char level; /* level of message for tracing */ short flags; /* message disposition */ #if defined(_LP64) || defined(_I32LPx) clock32_t ltime; /* time in machine ticks since boot */ time32_t ttime; /* time in seconds since 1970 */ #else clock_t ltime; time_t ttime; #endif int seq_no; /* sequence number */ int pri; /* priority = (facility|level) */ }; .fi .in -2 .sp .LP The priority consists of a priority code and a facility code, found in \fB\fR\&. If \fBSL_CONSOLE\fR is set in \fIflags\fR, the priority code is set as follows: If \fBSL_WARN\fR is set, the priority code is set to \fBLOG_WARNING\fR; If \fBSL_FATAL\fR is set, the priority code is set to \fBLOG_CRIT\fR; If \fBSL_ERROR\fR is set, the priority code is set to \fBLOG_ERR\fR; If \fBSL_NOTE\fR is set, the priority code is set to \fBLOG_NOTICE\fR; If \fBSL_TRACE\fR is set, the priority code is set to \fBLOG_DEBUG\fR; If only \fBSL_CONSOLE\fR is set, the priority code is set to \fBLOG_INFO\fR. Messages originating from the kernel have the facility code set to \fBLOG_KERN\fR. Most messages originating from user processes will have the facility code set to \fBLOG_USER\fR. .sp .LP Different sequence numbers are maintained for the error and trace logging streams, and are provided so that gaps in the sequence of messages can be determined (during times of high message traffic some messages may not be delivered by the logger to avoid hogging system resources). The data part of the message contains the unexpanded text of the format string (null terminated), followed by \fBNLOGARGS\fR words for the arguments to the format string, aligned on the first word boundary following the format string. .sp .LP A process may also send a message of the same structure to \fBlog\fR, even if it is not an error or trace logger. The only fields of the \fBlog_ctl\fR structure in the control part of the message that are accepted are the \fIlevel\fR, \fIflags\fR, and \fIpri\fR fields; all other fields are filled in by \fBlog\fR before being forwarded to the appropriate logger. The data portion must contain a null terminated format string, and any arguments (up to \fBNLOGARGS\fR) must be packed, 32-bits each, on the next 32-bit boundary following the end of the format string. .sp .LP \fBENXIO\fR is returned for \fBI_TRCLOG\fR ioctls without any \fBtrace_ids\fR structures, or for any unrecognized \fBioctl\fR calls. The driver silently ignores incorrectly formatted \fBlog\fR messages sent to the driver by a user process (no error results). .sp .LP Processes that wish to write a message to the console logger may direct their output to \fB/dev/conslog\fR, using either \fBwrite\fR(2) or \fBputmsg\fR(2). .SS "Driver Configuration" .sp .LP The following driver configuration properties may be defined in the \fBlog.conf\fR file. .sp .ne 2 .mk .na \fBmsgid=1\fR .ad .RS 11n .rt If \fBmsgid=1\fR, each message will be preceded by a message ID as described in \fBsyslogd\fR(1M). .RE .sp .ne 2 .mk .na \fBmsgid=0\fR .ad .RS 11n .rt If \fBmsgid=0\fR, message IDs will not be generated. This property is unstable and may be removed in a future release. .RE .SH EXAMPLES .LP \fBExample 1 \fR\fBI_ERRLOG\fR registration. .sp .in +2 .nf struct strioctl ioc; ioc.ic_cmd = I_ERRLOG; ioc.ic_timout = 0; /* default timeout (15 secs.) */ ioc.ic_len = 0; ioc.ic_dp = NULL; ioctl(log, I_STR, &ioc); .fi .in -2 .LP \fBExample 2 \fR\fBI_TRCLOG\fR registration. .sp .in +2 .nf struct trace_ids tid[2]; tid[0].ti_mid = 2; tid[0].ti_sid = 0; tid[0].ti_level = 1; tid[1].ti_mid = 1002; tid[1].ti_sid = \(mi1; /* any sub-id will be allowed */ tid[1].ti_level = \(mi1; /* any level will be allowed */ ioc.ic_cmd = I_TRCLOG; ioc.ic_timout = 0; ioc.ic_len = 2 * sizeof(struct trace_ids); ioc.ic_dp = (char *)tid; ioctl(log, I_STR, &ioc); .fi .in -2 .sp .LP Example of submitting a \fBlog\fR message (no arguments): .sp .in +2 .nf struct strbuf ctl, dat; struct log_ctl lc; char *message = "Don't forget to pick up some milk on the way home"; ctl.len = ctl.maxlen = sizeof(lc); ctl.buf = (char *)&lc; dat.len = dat.maxlen = strlen(message); dat.buf = message; lc.level = 0; lc.flags = SL_ERROR|SL_NOTIFY; putmsg(log, &ctl, &dat, 0); .fi .in -2 .SH FILES .sp .ne 2 .mk .na \fB\fB/dev/log\fR\fR .ad .RS 24n .rt Log driver. .RE .sp .ne 2 .mk .na \fB\fB/dev/conslog\fR\fR .ad .RS 24n .rt Write only instance of the log driver, for console logging. .RE .sp .ne 2 .mk .na \fB\fB/kernel/drv/log.conf\fR\fR .ad .RS 24n .rt Log configuration file. .RE .SH SEE ALSO .sp .LP \fBstrace\fR(1M), \fBstrerr\fR(1M), \fBIntro\fR(3), \fBgetmsg\fR(2), \fBioctl\fR(2), \fBputmsg\fR(2), \fBwrite\fR(2), \fBprintf\fR(3C), \fBstrlog\fR(9F) .sp .LP \fISTREAMS Programming Guide\fR