]>
Commit | Line | Data |
---|---|---|
224c7076 | 1 | .\" Copyright (c) 2005-2007 Apple Inc. |
3d9156a7 A |
2 | .\" All rights reserved. |
3 | .\" | |
4 | .\" Redistribution and use in source and binary forms, with or without | |
5 | .\" modification, are permitted provided that the following conditions | |
6 | .\" are met: | |
7 | .\" 1. Redistributions of source code must retain the above copyright | |
8 | .\" notice, this list of conditions and the following disclaimer. | |
9 | .\" 2. Redistributions in binary form must reproduce the above copyright | |
10 | .\" notice, this list of conditions and the following disclaimer in the | |
11 | .\" documentation and/or other materials provided with the distribution. | |
12 | .\" 4. Neither the name of Apple Computer nor the names of its contributors | |
13 | .\" may be used to endorse or promote products derived from this software | |
14 | .\" without specific prior written permission. | |
15 | .\" | |
16 | .\" THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER AND CONTRIBUTORS ``AS IS'' AND | |
17 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
18 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
19 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
20 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
21 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
22 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
23 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
24 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
25 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
26 | .\" SUCH DAMAGE. | |
27 | .\" | |
28 | .\" | |
224c7076 | 29 | .Dd January 11, 2007 |
3d9156a7 A |
30 | .Dt asl 3 |
31 | .Os "Mac OS X" | |
32 | .Sh NAME | |
224c7076 | 33 | .Nm asl_add_log_file , |
3d9156a7 | 34 | .Nm asl_close , |
3d9156a7 | 35 | .Nm asl_free , |
3d9156a7 | 36 | .Nm asl_get , |
3d9156a7 | 37 | .Nm asl_key , |
224c7076 A |
38 | .Nm asl_log , |
39 | .Nm asl_new , | |
40 | .Nm asl_open , | |
3d9156a7 | 41 | .Nm asl_remove_log_file , |
3d9156a7 | 42 | .Nm asl_search , |
224c7076 A |
43 | .Nm asl_send , |
44 | .Nm asl_set , | |
45 | .Nm asl_set_filter , | |
46 | .Nm asl_set_query , | |
47 | .Nm asl_unset , | |
48 | .Nm asl_vlog , | |
49 | .Nm aslresponse_free , | |
50 | .Nm aslresponse_next | |
3d9156a7 A |
51 | .Nd system log message sending and searching functions |
52 | .Sh SYNOPSIS | |
53 | .Fd #include <asl.h> | |
224c7076 A |
54 | .\" |
55 | .Ft int | |
56 | .Fo asl_add_log_file | |
57 | .Fa "aslclient asl" | |
58 | .Fa "int fd" | |
59 | .Fc | |
3d9156a7 | 60 | .Ft void |
224c7076 A |
61 | .Fo asl_close |
62 | .Fa "aslclient asl" | |
63 | .Fc | |
3d9156a7 | 64 | .Ft void |
224c7076 A |
65 | .Fo asl_free |
66 | .Fa "aslmsg msg" | |
67 | .Fc | |
3d9156a7 | 68 | .Ft const char * |
224c7076 A |
69 | .Fo asl_get |
70 | .Fa "aslmsg msg" | |
71 | .Fa "const char *key" | |
72 | .Fc | |
3d9156a7 | 73 | .Ft const char * |
224c7076 A |
74 | .Fo asl_key |
75 | .Fa "aslmsg msg" | |
76 | .Fa "uint32_t n" | |
77 | .Fc | |
3d9156a7 | 78 | .Ft int |
224c7076 A |
79 | .Fo asl_log |
80 | .Fa "aslclient asl" | |
81 | .Fa "aslmsg msg" | |
82 | .Fa "int level" | |
83 | .Fa "const char *format" | |
84 | .Fa "..." | |
85 | .Fc | |
86 | .Ft aslmsg | |
87 | .Fo asl_new | |
88 | .Fa "uint32_t type" | |
89 | .Fc | |
90 | .Ft aslclient | |
91 | .Fo asl_open | |
92 | .Fa "const char *ident" | |
93 | .Fa "const char *facility" | |
94 | .Fa "uint32_t opts" | |
95 | .Fc | |
3d9156a7 | 96 | .Ft int |
224c7076 A |
97 | .Fo asl_remove_log_file |
98 | .Fa "aslclient asl" | |
99 | .Fa "int fd" | |
100 | .Fc | |
101 | .Ft aslresponse | |
102 | .Fo asl_search | |
103 | .Fa "aslclient asl" | |
104 | .Fa "aslmsg msg" | |
105 | .Fc | |
3d9156a7 | 106 | .Ft int |
224c7076 A |
107 | .Fo asl_send |
108 | .Fa "aslclient asl" | |
109 | .Fa "aslmsg msg" | |
110 | .Fc | |
3d9156a7 | 111 | .Ft int |
224c7076 A |
112 | .Fo asl_set |
113 | .Fa "aslmsg msg" | |
114 | .Fa "const char *key" | |
115 | .Fa "const char *value" | |
116 | .Fc | |
3d9156a7 | 117 | .Ft int |
224c7076 A |
118 | .Fo asl_set_filter |
119 | .Fa "aslclient asl" | |
120 | .Fa "int f" | |
121 | .Fc | |
3d9156a7 | 122 | .Ft int |
224c7076 A |
123 | .Fo asl_set_query |
124 | .Fa "aslmsg msg" | |
125 | .Fa "const char *key" | |
126 | .Fa "const char *value" | |
127 | .Fa "uint32_t op" | |
128 | .Fc | |
3d9156a7 | 129 | .Ft int |
224c7076 A |
130 | .Fo asl_unset |
131 | .Fa "aslmsg msg" | |
132 | .Fa "const char *key" | |
133 | .Fc | |
134 | .Ft int | |
135 | .Fo asl_vlog | |
136 | .Fa "aslclient asl" | |
137 | .Fa "aslmsg msg" | |
138 | .Fa "int level" | |
139 | .Fa "const char *format" | |
140 | .Fa "va_list ap" | |
141 | .Fc | |
3d9156a7 | 142 | .Ft void |
224c7076 A |
143 | .Fo aslresponse_free |
144 | .Fa "aslresponse a" | |
145 | .Fc | |
146 | .Ft aslmsg | |
147 | .Fo aslresponse_next | |
148 | .Fa "aslresponse r" | |
149 | .Fc | |
3d9156a7 | 150 | .Sh DESCRIPTION |
224c7076 | 151 | These routines provide an interface to the Apple System Log facility. |
3d9156a7 A |
152 | They are intended to be a replacement for the |
153 | .Xr syslog 3 | |
154 | API, which will continue to be supported for backwards compatibility. | |
224c7076 A |
155 | The new API allows client applications |
156 | to create flexible, structured messages and send them to the | |
3d9156a7 A |
157 | .Nm syslogd |
158 | server, where they may undergo additional processing. | |
224c7076 A |
159 | Messages received by the server are saved in a data store |
160 | (subject to input filtering constraints). | |
161 | This API permits clients to create queries | |
162 | and search the message data store for matching messages. | |
3d9156a7 A |
163 | .Ss MESSAGES |
164 | At the core of this API is the aslmsg structure. | |
224c7076 A |
165 | Although the structure is opaque and may not be directly manipulated, |
166 | it contains a list of key/value pairs. | |
3d9156a7 A |
167 | All keys and values are NULL-terminated C language character strings. |
168 | UTF-8 encoding may be used for non-ASCII characters. | |
169 | .Pp | |
224c7076 A |
170 | Message structures are generally used to send log messages, |
171 | and are created thusly: | |
3d9156a7 A |
172 | .Pp |
173 | aslmsg m = asl_new(ASL_TYPE_MSG); | |
174 | .Pp | |
224c7076 A |
175 | Another message type, ASL_TYPE_QUERY, |
176 | is used to create queries when searching the data store. | |
3d9156a7 A |
177 | Query type messages and searching are described in detail in the |
178 | .Sx SEARCHING | |
179 | section below. | |
224c7076 A |
180 | For the remainder of this section, |
181 | the messages described will be of the ASL_TYPE_MSG variety. | |
3d9156a7 | 182 | .Pp |
224c7076 A |
183 | Each aslmsg contains a default set of keys |
184 | and values that are associated with them. | |
3d9156a7 A |
185 | These keys are listed in the asl.h header file. |
186 | They are: | |
187 | .Pp | |
224c7076 A |
188 | #define ASL_KEY_TIME "Time" |
189 | #define ASL_KEY_HOST "Host" | |
190 | #define ASL_KEY_SENDER "Sender" | |
191 | #define ASL_KEY_FACILITY "Facility" | |
192 | #define ASL_KEY_PID "PID" | |
193 | #define ASL_KEY_UID "UID" | |
194 | #define ASL_KEY_GID "GID" | |
195 | #define ASL_KEY_LEVEL "Level" | |
196 | #define ASL_KEY_MSG "Message" | |
3d9156a7 A |
197 | .Pp |
198 | Many of these correspond to equivalent parts of messages described in the | |
199 | .Xr syslog 3 | |
200 | API. | |
201 | Values associated with these message keys are assigned appropriate defaults. | |
202 | The value for ASL_KEY_HOST is the local host name, | |
203 | the value associated with ASL_KEY_SENDER is the process name, | |
204 | the ASL_KEY_PID is the client's process ID number, and so on. | |
205 | .Pp | |
206 | Note the addition of the UID and GID keys. | |
207 | The values for UID and GID are set in library code by the message sender. | |
224c7076 A |
208 | The server will attempt to confirm the values, |
209 | but no claim is made that these values cannot be maliciously overridden | |
210 | in an attempt to deceive a log message reader | |
211 | as to the identity of the sender of a message. | |
3d9156a7 A |
212 | The contents of log messages must be regarded as insecure. |
213 | .Pp | |
3d9156a7 A |
214 | The |
215 | .Xr asl 3 | |
216 | API does not require a process to choose a facility name. | |
217 | The | |
218 | .Nm syslogd | |
219 | server will use a default value of | |
220 | .Dq user | |
221 | if a facility is not set. | |
224c7076 A |
222 | However, a client may set a facility name as an argument in the |
223 | .Nm asl_open | |
224 | call, or by setting a specific value for the ASL_KEY_FACILITY in a message: | |
3d9156a7 | 225 | .Pp |
224c7076 | 226 | asl_set(m, ASL_KEY_FACILITY, "com.somename.greatservice"); |
3d9156a7 A |
227 | .Pp |
228 | An application may choose any facility name at will. | |
224c7076 A |
229 | Different facility names may be attached to different messages, perhaps to distinguish different subsystems in log messages. |
230 | Developers are encouraged to adopt a | |
231 | .Dq Reverse ICANN | |
232 | naming convention to avoid conflicting facility names. | |
233 | .Pp | |
234 | Default values are set in the message for each of the keys listed above, | |
235 | except for ASL_KEY_MSG, | |
236 | which may be explicitly set at any time using the | |
3d9156a7 A |
237 | .Nm asl_set |
238 | routine, or implicitly set at the time the message is sent using the | |
239 | .Nm asl_log | |
240 | or | |
241 | .Nm asl_vlog | |
242 | routines. | |
224c7076 A |
243 | These two routines also have an integer-level parameter |
244 | for specifying the log priority. | |
3d9156a7 | 245 | The ASL_KEY_LEVEL value is set accordingly. |
224c7076 A |
246 | Finally, the value associated with ASL_KEY_TIME |
247 | is set in the sending routine. | |
3d9156a7 | 248 | .Pp |
224c7076 A |
249 | Although it may appear that there is significant overhead required |
250 | to send a log message using this API, | |
3d9156a7 A |
251 | the opposite is actually true. |
252 | A simple | |
253 | .Dq Hello World | |
254 | program requires only: | |
255 | .Pp | |
256 | #include <asl.h> | |
257 | ... | |
258 | asl_log(NULL, NULL, ASL_LEVEL_INFO, "Hello World!"); | |
259 | .Pp | |
260 | Both | |
261 | .Nm asl_log | |
262 | and | |
263 | .Nm asl_vlog | |
224c7076 A |
264 | will provide the appropriate default values |
265 | when passed a NULL aslmsg argument. | |
3d9156a7 A |
266 | .Pp |
267 | .Pp | |
268 | In this example, the aslclient argument is NULL. | |
269 | This is sufficient for a single-threaded application, | |
270 | or for an application which only sends log messages from a single thread. | |
224c7076 A |
271 | When logging from multiple threads, |
272 | each thread must open a separate client handle using | |
3d9156a7 A |
273 | .Nm asl_open . |
274 | The client handle may then be closed when it is no longer required using | |
275 | .Nm asl_close . | |
276 | .Pp | |
224c7076 A |
277 | When an application requires additional keys and values |
278 | to be associated with each log message, | |
3d9156a7 A |
279 | a single message structure may be allocated and set up as |
280 | .Dq template | |
281 | message of sorts: | |
282 | .Pp | |
283 | aslmsg m = asl_new(ASL_TYPE_MSG); | |
224c7076 | 284 | asl_set(m, ASL_KEY_FACILITY, "com.secrets.r.us"); |
3d9156a7 A |
285 | asl_set(m, "Clearance", "Top Secret"); |
286 | ... | |
287 | asl_log(NULL, m, ASL_LEVEL_NOTICE, "Message One"); | |
288 | ... | |
289 | asl_log(NULL, m, ASL_LEVEL_ERR, "Message Two"); | |
290 | .Pp | |
291 | The message structure will carry the values set for the | |
292 | .Dq Facility | |
293 | and | |
294 | .Dq Clearance | |
295 | keys so that they are used in each call to | |
296 | .Nm asl_log , | |
224c7076 A |
297 | while the log level and the message text |
298 | are taken from the calling parameters. | |
299 | .Pp | |
300 | The | |
301 | .Ar format | |
302 | argument to | |
303 | .Nm asl_log | |
304 | and | |
305 | .Nm asl_vlog | |
306 | is identical to | |
307 | .Xr printf 3 , | |
308 | and may include | |
309 | .Ql %m , | |
310 | which is replaced by the current error message | |
311 | (as denoted by the global variable | |
312 | .Va errno ; | |
313 | see | |
314 | .Xr strerror 3 . ) | |
3d9156a7 A |
315 | .Pp |
316 | Key/value pairs may be removed from a message structure with | |
317 | .Nm asl_unset . | |
318 | A message may be freed using | |
319 | .Nm asl_free . | |
320 | .Pp | |
321 | The | |
322 | .Nm asl_send | |
323 | routine is used by | |
324 | .Nm asl_log | |
325 | and | |
326 | .Nm asl_vlog | |
327 | to transmit a message to the server. | |
224c7076 A |
328 | This routine sets the value associated with ASL_KEY_TIME |
329 | and sends the message. | |
330 | It may be called directly if all of a message's key/value pairs | |
331 | have been created using | |
3d9156a7 | 332 | .Nm asl_set . |
224c7076 A |
333 | .Ss SECURITY |
334 | Messages that are sent to the | |
335 | .Nm syslogd | |
336 | server may be saved in a message store. | |
337 | The store may be searched using | |
338 | .Nm asl_search , | |
339 | as described below. | |
340 | By default, all messages are readable by any user. | |
341 | However, some applications may wish to restrict read access | |
342 | for some messages. | |
343 | To accomodate this, | |
344 | a client may set a value for the "ReadUID" and "ReadGID" keys. | |
345 | These keys may be associated with a value | |
346 | containing an ASCII representation of a numeric UID or GID. | |
347 | Only the root user (UID 0), | |
348 | the user with the given UID, | |
349 | or a member of the group with the given GID | |
350 | may fetch access-controlled messages from the database. | |
351 | .Pp | |
352 | Although the ASL system does not require a "Facility" key in a message, | |
353 | many processes specify a "Facility" value similar | |
354 | to the common usage of the BSD | |
355 | .Nm syslog | |
356 | API, although developers are encouraged to adopt facility names that make sense for their application. | |
357 | A | |
358 | .Dq Reverse ICANN | |
359 | naming convention (e.g. "com.apple.system.syslog") should be adopted to avoid conflicting names. | |
360 | The ASL system generally allows any string to be used as a facility value, | |
361 | with one exception. | |
362 | The value "com.apple.system", | |
363 | or any string that has "com.apple.system" as a prefix, | |
364 | may only be used by processes running with the UID 0. | |
365 | This allows system processes to log messages that can not be "spoofed" by user processes. | |
366 | Non-UID 0 client processes that specify "com.apple.system" as a facility, will be assigned the value "user" | |
367 | by the | |
368 | .Nm syslogd | |
369 | server. | |
3d9156a7 A |
370 | .Ss CLIENT HANDLES |
371 | When logging is done from a single thread, | |
224c7076 A |
372 | a NULL value may be used in any of the routines |
373 | that require an aslclient argument. | |
374 | In this case, the library will open an internal client handle | |
375 | on behalf of the application. | |
3d9156a7 A |
376 | .Pp |
377 | If multiple threads must do logging, | |
378 | or if client options are desired, | |
379 | then the application should call | |
380 | .Nm asl_open | |
381 | to create a client handle for each thread. | |
382 | As a convenience, | |
383 | the | |
384 | .Nm asl_open | |
385 | routine may be given an ident argument, | |
386 | which becomes the default value for the ASL_KEY_SENDER key, | |
387 | and a facility argument, | |
224c7076 | 388 | which becomes the value associated with the ASL_KEY_FACILITY key. |
3d9156a7 A |
389 | .Pp |
390 | Several options are available when creating a client handle. | |
391 | They are: | |
392 | .Pp | |
393 | .Bl -tag -width "ASL_OPT_NO_REMOTE" -compact | |
394 | .It ASL_OPT_STDERR | |
395 | adds stderr as an output file descriptor | |
396 | .It ASL_OPT_NO_DELAY | |
397 | connects to the server immediately | |
398 | .It ASL_OPT_NO_REMOTE | |
399 | disables remote-control filter adjustment | |
400 | .El | |
401 | .Pp | |
402 | See the FILTERING section below, and the | |
403 | .Xr syslog 1 | |
404 | for additional details on filter controls. | |
405 | .Pp | |
406 | A client handle is closed and it's resources released using | |
407 | .Nm asl_close . | |
224c7076 A |
408 | Note that if additional file descriptors were added to the handle, |
409 | either using the ASL_OPT_STDERR option | |
410 | or afterwards with the | |
3d9156a7 A |
411 | .Nm asl_add_log_file |
412 | routine, those file descriptors are not closed by | |
413 | .Nm asl_close . | |
414 | .Ss LOGGING TO ADDITIONAL FILES | |
415 | If a client handle is opened with the ASL_OPT_STDERR option to | |
416 | .Nm asl_open , | |
417 | a copy of each log message will be sent to stderr. | |
418 | Additional output streams may be include using | |
419 | .Nm asl_add_log_file . | |
224c7076 A |
420 | .Pp |
421 | Messages sent to stderr or other files are printed in the "standard" message format | |
422 | also used as a default format by the | |
423 | .Xr syslog 1 | |
424 | command line utility. | |
425 | The | |
426 | .Xr strvis 3 | |
427 | encoding with the VIS_CSTYLE, VIS_TAB, and VIS_NL options is used to print the message. | |
428 | .Pp | |
429 | File descriptors may be removed from the list of outputs associated | |
430 | with a client handle with | |
3d9156a7 A |
431 | .Nm asl_remove_log_file . |
432 | This routine simply removes the file descriptor from the output list. | |
433 | The file is not closed as a result. | |
434 | .Pp | |
224c7076 A |
435 | The ASL_OPT_STDERR option may not be unset |
436 | after a client handle has been opened. | |
3d9156a7 A |
437 | .Pp |
438 | In the present release of Mac OS X, a | |
439 | .Dq raw | |
224c7076 A |
440 | format is used to format messages |
441 | that are sent to file descriptors | |
442 | that have been added to a client handle. | |
3d9156a7 A |
443 | Each message is preceded by a 10-character field containing a message length. |
444 | The message length is padded with leading white space. | |
445 | The length gives the string length of the remainder of the output string. | |
446 | Following the length is a space character, and then the message. | |
224c7076 A |
447 | The message is encoded as a set of key/value pairs |
448 | enclosed in square brackets, | |
3d9156a7 A |
449 | which are themselves separated by a space character. |
450 | The key is separated from the value by space character. | |
451 | Embedded closing square brackets are escaped by a backslash. | |
452 | Embedded space characters in keys are escaped by a backslash; | |
453 | Embedded newlines are summarily turned into semicolons. | |
454 | The output is terminated by a trailing newline and a NUL character. | |
455 | .Ss SEARCHING | |
456 | The | |
457 | .Nm syslogd | |
224c7076 A |
458 | server archives received messages in a data store |
459 | that may be searched using the | |
3d9156a7 A |
460 | .Nm asl_search , |
461 | .Nm aslresponse_next , | |
462 | and | |
463 | .Nm aslresponse_free | |
464 | routines. | |
465 | A query message is created using: | |
466 | .Pp | |
467 | aslmsg q = asl_new(ASL_TYPE_QUERY); | |
468 | .Pp | |
469 | Search settings are made in the query using | |
470 | .Nm asl_set_query . | |
471 | A search is performed on the data store with | |
472 | .Nm asl_search . | |
473 | It returns an | |
474 | .Ft aslresponse | |
475 | structure. | |
476 | The caller may then call | |
477 | .Nm aslresponse_next | |
478 | to iterate through matching messages. | |
479 | The | |
480 | .Ft aslresponse | |
481 | structure may be freed with | |
482 | .Nm aslresponse_free . | |
483 | .Pp | |
484 | Like other messages, ASL_TYPE_QUERY messages contain keys and values. | |
485 | They also associate an operation with each key and value. | |
486 | The operation is used to decide if a message matches the query. | |
487 | The simplest operation is ASL_QUERY_OP_EQUAL, which tests for equality. | |
224c7076 A |
488 | For example, the following code snippet searches for messages |
489 | with a Sender value equal to | |
3d9156a7 A |
490 | .Dq MyApp . |
491 | .Pp | |
492 | aslmsg m; | |
493 | aslresponse r; | |
494 | q = asl_new(ASL_TYPE_QUERY); | |
495 | asl_set_query(q, ASL_KEY_SENDER, "MyApp", ASL_QUERY_OP_EQUAL); | |
496 | r = asl_search(NULL, q); | |
497 | .Pp | |
498 | More complex searches may be performed using other query operations. | |
499 | .Pp | |
500 | .Bl -tag -width "ASL_QUERY_OP_GREATER_EQUAL" -compact | |
501 | .It ASL_QUERY_OP_EQUAL | |
502 | value equality | |
503 | .It ASL_QUERY_OP_GREATER | |
504 | value greater than | |
505 | .It ASL_QUERY_OP_GREATER_EQUAL | |
506 | value greater than or equal to | |
507 | .It ASL_QUERY_OP_LESS | |
508 | value less than | |
509 | .It ASL_QUERY_OP_LESS_EQUAL | |
510 | value less than or equal to | |
511 | .It ASL_QUERY_OP_NOT_EQUAL | |
512 | value not equal | |
513 | .It ASL_QUERY_OP_REGEX | |
514 | regular expression search | |
515 | .It ASL_QUERY_OP_TRUE | |
516 | always true - use to test for the existence of a key | |
517 | .El | |
518 | .Pp | |
519 | Regular expression search uses | |
520 | .Xr regex 3 | |
521 | library. | |
522 | Patterns are compiled using the REG_EXTENDED and REG_NOSUB options. | |
523 | .Pp | |
224c7076 A |
524 | Modifiers that change the behavior of these operations |
525 | may also be specified by ORing the modifier value with the operation. | |
3d9156a7 A |
526 | The modifiers are: |
527 | .Pp | |
528 | .Bl -tag -width "ASL_QUERY_OP_SUBSTRING" -compact | |
529 | .It ASL_QUERY_OP_CASEFOLD | |
530 | string comparisons are case-folded | |
531 | .It ASL_QUERY_OP_PREFIX | |
532 | match a leading substring | |
533 | .It ASL_QUERY_OP_SUFFIX | |
534 | match a trailing substring | |
535 | .It ASL_QUERY_OP_SUBSTRING | |
536 | match any substring | |
537 | .It ASL_QUERY_OP_NUMERIC | |
538 | values are converted to integer using | |
539 | .Nm atoi | |
540 | .El | |
541 | .Pp | |
224c7076 A |
542 | The only modifier that is checked |
543 | for ASL_QUERY_OP_REGEX search is ASL_QUERY_OP_CASEFOLD. | |
544 | This causes the regular expression to be compiled | |
545 | with the REG_ICASE option. | |
3d9156a7 A |
546 | .Pp |
547 | If a query message contains more than one set of key/value/operation triples, | |
548 | the result will be a logical AND. For example, to find messages from | |
549 | .Dq MyApp | |
550 | with a priority level less than or equal to | |
551 | .Dq 3 : | |
552 | .Pp | |
553 | aslmsg q; | |
554 | aslresponse r; | |
555 | q = asl_new(ASL_TYPE_QUERY); | |
556 | asl_set_query(q, ASL_KEY_SENDER, "MyApp", ASL_QUERY_OP_EQUAL); | |
557 | asl_set_query(q, ASL_KEY_LEVEL, "3", | |
558 | ASL_QUERY_OP_LESS_EQUAL | ASL_QUERY_OP_NUMERIC); | |
559 | r = asl_search(NULL, q); | |
560 | .Pp | |
561 | After calling | |
562 | .Nm asl_search | |
563 | to get an | |
564 | .Ft aslresponse | |
565 | structure, use | |
566 | .Nm aslresponse_next | |
567 | to iterate through all matching messages. | |
568 | To iterate through the keys and values in a message, use | |
569 | .Nm asl_key | |
570 | to iterate through the keys, then call | |
571 | .Nm asl_get | |
572 | to get the value associated with each key. | |
573 | .Pp | |
574 | aslmsg q, m; | |
575 | int i; | |
576 | const char *key, *val; | |
577 | .Pp | |
578 | ... | |
579 | r = asl_search(NULL, q); | |
580 | while (NULL != (m = aslresponse_next(r))) | |
581 | { | |
582 | for (i = 0; (NULL != (key = asl_key(m, i))); i++) | |
583 | { | |
584 | val = asl_get(m, key); | |
585 | ... | |
586 | } | |
587 | } | |
588 | aslresponse_free(r); | |
589 | .Pp | |
590 | .Ss FILTERING AND REMOTE CONTROL | |
591 | Clients may set a filter mask value with | |
592 | .Nm asl_set_filter . | |
593 | The mask specifies which messages should be sent to the | |
594 | .Nm syslogd | |
595 | daemon by specifying a yes/no setting for each priority level. | |
224c7076 A |
596 | Clients typically set a filter mask |
597 | to avoid sending relatively unimportant messages. | |
598 | For example, Debug or Info priority level messages | |
599 | are generally only useful for debugging operations. | |
600 | By setting a filter mask, a process can improve performance | |
601 | by avoiding sending messages that are in most cases unnecessary. | |
602 | .Pp | |
603 | .Nm asl_set_filter returns the previous value of the filter, i.e. the value of the filter before the routine was called. | |
3d9156a7 A |
604 | .Pp |
605 | As a convenience, the macros ASL_FILTER_MASK(level) and ASL_FILTER_MASK_UPTO(level) | |
606 | may be used to construct a bit mask corresponding to a given priority level, | |
224c7076 A |
607 | or corresponding to a bit mask for all priority levels |
608 | from ASL_LEVEL_EMERG to a given input level. | |
3d9156a7 A |
609 | .Pp |
610 | The default filter mask is ASL_FILTER_MASK_UPTO(ASL_LEVEL_NOTICE). | |
224c7076 A |
611 | This means that by default, |
612 | and in the absence of remote-control changes (described below), | |
613 | ASL_LEVEL_DEBUG and ASL_LEVEL_INFO priority level messages | |
614 | are not sent to the | |
3d9156a7 A |
615 | .Mn syslogd |
616 | server. | |
617 | .Pp | |
618 | Three different filters exist for each application. | |
619 | The first is the filter mask set using | |
620 | .Nm asl_set_filter | |
621 | as described above. | |
622 | The Apple System Log facility also manages a | |
623 | .Dq master | |
624 | filter mask. | |
224c7076 A |
625 | The master filter mask usually has a value |
626 | that indicates to the library that it is | |
3d9156a7 A |
627 | .Dq off , |
628 | and thus it has no effect. | |
224c7076 A |
629 | However, the mask filter mask may be enabled |
630 | by giving it a value using the | |
3d9156a7 A |
631 | .Nm syslog |
632 | command, using the | |
633 | .Fl c | |
634 | 0 option. | |
635 | When the master filter mask has been set, | |
636 | it takes precedence over the client's filter mask. | |
224c7076 A |
637 | The client's mask is unmodified, |
638 | and will become active again if remote-control filtering is disabled. | |
3d9156a7 A |
639 | .Pp |
640 | In addition to the master filter mask, | |
224c7076 A |
641 | The Apple System Log facility |
642 | also manages a per-client remote-control filter mask. | |
3d9156a7 A |
643 | Like the master filter mask, the per-client mask is usually |
644 | .Dq off , | |
645 | having no effect on a client. | |
646 | If a per-client filter mask is set using the | |
647 | .Nm syslog | |
648 | command, using the | |
649 | .Fl c Ar process | |
224c7076 A |
650 | option, then it takes precedence |
651 | over both the client's filter mask and the master filter mask. | |
652 | As is the case with the master filter mask, | |
653 | a per-client mask ceases having any effect when if is disabled. | |
3d9156a7 A |
654 | .Pp |
655 | The ASL_OPT_NO_REMOTE option to | |
656 | .Nm asl_open | |
224c7076 A |
657 | causes both the master and per-client remote-control masks |
658 | to be ignored in the library. | |
659 | In that case, only the client's own filter mask | |
660 | is used to determine which messages are sent to the server. | |
661 | This may be useful for Applications that produce log messages | |
662 | that should never be filtered, due to security considerations. | |
663 | Note that root (administrator) access is required | |
664 | to set or change the master filter mask, | |
665 | and that only root may change a per-client remote-control filter mask | |
666 | for a root (UID 0) process. | |
3d9156a7 A |
667 | .Sh HISTORY |
668 | These functions first appeared in | |
669 | Mac OS X 10.4. | |
670 | .Sh SEE ALSO | |
224c7076 A |
671 | .Xr syslog 1 , |
672 | .Xr strvis 3 , | |
673 | .Xr syslogd 8 |