]> git.saurik.com Git - apple/libc.git/blame_incremental - gen/asl.3
Libc-594.9.4.tar.gz
[apple/libc.git] / gen / asl.3
... / ...
CommitLineData
1.\" Copyright (c) 2005-2007 Apple Inc.
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.\"
29.Dd January 11, 2007
30.Dt asl 3
31.Os "Mac OS X"
32.Sh NAME
33.Nm asl_add_log_file ,
34.Nm asl_close ,
35.Nm asl_free ,
36.Nm asl_get ,
37.Nm asl_key ,
38.Nm asl_log ,
39.Nm asl_new ,
40.Nm asl_open ,
41.Nm asl_remove_log_file ,
42.Nm asl_search ,
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
51.Nd system log message sending and searching functions
52.Sh SYNOPSIS
53.Fd #include <asl.h>
54.\"
55.Ft int
56.Fo asl_add_log_file
57.Fa "aslclient asl"
58.Fa "int fd"
59.Fc
60.Ft void
61.Fo asl_close
62.Fa "aslclient asl"
63.Fc
64.Ft void
65.Fo asl_free
66.Fa "aslmsg msg"
67.Fc
68.Ft const char *
69.Fo asl_get
70.Fa "aslmsg msg"
71.Fa "const char *key"
72.Fc
73.Ft const char *
74.Fo asl_key
75.Fa "aslmsg msg"
76.Fa "uint32_t n"
77.Fc
78.Ft int
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
96.Ft int
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
106.Ft int
107.Fo asl_send
108.Fa "aslclient asl"
109.Fa "aslmsg msg"
110.Fc
111.Ft int
112.Fo asl_set
113.Fa "aslmsg msg"
114.Fa "const char *key"
115.Fa "const char *value"
116.Fc
117.Ft int
118.Fo asl_set_filter
119.Fa "aslclient asl"
120.Fa "int f"
121.Fc
122.Ft int
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
129.Ft int
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
142.Ft void
143.Fo aslresponse_free
144.Fa "aslresponse r"
145.Fc
146.Ft aslmsg
147.Fo aslresponse_next
148.Fa "aslresponse r"
149.Fc
150.Sh DESCRIPTION
151These routines provide an interface to the Apple System Log facility.
152They are intended to be a replacement for the
153.Xr syslog 3
154API, which will continue to be supported for backwards compatibility.
155The new API allows client applications
156to create flexible, structured messages and send them to the
157.Nm syslogd
158server, where they may undergo additional processing.
159Messages received by the server are saved in a data store
160(subject to input filtering constraints).
161This API permits clients to create queries
162and search the message data store for matching messages.
163.Pp
164An introduction to the concepts underlying this interface follows the interface summary below.
165.Ss INTERFACE SUMMARY
166.Fo asl_open
167.Fa ident
168.Fa facility
169.Fa opts
170.Fc
171creates and returns a client handle, or NULL if an error occurs in the library.
172Messages sent using this handle will default to having the string
173.Ar ident
174as the value assocated with the ASL_KEY_SENDER key, and the value
175.Ar facility
176assocated with the ASL_KEY_FACILITY key.
177Several options are available, as described in the
178.Sx CLIENT HANDLES
179section.
180.Pp
181Multi-threaded applications should create one client handle for each thread that logs messages.
182A client may use NULL as a client handle, in which case a default handle managed by the library will be used.
183A NULL handle may be used safely by multiple threads, but the threads will contend for a single internal lock when
184sending log messages using a NULL handle.
185.Pp
186.Fo asl_close
187.Fa asl
188.Fc
189closes the client handle
190.Ar asl
191and releases its associated resources.
192.Pp
193.Fo asl_add_log_file
194.Fa asl
195.Fa fd
196.Fc
197adds the file descriptor
198.Ar fd
199to the a set of file descriptors associated with the client handle
200.Ar asl .
201Each log message sent by that client handle is also written to these file descriptors.
202Returns 0 on success, non-zero on failure.
203.Pp
204.Fo asl_remove_log_file
205.Fa asl
206.Fa fd
207.Fc
208removes a file descriptor from the set of file descriptors associated with a client handle.
209Returns 0 on success, non-zero on failure.
210.Pp
211.Fo asl_new
212.Fa type
213.Fc
214allocates and returns an aslmsg structure, or NULL in the case of a failure in the library.
215The
216.Ar type
217argument must be ASL_TYPE_MSG or ASL_TYPE_QUERY.
218.Pp
219.Fo asl_free
220.Fa msg
221.Fc
222frees an aslmsg and releases resources associated with the structure.
223.Pp
224.Fo asl_set
225.Fa msg
226.Fa key
227.Fa value
228.Fc
229creates a new key and value in an aslmsg structure, or replaces the value of an existing key.
230Returns 0 on success, non-zero on failure.
231.Pp
232.Fo asl_set_query
233.Fa msg
234.Fa key
235.Fa op
236.Fa value
237.Fc
238is used to construct searches.
239It is similar to
240.Fn asl_set ,
241except that it takes an additional
242.Ar op
243(operation) argument.
244Creates a new (key, op, value) triple in an aslmsg structure,
245or replaces the value and operation for an existing key.
246See the
247.Sx SEARCHING
248section for more information.
249Returns 0 on success, non-zero on failure.
250.Pp
251.Fo asl_unset
252.Fa msg
253.Fa key
254.Fc
255removes a key and its associated value from an aslmsg structure.
256Returns 0 on success, non-zero on failure.
257.Pp
258.Fo asl_key
259.Fa msg
260.Fa n
261.Fc
262returns the nth key in an aslmsg (beginning at zero),
263allowing an application to iterate through the keys.
264Returns NULL if
265.Ar n
266indexes beyond the number of keys in
267.Ar msg .
268.Pp
269.Fo asl_get
270.Fa msg
271.Fa key
272.Fc
273returns the value associated with
274.Ar key
275in the aslmsg
276.Ar msg .
277Returns NULL if
278.Ar msg
279does not contain
280. Ar key .
281.Pp
282.Fo asl_set_filter
283.Fa asl
284.Fa f
285.Fc
286sets a filter for messages being sent to the server.
287The filter is a bitmask representing priority levels.
288Only messages having a priority level with a corresponding bit set in the filter mask are sent to the
289.Nm syslogd
290server.
291The filter does not control writes to additional files associated with the client handle using
292.Fn asl_add_log_file .
293Returns the previous filter value.
294.Pp
295.Fo asl_log
296.Fa asl
297.Fa msg
298.Fa level
299.Fa format
300.Fa args...
301.Fc
302sends a log to the server (subject to filtering, see
303.Fn asl_set_filter
304above) and to any file descriptors associated with the client handle
305.Ar asl .
306The
307.Ar msg
308argument may contain any keys and values, which will be formatted as part of the log message.
309The value for ASL_KEY_LEVEL is supplied by the
310.Ar level
311argument.
312The value for ASL_KEY_MESSAGE is computed from
313.Ar format
314and the associated arguments
315.Ar args... .
316Normal
317.Fn printf
318style argument processing is applied to the format and the arguments.
319The format may also contain
320.Dq %m
321which will be substituted with the string value corresponding to the current
322.Em errno .
323.Pp
324.Fo asl_vlog
325.Fa asl
326.Fa msg
327.Fa level
328.Fa format
329.Fa ap
330.Fc
331is similar to
332.Fn asl_log
333except that it takes a va_list argument.
334.Pp
335.Fo asl_send
336.Fa asl
337.Fa msg
338.Fc
339is similar to
340.Fn asl_log ,
341exceopt the value for ASL_KEY_MESSAGE is taken from
342.Ar msg
343rather than being constructed using a
344.Fn printf
345style syntax.
346.Pp
347.Fo asl_search
348.Fa asl
349.Fa msg
350.Fc
351searches for messages that match the keys and values in
352.Ar msg ,
353subject to matching operations associated with those keys and values.
354The
355.Ar msg
356argument should be constructed using
357.Fn asl_set_query .
358See the
359.Sx SEARCHING
360section for details on constructing queries.
361Returns an aslresponse structure that contains matching log messages.
362NULL is returned in case of error or if there are no matching messages in the ASL database.
363.Pp
364.Fo aslresponse_next
365.Fa r
366.Fc
367iterates over an aslresponse structure returned by
368.Fn asl_search .
369Each call returns the next aslmsg in the response.
370Returns NULL when there are no further messages.
371.Pp
372.Fo aslresponse_free
373.Fa r
374.Fc
375frees the aslresponse structure
376.Ar r
377and all of its associated resources.
378.Ss MESSAGES
379At the core of this API is the aslmsg structure.
380Although the structure is opaque and may not be directly manipulated,
381it contains a list of key/value pairs.
382All keys and values are NUL-character terminated C language strings.
383UTF-8 encoding may be used for non-ASCII characters.
384.Pp
385Message structures are generally used to send log messages,
386and are created thusly:
387.Pp
388 aslmsg m = asl_new(ASL_TYPE_MSG);
389.Pp
390Another message type, ASL_TYPE_QUERY,
391is used to create queries when searching the data store.
392Query type messages and searching are described in detail in the
393.Sx SEARCHING
394section.
395For the remainder of this section,
396the messages described will be of the ASL_TYPE_MSG variety.
397.Pp
398Each aslmsg contains a default set of keys
399and values that are associated with them.
400These keys are listed in the asl.h header file.
401They are:
402.Pp
403 #define ASL_KEY_TIME "Time"
404 #define ASL_KEY_HOST "Host"
405 #define ASL_KEY_SENDER "Sender"
406 #define ASL_KEY_FACILITY "Facility"
407 #define ASL_KEY_PID "PID"
408 #define ASL_KEY_UID "UID"
409 #define ASL_KEY_GID "GID"
410 #define ASL_KEY_LEVEL "Level"
411 #define ASL_KEY_MSG "Message"
412.Pp
413Many of these correspond to equivalent parts of messages described in the
414.Xr syslog 3
415API.
416Values associated with these message keys are assigned appropriate defaults.
417The value for ASL_KEY_HOST is the local host name,
418the value associated with ASL_KEY_SENDER is the process name,
419the ASL_KEY_PID is the client's process ID number, and so on.
420.Pp
421Note the addition of the UID and GID keys.
422The values for UID and GID are set in library code by the message sender.
423The server will attempt to confirm the values,
424but no claim is made that these values cannot be maliciously overridden
425in an attempt to deceive a log message reader
426as to the identity of the sender of a message.
427The contents of log messages must be regarded as insecure.
428.Pp
429The
430.Xr asl 3
431API does not require a process to choose a facility name.
432The
433.Nm syslogd
434server will use a default value of
435.Dq user
436if a facility is not set.
437However, a client may set a facility name as an argument in the
438.Nm asl_open
439call, or by setting a specific value for the ASL_KEY_FACILITY in a message:
440.Pp
441 asl_set(m, ASL_KEY_FACILITY, "com.somename.greatservice");
442.Pp
443An application may choose any facility name at will.
444Different facility names may be attached to different messages, perhaps to distinguish different subsystems in log messages.
445Developers are encouraged to adopt a
446.Dq Reverse ICANN
447naming convention to avoid conflicting facility names.
448.Pp
449Default values are set in the message for each of the keys listed above,
450except for ASL_KEY_MSG,
451which may be explicitly set at any time using the
452.Nm asl_set
453routine, or implicitly set at the time the message is sent using the
454.Nm asl_log
455or
456.Nm asl_vlog
457routines.
458These two routines also have an integer-level parameter
459for specifying the log priority.
460The ASL_KEY_LEVEL value is set accordingly.
461Finally, the value associated with ASL_KEY_TIME
462is set in the sending routine.
463.Pp
464Although it may appear that there is significant overhead required
465to send a log message using this API,
466the opposite is actually true.
467A simple
468.Dq Hello World
469program requires only:
470.Pp
471 #include <asl.h>
472 ...
473 asl_log(NULL, NULL, ASL_LEVEL_INFO, "Hello World!");
474.Pp
475Both
476.Nm asl_log
477and
478.Nm asl_vlog
479will provide the appropriate default values
480when passed a NULL aslmsg argument.
481.Pp
482.Pp
483In this example, the aslclient argument is NULL.
484This is sufficient for a single-threaded application,
485or for an application which only sends log messages from a single thread.
486When logging from multiple threads,
487each thread
488.Em should
489open a separate client handle using
490.Nm asl_open .
491The client handle may then be closed when it is no longer required using
492.Nm asl_close .
493Multiple threads may log messages safely using a NULL aslclient argument,
494but the library will use an internal lock, so that in fact only one thread
495will log at a time.
496.Pp
497When an application requires additional keys and values
498to be associated with each log message,
499a single message structure may be allocated and set up as
500.Dq template
501message of sorts:
502.Pp
503 aslmsg m = asl_new(ASL_TYPE_MSG);
504 asl_set(m, ASL_KEY_FACILITY, "com.secrets.r.us");
505 asl_set(m, "Clearance", "Top Secret");
506 ...
507 asl_log(NULL, m, ASL_LEVEL_NOTICE, "Message One");
508 ...
509 asl_log(NULL, m, ASL_LEVEL_ERR, "Message Two");
510.Pp
511The message structure will carry the values set for the
512.Dq Facility
513and
514.Dq Clearance
515keys so that they are used in each call to
516.Nm asl_log ,
517while the log level and the message text
518are taken from the calling parameters.
519.Pp
520The
521.Ar format
522argument to
523.Nm asl_log
524and
525.Nm asl_vlog
526is identical to
527.Xr printf 3 ,
528and may include
529.Ql %m ,
530which is replaced by the current error message
531(as denoted by the global variable
532.Va errno ;
533see
534.Xr strerror 3 . )
535.Pp
536Key/value pairs may be removed from a message structure with
537.Nm asl_unset .
538A message may be freed using
539.Nm asl_free .
540.Pp
541The
542.Nm asl_send
543routine is used by
544.Nm asl_log
545and
546.Nm asl_vlog
547to transmit a message to the server.
548This routine sets the value associated with ASL_KEY_TIME
549and sends the message.
550It may be called directly if all of a message's key/value pairs
551have been created using
552.Nm asl_set .
553.Ss SECURITY
554Messages that are sent to the
555.Nm syslogd
556server may be saved in a message store.
557The store may be searched using
558.Nm asl_search ,
559as described below.
560By default, all messages are readable by any user.
561However, some applications may wish to restrict read access
562for some messages.
563To accomodate this,
564a client may set a value for the "ReadUID" and "ReadGID" keys.
565These keys may be associated with a value
566containing an ASCII representation of a numeric UID or GID.
567Only the root user (UID 0),
568the user with the given UID,
569or a member of the group with the given GID
570may fetch access-controlled messages from the database.
571.Pp
572Although the ASL system does not require a "Facility" key in a message,
573many processes specify a "Facility" value similar
574to the common usage of the BSD
575.Nm syslog
576API, although developers are encouraged to adopt facility names that make sense for their application.
577A
578.Dq Reverse ICANN
579naming convention (e.g. "com.apple.system.syslog") should be adopted to avoid conflicting names.
580The ASL system generally allows any string to be used as a facility value,
581with one exception.
582The value "com.apple.system",
583or any string that has "com.apple.system" as a prefix,
584may only be used by processes running with the UID 0.
585This allows system processes to log messages that can not be "spoofed" by user processes.
586Non-UID 0 client processes that specify "com.apple.system" as a facility, will be assigned the value "user"
587by the
588.Nm syslogd
589server.
590.Ss CLIENT HANDLES
591When logging is done from a single thread,
592a NULL value may be used in any of the routines
593that require an aslclient argument.
594In this case, the library will open an internal client handle
595on behalf of the application.
596.Pp
597If multiple threads must do logging,
598or if client options are desired,
599then the application should call
600.Nm asl_open
601to create a client handle for each thread.
602As a convenience,
603the
604.Nm asl_open
605routine may be given an ident argument,
606which becomes the default value for the ASL_KEY_SENDER key,
607and a facility argument,
608which becomes the value associated with the ASL_KEY_FACILITY key.
609.Pp
610Several options are available when creating a client handle.
611They are:
612.Pp
613.Bl -tag -width "ASL_OPT_NO_REMOTE" -compact
614.It ASL_OPT_STDERR
615adds stderr as an output file descriptor
616.It ASL_OPT_NO_DELAY
617connects to the server immediately
618.It ASL_OPT_NO_REMOTE
619disables remote-control filter adjustment
620.El
621.Pp
622ASL_OPT_NO_DELAY makes the client library connect to the
623.Nm syslogd
624server at the time that
625.Nm asl_open
626is called, rather than waiting for the first message to be sent.
627Opening the connection is quite fast, but some applications may want to avoid any unnecessary delays when calling
628.Nm asl_log ,
629.Nm asl_vlog ,
630or
631.Nm asl_send .
632.Pp
633See the FILTERING section below, and the
634.Xr syslog 1
635for additional details on filter controls.
636.Pp
637A client handle is closed and it's resources released using
638.Nm asl_close .
639Note that if additional file descriptors were added to the handle,
640either using the ASL_OPT_STDERR option
641or afterwards with the
642.Nm asl_add_log_file
643routine, those file descriptors are not closed by
644.Nm asl_close .
645.Ss LOGGING TO ADDITIONAL FILES
646If a client handle is opened with the ASL_OPT_STDERR option to
647.Nm asl_open ,
648a copy of each log message will be sent to stderr.
649Additional output streams may be include using
650.Nm asl_add_log_file .
651.Pp
652Messages sent to stderr or other files are printed in the "standard" message format
653also used as a default format by the
654.Xr syslog 1
655command line utility.
656Non-ASCII characters in a message are encoded using the
657.Dq safe
658encoding style used by
659.Xr syslog 1
660with the
661.Fl E Ar safe
662option.
663Backspace characters are printed as ^H.
664Carriage returns are mapped to newlines.
665A tab character is appended after newlines so that message text is indented.
666.Pp
667File descriptors may be removed from the list of outputs associated
668with a client handle with
669.Nm asl_remove_log_file .
670This routine simply removes the file descriptor from the output list.
671The file is not closed as a result.
672.Pp
673The ASL_OPT_STDERR option may not be unset
674after a client handle has been opened.
675.Ss SEARCHING
676The
677.Nm syslogd
678server archives received messages in a data store
679that may be searched using the
680.Nm asl_search ,
681.Nm aslresponse_next ,
682and
683.Nm aslresponse_free
684routines.
685A query message is created using:
686.Pp
687 aslmsg q = asl_new(ASL_TYPE_QUERY);
688.Pp
689Search settings are made in the query using
690.Nm asl_set_query .
691A search is performed on the data store with
692.Nm asl_search .
693It returns an
694.Ft aslresponse
695structure.
696The caller may then call
697.Nm aslresponse_next
698to iterate through matching messages.
699The
700.Ft aslresponse
701structure may be freed with
702.Nm aslresponse_free .
703.Pp
704Like other messages, ASL_TYPE_QUERY messages contain keys and values.
705They also associate an operation with each key and value.
706The operation is used to decide if a message matches the query.
707The simplest operation is ASL_QUERY_OP_EQUAL, which tests for equality.
708For example, the following code snippet searches for messages
709with a Sender value equal to
710.Dq MyApp .
711.Pp
712 aslmsg m;
713 aslresponse r;
714 q = asl_new(ASL_TYPE_QUERY);
715 asl_set_query(q, ASL_KEY_SENDER, "MyApp", ASL_QUERY_OP_EQUAL);
716 r = asl_search(NULL, q);
717.Pp
718More complex searches may be performed using other query operations.
719.Pp
720.Bl -tag -width "ASL_QUERY_OP_GREATER_EQUAL" -compact
721.It ASL_QUERY_OP_EQUAL
722value equality
723.It ASL_QUERY_OP_GREATER
724value greater than
725.It ASL_QUERY_OP_GREATER_EQUAL
726value greater than or equal to
727.It ASL_QUERY_OP_LESS
728value less than
729.It ASL_QUERY_OP_LESS_EQUAL
730value less than or equal to
731.It ASL_QUERY_OP_NOT_EQUAL
732value not equal
733.It ASL_QUERY_OP_REGEX
734regular expression search
735.It ASL_QUERY_OP_TRUE
736always true - use to test for the existence of a key
737.El
738.Pp
739Regular expression search uses
740.Xr regex 3
741library.
742Patterns are compiled using the REG_EXTENDED and REG_NOSUB options.
743.Pp
744Modifiers that change the behavior of these operations
745may also be specified by ORing the modifier value with the operation.
746The modifiers are:
747.Pp
748.Bl -tag -width "ASL_QUERY_OP_SUBSTRING" -compact
749.It ASL_QUERY_OP_CASEFOLD
750string comparisons are case-folded
751.It ASL_QUERY_OP_PREFIX
752match a leading substring
753.It ASL_QUERY_OP_SUFFIX
754match a trailing substring
755.It ASL_QUERY_OP_SUBSTRING
756match any substring
757.It ASL_QUERY_OP_NUMERIC
758values are converted to integer using
759.Nm atoi
760.El
761.Pp
762The only modifier that is checked
763for ASL_QUERY_OP_REGEX search is ASL_QUERY_OP_CASEFOLD.
764This causes the regular expression to be compiled
765with the REG_ICASE option.
766.Pp
767If a query message contains more than one set of key/value/operation triples,
768the result will be a logical AND. For example, to find messages from
769.Dq MyApp
770with a priority level less than or equal to
771.Dq 3 :
772.Pp
773 aslmsg q;
774 aslresponse r;
775 q = asl_new(ASL_TYPE_QUERY);
776 asl_set_query(q, ASL_KEY_SENDER, "MyApp", ASL_QUERY_OP_EQUAL);
777 asl_set_query(q, ASL_KEY_LEVEL, "3",
778 ASL_QUERY_OP_LESS_EQUAL | ASL_QUERY_OP_NUMERIC);
779 r = asl_search(NULL, q);
780.Pp
781After calling
782.Nm asl_search
783to get an
784.Ft aslresponse
785structure, use
786.Nm aslresponse_next
787to iterate through all matching messages.
788To iterate through the keys and values in a message, use
789.Nm asl_key
790to iterate through the keys, then call
791.Nm asl_get
792to get the value associated with each key.
793.Pp
794 aslmsg q, m;
795 int i;
796 const char *key, *val;
797.Pp
798 ...
799 r = asl_search(NULL, q);
800 while (NULL != (m = aslresponse_next(r)))
801 {
802 for (i = 0; (NULL != (key = asl_key(m, i))); i++)
803 {
804 val = asl_get(m, key);
805 ...
806 }
807 }
808 aslresponse_free(r);
809.Pp
810.Ss FILTERING AND REMOTE CONTROL
811Clients may set a filter mask value with
812.Nm asl_set_filter .
813The mask specifies which messages should be sent to the
814.Nm syslogd
815daemon by specifying a yes/no setting for each priority level.
816Clients typically set a filter mask
817to avoid sending relatively unimportant messages.
818For example, Debug or Info priority level messages
819are generally only useful for debugging operations.
820By setting a filter mask, a process can improve performance
821by avoiding sending messages that are in most cases unnecessary.
822.Pp
823.Nm asl_set_filter returns the previous value of the filter, i.e. the value of the filter before the routine was called.
824.Pp
825As a convenience, the macros ASL_FILTER_MASK(level) and ASL_FILTER_MASK_UPTO(level)
826may be used to construct a bit mask corresponding to a given priority level,
827or corresponding to a bit mask for all priority levels
828from ASL_LEVEL_EMERG to a given input level.
829.Pp
830The default filter mask is ASL_FILTER_MASK_UPTO(ASL_LEVEL_NOTICE).
831This means that by default,
832and in the absence of remote-control changes (described below),
833ASL_LEVEL_DEBUG and ASL_LEVEL_INFO priority level messages
834are not sent to the
835.Mn syslogd
836server.
837.Pp
838Three different filters exist for each application.
839The first is the filter mask set using
840.Nm asl_set_filter
841as described above.
842The Apple System Log facility also manages a
843.Dq master
844filter mask.
845The master filter mask usually has a value
846that indicates to the library that it is
847.Dq off ,
848and thus it has no effect.
849However, the mask filter mask may be enabled
850by giving it a value using the
851.Nm syslog
852command, using the
853.Fl c
8540 option.
855When the master filter mask has been set,
856it takes precedence over the client's filter mask.
857The client's mask is unmodified,
858and will become active again if remote-control filtering is disabled.
859.Pp
860In addition to the master filter mask,
861The Apple System Log facility
862also manages a per-client remote-control filter mask.
863Like the master filter mask, the per-client mask is usually
864.Dq off ,
865having no effect on a client.
866If a per-client filter mask is set using the
867.Nm syslog
868command, using the
869.Fl c Ar process
870option, then it takes precedence
871over both the client's filter mask and the master filter mask.
872As is the case with the master filter mask,
873a per-client mask ceases having any effect when if is disabled.
874.Pp
875The ASL_OPT_NO_REMOTE option to
876.Nm asl_open
877causes both the master and per-client remote-control masks
878to be ignored in the library.
879In that case, only the client's own filter mask
880is used to determine which messages are sent to the server.
881This may be useful for Applications that produce log messages
882that should never be filtered, due to security considerations.
883Note that root (administrator) access is required
884to set or change the master filter mask,
885and that only root may change a per-client remote-control filter mask
886for a root (UID 0) process.
887.Pp
888The per-process remote control filter value is kept as a state value
889associated with a key managed by
890.Nm notifyd .
891The key is protected by an access control mechanism that only permits the
892filter value to be accessed and modified by the same effective UID as the
893ASL client at the time that the first ASL connection was created.
894Remote filter control using
895.Nm syslog Fl c
896will fail for processes that change effective UID after starting an ASL connection.
897Those processes should close all ASL client handles and then re-open ASL connections
898if remote filter control support is desired.
899.Sh HISTORY
900These functions first appeared in
901Mac OS X 10.4.
902.Sh SEE ALSO
903.Xr syslog 1 ,
904.Xr strvis 3 ,
905.Xr syslogd 8