1 LOG(7D) Devices LOG(7D)
2
3 NAME
4 log - interface to STREAMS error logging and event tracing
5
6 SYNOPSIS
7 #include <sys/strlog.h>
8 #include <sys/log.h>
9
10 DESCRIPTION
11 log is a STREAMS software device driver that provides an interface for
12 console logging and for the STREAMS error logging and event tracing
13 processes (see strerr(1M), and strace(1M)). log presents two separate
14 interfaces: a function call interface in the kernel through which STREAMS
15 drivers and modules submit log messages; and a set of ioctl(2) requests
16 and STREAMS messages for interaction with a user level console logger, an
17 error logger, a trace logger, or processes that need to submit their own
18 log messages.
19
20 Kernel Interface
21 Log messages are generated within the kernel by calls to the function
22 strlog(9F).
23
24 User Interface
25 log is implemented as a cloneable device, it clones itself without
26 intervention from the system clone device. Each open of /dev/log obtains
27 a separate stream to log. In order to receive log messages, a process
28 must first notify log whether it is an error logger, trace logger, or
29 console logger using a STREAMS I_STR ioctl(2) call (see below). For the
30 console logger, the I_STR ioctl(2) has an ic_cmd field of I_CONSLOG, with
31 no accompanying data. For the error logger, the I_STR ioctl(2) has an
32 ic_cmd field of I_ERRLOG, with no accompanying data. For the trace
33 logger, the ioctl(2) has an ic_cmd field of I_TRCLOG, and must be
34 accompanied by a data buffer containing an array of one or more struct
35 trace_ids elements.
36
37 struct trace_ids {
38 short ti_mid;
39 short ti_sid;
40 char ti_level;
41 };
42
43 Each trace_ids structure specifies a mid, sid, and level from which
44 messages will be accepted. strlog(9F) will accept messages whose mid and
45 sid exactly match those in the trace_ids structure, and whose level is
46 less than or equal to the level given in the trace_ids structure. A
47 value of -1 in any of the fields of the trace_ids structure indicates
48 that any value is accepted for that field.
49
50 Once the logger process has identified itself using the ioctl(2) call,
51 log will begin sending up messages subject to the restrictions noted
52 above. These messages are obtained using the getmsg(2) function. The
53 control part of this message contains a log_ctl structure, which
54 specifies the mid, sid, level, flags, time in ticks since boot that the
55 message was submitted, the corresponding time in seconds since Jan. 1,
56 1970, a sequence number, and a priority. The time in seconds since 1970
57 is provided so that the date and time of the message can be easily
58 computed, and the time in ticks since boot is provided so that the
59 relative timing of log messages can be determined.
60
61 struct log_ctl {
62 short mid;
63 short sid;
64 char level; /* level of message for tracing */
65 short flags; /* message disposition */
66 #if defined(_LP64) || defined(_I32LPx)
67 clock32_t ltime; /* time in machine ticks since boot */
68 time32_t ttime; /* time in seconds since 1970 */
69 #else
70 clock_t ltime;
71 time_t ttime;
72 #endif
73 int seq_no; /* sequence number */
74 int pri; /* priority = (facility|level) */
75 };
76
77 The priority consists of a priority code and a facility code, found in
78 <sys/syslog.h>. If SL_CONSOLE is set in flags, the priority code is set
79 as follows:
80
81 o If SL_WARN is set, the priority code is set to LOG_WARNING
82 o If SL_FATAL is set, the priority code is set to LOG_CRIT
83 o If SL_ERROR is set, the priority code is set to LOG_ERR
84 o If SL_NOTE is set, the priority code is set to LOG_NOTICE
85 o If SL_TRACE is set, the priority code is set to LOG_DEBUG
86 o If only SL_CONSOLE is set, the priority code is set to LOG_INFO
87
88 Messages originating from the kernel have the facility code set to
89 LOG_KERN. Most messages originating from user processes will have the
90 facility code set to LOG_USER.
91
92 Different sequence numbers are maintained for the error and trace logging
93 streams, and are provided so that gaps in the sequence of messages can be
94 determined (during times of high message traffic some messages may not be
95 delivered by the logger to avoid hogging system resources). The data
96 part of the message contains the unexpanded text of the format string
97 (null terminated), followed by NLOGARGS words for the arguments to the
98 format string, aligned on the first word boundary following the format
99 string.
100
101 A process may also send a message of the same structure to log, even if
102 it is not an error or trace logger. The only fields of the log_ctl
103 structure in the control part of the message that are accepted are the
104 level, flags, and pri fields; all other fields are filled in by log
105 before being forwarded to the appropriate logger. The data portion must
106 contain a null terminated format string, and any arguments (up to
107 NLOGARGS) must be packed, 32-bits each, on the next 32-bit boundary
108 following the end of the format string.
109
110 ENXIO is returned for I_TRCLOG ioctl(2) without any trace_ids structures,
111 or for any unrecognized ioctl(2) calls. The driver silently ignores
112 incorrectly formatted log messages sent to the driver by a user process
113 (no error results).
114
115 Processes that wish to write a message to the console logger may direct
116 their output to /dev/conslog, using either write(2) or putmsg(2).
117
118 Driver Configuration
119 The following driver configuration properties may be defined in the
120 log.conf file:
121
122 msgid=1 Each message will be preceded by a message ID as described in
123 syslogd(1M).
124
125 msgid=0 Message IDs will not be generated.
126
127 FILES
128 /dev/log Log driver.
129
130 /dev/conslog Write only instance of the log driver, for console
131 logging.
132
133 /kernel/drv/log.conf Log configuration file.
134
135 EXAMPLES
136 Example 1 I_ERRLOG registration.
137
138 struct strioctl ioc;
139 ioc.ic_cmd = I_ERRLOG;
140 ioc.ic_timout = 0; /* default timeout (15 secs.) */
141 ioc.ic_len = 0;
142 ioc.ic_dp = NULL;
143 ioctl(log, I_STR, &ioc);
144
145 Example 2 I_TRCLOG registration.
146
147 struct trace_ids tid[2];
148 tid[0].ti_mid = 2;
149 tid[0].ti_sid = 0;
150 tid[0].ti_level = 1;
151 tid[1].ti_mid = 1002;
152 tid[1].ti_sid = -1; /* any sub-id will be allowed */
153 tid[1].ti_level = -1; /* any level will be allowed */
154 ioc.ic_cmd = I_TRCLOG;
155 ioc.ic_timout = 0;
156 ioc.ic_len = 2 * sizeof(struct trace_ids);
157 ioc.ic_dp = (char *)tid;
158 ioctl(log, I_STR, &ioc);
159
160 Example 3 Submitting a log message (no arguments)
161
162 struct strbuf ctl, dat;
163 struct log_ctl lc;
164 char *message = "Don't forget to pick up some milk "
165 "on the way home";
166 ctl.len = ctl.maxlen = sizeof(lc);
167 ctl.buf = (char *)&lc;
168 dat.len = dat.maxlen = strlen(message);
169 dat.buf = message;
170 lc.level = 0;
171 lc.flags = SL_ERROR|SL_NOTIFY;
172 putmsg(log, &ctl, &dat, 0);
173
174 SEE ALSO
175 strace(1M), strerr(1M), getmsg(2), ioctl(2), putmsg(2), write(2),
176 strlog(9F)
177
178 STREAMS Programming Guide
179
180 illumos January 20, 2018 illumos