]> git.saurik.com Git - apple/syslog.git/blob - libsystem_asl.tproj/man/asl.3
f2fdda03f4f298f5f76a242ded4e1f1f7e0d8055
[apple/syslog.git] / libsystem_asl.tproj / man / asl.3
1 .\" Copyright (c) 2005-2013 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 October 1, 2011
30 .Dt asl 3
31 .Os "Mac OS X"
32 .Sh NAME
33 .Nm asl_add_log_file ,
34 .Nm asl_add_outout_file ,
35 .Nm asl_append ,
36 .Nm asl_close ,
37 .Nm asl_close_auxiliary_file ,
38 .Nm asl_count ,
39 .Nm asl_create_auxiliary_file ,
40 .Nm asl_decode_buffer ,
41 .Nm asl_encode_buffer ,
42 .Nm asl_fetch_key_val_op ,
43 .Nm asl_format ,
44 .Nm asl_free ,
45 .Nm asl_get ,
46 .Nm asl_get_index ,
47 .Nm asl_get_type ,
48 .Nm asl_key ,
49 .Nm asl_log ,
50 .Nm asl_log_auxiliary_location ,
51 .Nm asl_log_descriptor ,
52 .Nm asl_match ,
53 .Nm asl_new ,
54 .Nm asl_next ,
55 .Nm asl_open ,
56 .Nm asl_open_from_file ,
57 .Nm asl_open_path ,
58 .Nm asl_prepend ,
59 .Nm asl_prev ,
60 .Nm asl_release ,
61 .Nm asl_remove_index ,
62 .Nm asl_remove_log_file ,
63 .Nm asl_reset_iteration ,
64 .Nm asl_retain ,
65 .Nm asl_search ,
66 .Nm asl_send ,
67 .Nm asl_set ,
68 .Nm asl_set_filter ,
69 .Nm asl_set_output_file_filter ,
70 .Nm asl_set_query ,
71 .Nm asl_unset ,
72 .Nm asl_vlog ,
73 .Nm aslresponse_free ,
74 .Nm aslresponse_next
75 .Nd system log message sending and searching functions
76 .Sh SYNOPSIS
77 .Fd #include <asl.h>
78 .\"
79 .Ft int
80 .Fo asl_add_log_file
81 .Fa "asl_object_t client"
82 .Fa "int descriptor"
83 .Fc
84 .Ft int
85 .Fo asl_add_output_file
86 .Fa "asl_object_t client"
87 .Fa "int descriptor"
88 .Fa "const char *msg_fmt"
89 .Fa "const char *time_fmt"
90 .Fa "int filter"
91 .Fa "int text_encoding"
92 .Fc
93 .Ft void
94 .Fo asl_append
95 .Fa "asl_object_t obj"
96 .Fa "asl_object_t msg"
97 .Fc
98 .Pp
99 .Ft void
100 .Fo asl_close
101 .Fa "asl_object_t obj"
102 .Fc
103 .Ft int
104 .Fo asl_close_auxiliary_file
105 .Fa "int descriptor"
106 .Fc
107 .Ft size_t
108 .Fo asl_count
109 .Fa "asl_object_t obj"
110 .Fc
111 .Ft int
112 .Fo asl_create_auxiliary_file
113 .Fa "asl_object_t msg"
114 .Fa "const char *title"
115 .Fa "const char *uti"
116 .Fa "int *out_descriptor"
117 .Fc
118 .Ft int
119 .Fo asl_decode_buffer
120 .Fa "const char *in"
121 .Fa "char **buf"
122 .Fa "size_t *len"
123 .Fc
124 .Ft char *
125 .Fo asl_encode_buffer
126 .Fa "const char *in"
127 .Fa "size_t len"
128 .Fc
129 .Ft int
130 .Fo asl_fetch_key_val_op
131 .Fa "asl_object_t msg"
132 .Fa "uint32_t n"
133 .Fa "const char **key"
134 .Fa "const char **val"
135 .Fa "uint32_t *op"
136 .Fc
137 .Ft char *
138 .Fo asl_format
139 .Fa "asl_object_t msg"
140 .Fa "const char *msg_fmt"
141 .Fa "const char *time_fmt"
142 .Fa "uint32_t text_encoding"
143 .Fc
144 .Ft [DEPRECATED] void
145 .Fo asl_free
146 .Fa "asl_object_t obj"
147 .Fc
148 .Ft const char *
149 .Fo asl_get
150 .Fa "asl_object_t msg"
151 .Fa "const char *key"
152 .Fc
153 .Ft asl_object_t
154 .Fo asl_get_index
155 .Fa "asl_object_t list"
156 .Fa "size_t index"
157 .Fc
158 .Ft uint32_t
159 .Fo asl_get_type
160 .Fa "asl_object_t obj"
161 .Fc
162 .Ft const char *
163 .Fo asl_key
164 .Fa "asl_object_t msg"
165 .Fa "uint32_t n"
166 .Fc
167 .Ft int
168 .Fo asl_log
169 .Fa "asl_object_t obj"
170 .Fa "asl_object_t msg"
171 .Fa "int level"
172 .Fa "const char *format"
173 .Fa "..."
174 .Fc
175 .Ft int
176 .Fo asl_log_auxiliary_location
177 .Fa "asl_object_t msg"
178 .Fa "const char *title"
179 .Fa "const char *uti"
180 .Fa "const char *url"
181 .Fc
182 .Ft int
183 .Fo asl_log_descriptor
184 .Fa "asl_object_t client"
185 .Fa "asl_object_t msg"
186 .Fa "int level"
187 .Fa "int descriptor"
188 .Fa "uint32_t fd_type"
189 .Fc
190 .Ft int
191 .Fo asl_log_message
192 .Fa "int level"
193 .Fa "const char *format"
194 .Fa "..."
195 .Fc
196 .Ft asl_object_t
197 .Fo asl_match
198 .Fa "asl_object_t obj"
199 .Fa "asl_object_t querylist"
200 .Fa "size_t *last"
201 .Fa "size_t start"
202 .Fa "size_t count"
203 .Fa "uint32_t duration"
204 .Fa "int32_t direction"
205 .Fc
206 .Ft asl_object_t
207 .Fo asl_new
208 .Fa "uint32_t type"
209 .Fc
210 .Ft asl_object_t
211 .Fo asl_next
212 .Fa "asl_object_t obj"
213 .Fc
214 .Ft asl_object_t
215 .Fo asl_open
216 .Fa "const char *ident"
217 .Fa "const char *facility"
218 .Fa "uint32_t opts"
219 .Fc
220 .Ft asl_object_t
221 .Fo asl_open_from_file
222 .Fa "int descriptor"
223 .Fa "const char *ident"
224 .Fa "const char *facility"
225 .Fc
226 .Ft asl_object_t
227 .Fo asl_open_path
228 .Fa "const char *path"
229 .Fa "uint32_t opts"
230 .Fc
231 .Ft void
232 .Fo asl_prepend
233 .Fa "asl_object_t obj"
234 .Fa "asl_object_t msg"
235 .Fc
236 .Ft asl_object_t
237 .Fo asl_prev
238 .Fa "asl_object_t obj"
239 .Fc
240 .Ft void
241 .Fo asl_release
242 .Fa "asl_object_t obj"
243 .Fc
244 .Ft void
245 .Fo asl_remove_index
246 .Fa "asl_object_t list"
247 .Fa "size_t index"
248 .Fc
249 .Ft int
250 .Fo asl_remove_log_file
251 .Fa "asl_object_t asl"
252 .Fa "int descriptor"
253 .Fc
254 .Ft void
255 .Fo asl_reset_iteration
256 .Fa "asl_object_t obj"
257 .Fa "size_t position"
258 .Fc
259 .Ft asl_object_t
260 .Fo asl_retain
261 .Fa "asl_object_t obj"
262 .Fc
263 .Ft asl_object_t
264 .Fo asl_search
265 .Fa "asl_object_t obj"
266 .Fa "asl_object_t query"
267 .Fc
268 .Ft int
269 .Fo asl_send
270 .Fa "asl_object_t obj"
271 .Fa "asl_object_t msg"
272 .Fc
273 .Ft int
274 .Fo asl_set
275 .Fa "asl_object_t msg"
276 .Fa "const char *key"
277 .Fa "const char *value"
278 .Fc
279 .Ft int
280 .Fo asl_set_filter
281 .Fa "asl_object_t asl"
282 .Fa "int filter"
283 .Fc
284 .Ft int
285 .Fo asl_set_output_file_filter
286 .Fa "asl_object_t asl"
287 .Fa "int descriptor"
288 .Fa "int filter"
289 .Fc
290 .Ft int
291 .Fo asl_set_query
292 .Fa "asl_object_t msg"
293 .Fa "const char *key"
294 .Fa "const char *value"
295 .Fa "uint32_t op"
296 .Fc
297 .Ft int
298 .Fo asl_unset
299 .Fa "asl_object_t msg"
300 .Fa "const char *key"
301 .Fc
302 .Ft int
303 .Fo asl_vlog
304 .Fa "asl_object_t obj"
305 .Fa "asl_object_t msg"
306 .Fa "int level"
307 .Fa "const char *format"
308 .Fa "va_list ap"
309 .Fc
310 .Ft [DEPRECATED] void
311 .Fo aslresponse_free
312 .Fa "asl_object_t obj"
313 .Fc
314 .Ft [DEPRECATED] asl_object_t
315 .Fo aslresponse_next
316 .Fa "asl_object_t obj"
317 .Fc
318 .Sh DESCRIPTION
319 These routines provide an interface to the Apple System Log facility and to various
320 data bearing memory objects, files, and storage directories.
321 .Pp
322 The API allows client applications to create and manipulate
323 flexible, structured messages, send them to the
324 .Nm syslogd
325 server, where they may undergo additional processing.
326 Messages received by the server are saved in a data store
327 (subject to input filtering constraints).
328 .Pp
329 Log messages may also be written directly to the filesystem from the ASL library.
330 This output may go to plain text files, to ASL-format data files, or to ASL databases.
331 .Pp
332 This API permits clients to create queries
333 and search the system ASL database, ASL-format files, or other ASL databases for matching messages.
334 .Pp
335 Clients that simply need to send messages to the ASL server may do so using
336 .Fn asl_log_message .
337 Other routines allow for more complex logging tasks.
338 .Pp
339 An introduction to the concepts underlying this interface follows the interface summary below.
340 .Ss INTERFACE SUMMARY
341 .Fo asl_log_message
342 .Fa level
343 .Fa format
344 .Fa "..."
345 .Fc
346 sends a message to the ASL server
347 .Nm syslogd .
348 .Fa level
349 is an integer between 7 (ASL_LEVEL_DEBUG) and 0 (ASL_LEVEL_EMERG),
350 indicating the priority of the message.
351 Note that message priority levels are used as the basis of filtering
352 messages in several places in the ASL system.
353 In general, messages with level ASL_LEVEL_DEBUG and ASL_LEVEL_INFO are often excluded from long-term storage,
354 or have shorter time-to-live durations.
355 .Pp
356 .Fa format
357 is a printf-like format string.
358 In addition to the conversion specifications supported by
359 .Nm printf ,
360 .Fn asl_log_message
361 supports the
362 .Dq %m
363 conversion, which is converted to the current error string returned by the
364 .Nm strerror
365 function for the current value of
366 .Fa errno .
367 .Pp
368 .Fn asl_log_message
369 is a simplified version of the
370 .Fn asl_log
371 interface.
372 It uses the default (NULL) ASL client handle.
373 This interface is thread-safe, although callers will contend for a mutex lock when using this routine.
374 Applications that log from multiple threads or dispatch queues may experience undesired performance
375 characteristics when using this routine.
376 The use of
377 .Fn asl_open
378 and
379 .Fn asl_log ,
380 .Fn asl_vlog ,
381 or
382 .Fn asl_send
383 is advised for applications that log from multiple threads.
384 .Pp
385 .Fo asl_log
386 .Fa obj
387 .Fa msg
388 .Fa level
389 .Fa format
390 .Fa "..."
391 .Fc
392 prepares a message, normally to be sent to the ASL server
393 .Nm syslogd .
394 The first parameter,
395 .Fa obj ,
396 may be an asl_object_t of any type.
397 It is typically of type ASL_TYPE_CLIENT.
398 In this case the settings and options associated with the ASL client handle
399 .Fa obj
400 are used when preparing the message.
401 The client may direct the ASL library to
402 print copies of the message to various output files as well as sending it to the ASL server.
403 Filter settings in the client may further direct the library in selecting where the message
404 will be sent, and may in fact prevent the message from being sent to the ASL server at all.
405 ASL client handles are created using
406 .Fn asl_open
407 and are described extensively below.
408 .Pp
409 ASL message are dictionaries.
410 The
411 .Fn asl_log
412 routine combines information carried in the ASL client handle
413 .Fa client
414 and the ASL message dictionary
415 .Fa msg ,
416 together with the
417 .Fa format
418 string and the associated arguments to construct a final message to be sent
419 to the ASL server and/or to be written to output files.
420 In general, the ASL client handle will provide the values for the
421 ASL_KEY_SENDER and ASL_KEY_FACILITY keys.
422 If
423 .Fa msg
424 is non-NULL, it may override the values for ASL_KEY_SENDER and ASL_KEY_FACILITY,
425 and it may supply additional key/value pairs.
426 The
427 .Fa format
428 string and it's associated arguments are used to construct a string value for the
429 ASL_KEY_MSG key in the final log message dictionary.
430 .Pp
431 If the
432 .Fa obj
433 parameter is of a type other than ASL_TYPE_CLIENT, then
434 .Fn asl_log
435 creates a message as if it were to be sent to
436 .Nm syslogd ,
437 but rather than sending the message, it stores the message in the
438 .Fa obj
439 provided.
440 If
441 .Fa obj
442 is of type ASL_TYPE_FILE or ASL_TYPE_STORE that has been opened for writing,
443 then the message is saved to the file or ASL data store.
444 If
445 .Fa obj
446 is of type ASL_TYPE_LIST, then the message is appended to the list.
447 If
448 .Fa obj
449 is of type ASL_TYPE_MSG, then the message key/value pairs constructed by
450 .Fn asl_log
451 are merged with
452 .Fa obj .
453 In a merge operation, existing keys and values in
454 .Fa obj
455 are preserved.
456 New values in the
457 .Fn asl_log
458 message are attached.
459 Although this routine works for type ASL_TYPE_QUERY,
460 new key/value pairs are attached with an operation value of zero.
461 .Pp
462 The ASL_PREFILTER_LOG(obj, msg, level, format, ...) macro may be used in
463 place of
464 .Fn asl_log
465 when
466 .Fa obj
467 is of type ASL_TYPE_CLIENT.
468 The macro avoids processing the variable argument list in those cases where
469 the message would be filtered out due to filter settings, would not be
470 written to a log file associated with the asl_object_t, or would not be
471 written to stderr.
472 The macro may provide a performance benefit for some applications.
473 Details on filter setting, additional log files, and asl_object_t options
474 are described below in this manual.
475 .Pp
476 .Fo asl_vlog
477 .Fa obj
478 .Fa msg
479 .Fa level
480 .Fa format
481 .Fa ap
482 .Fc
483 is similar to
484 .Fn asl_log
485 except that it takes a va_list argument.
486 .Pp
487 .Fo asl_send
488 .Fa obj
489 .Fa msg
490 .Fc
491 is similar to
492 .Fn asl_log ,
493 except the value for ASL_KEY_MESSAGE is taken from
494 .Ar msg
495 rather than being constructed using a
496 .Fn printf
497 style syntax.
498 .Pp
499 .Fo asl_open
500 .Fa ident
501 .Fa facility
502 .Fa opts
503 .Fc
504 creates and returns a client handle, or NULL if an error occurs in the library.
505 Messages sent using this handle will default to having the string
506 .Ar ident
507 as the value associated with the ASL_KEY_SENDER key, and the value
508 .Ar facility
509 associated with the ASL_KEY_FACILITY key.
510 If
511 .Ar ident
512 is NULL, the library uses the sending process name.
513 If
514 .Ar facility
515 is NULL, the library will use the
516 .Dq user
517 facility for processes with non-zero UID, and
518 .Dq daemon
519 for processes with zero UID.
520 .Pp
521 Several options are available, as described in the
522 .Sx CLIENT HANDLES
523 section.
524 .Pp
525 Each client handle holds state information that is used when a message is logged using that handle.
526 This information includes the
527 .Ar ident
528 and
529 .Ar facility
530 strings and the options from the
531 .Ar opts
532 parameter.
533 Client handles also contain various filter, file descriptor, and control data.
534 .Pp
535 The state information in a client handle is not protected by locking or thread synchronization mechanisms,
536 except for one special case where NULL is used as a client handle.
537 That special case is described below.
538 .Pp
539 It is not safe for two or more threads to use a single client handle simultaneously.
540 Multi-threaded applications should generally create one client handle for each thread
541 or serial dispatch queue that logs messages.
542 A client handle may only be safely shared amongst multiple threads if the application uses locks or some
543 synchronization strategy to ensure single-threaded access.
544 .Pp
545 As a special case, the ASL library allows the use of NULL in place of a client handle.
546 In this case, the library uses an internal structure which contains its own lock.
547 Multiple threads may safely use NULL in place of an ASL client handle,
548 although there may be contention for the lock.
549 .Pp
550 Applications that use libdispatch may use NULL in place of a client handle,
551 although this may cause undesirable synchronization behavior and degraded performance because of lock contention.
552 A better design is often to use one or more serial dispatch queues specifically for logging.
553 Each such serial queue should use a separate client handle.
554 .Pp
555 .Fo asl_open_path
556 .Fa path
557 .Fa opts
558 .Fc
559 opens an ASL data store or ASL data file for read or write access.
560 Returns an object of type ASL_TYPE_STORE or ASL_TYPE_FILE,
561 depending on the input parameters.
562 By default, the ASL store or file is opened for reading.
563 The routine checks the filesystem type of
564 .Fa path ,
565 and returns an object of type ASL_TYPE_STORE for an ASL data store (a directory in the filesystem)
566 or an object of type ASL_TYPE_FILE for an ASL data file.
567 If
568 .Fa path
569 is NULL, the system's ASL database (/var/log/asl) is opened.
570 .Pp
571 If the ASL_OPT_OPEN_WRITE option is specified, an existing file or database is
572 opened for writing.
573 New messages may be added to the file or database using
574 .Fn asl_log ,
575 .Fn asl_vlog ,
576 .Fn asl_send ,
577 or
578 .Fn asl_append .
579 Existing messages in the store or file may not be deleted or modified.
580 .Pp
581 If the path does not exist in the filesystem,
582 .Fn asl_open_path
583 will create a new data store if ASL_OPT_CREATE_STORE is set in the options,
584 The file will be created with the user's effective UID and GID as owner and group.
585 The mode will be 0644.
586 If a different mode, UID, or GID is desired, an empty file or directory may be
587 pre-created with the desired settings.
588 .Pp
589 .Fo asl_close
590 .Fa asl
591 .Fc
592 closes the client handle
593 .Ar asl
594 and releases its associated resources.
595 .Fn asl_release
596 may also be used to close a client handle.
597 .Pp
598 .Fo asl_set_filter
599 .Fa asl
600 .Fa f
601 .Fc
602 sets a filter for messages being sent to the server.
603 The filter is a bitmask representing priority levels.
604 Only messages having a priority level with a corresponding bit set in the filter mask are sent to the
605 .Nm syslogd
606 server.
607 The filter does not control writes to additional files associated with the client handle using
608 .Fn asl_add_output_file .
609 .Fn asl_set_filter
610 returns the previous filter value.
611 .Pp
612 .Fo asl_add_output_file
613 .Fa asl
614 .Fa descriptor
615 .Fa msg_fmt
616 .Fa time_fmt
617 .Fa filter
618 .Fa text_encoding
619 .Fc
620 adds the file descriptor
621 .Ar descriptor
622 to the a set of file descriptors associated with the client handle
623 .Ar asl .
624 Each log message sent by that client handle is also written to these file descriptors
625 (depending on the setting of the
626 .Ar filter
627 argument).
628 The message format is specified by the
629 .Ar msg_fmt
630 argument.
631 The format for timestamps is specified by the
632 .Ar time_fmt
633 argument, although custom format strings may specify more advanced formats for timestamps.
634 Details on custom format strings are below.
635 .Pp
636 Each output file has an associated
637 .Ar filter
638 value.
639 The filter determines which messages are formatted and written to the file based on the message priority level.
640 .Pp
641 Special handling for certain characters is specified by the
642 .Ar text_encoding
643 argument.
644 The supported values and their effect are described below.
645 .Pp
646 The
647 .Ar msg_format
648 argument is a character string that tells the library how to format each message written to the output file.
649 There are several pre-defined message formats, described below.
650 Custom formats are also supported,
651 giving complete control over which ASL message keys should be written
652 and the overall format of each output line.
653 The pre-defined formats are identified by constants in the asl.h header file.
654 .Pp
655 .Bl -tag -width "ASL_MSG_FMT_RAW" -compact
656 .It ASL_MSG_FMT_RAW
657 The contents of the ASL message dictionaries are formatted as a list,
658 with each key-value pair formatted as
659 .Dq [Key Value] .
660 .Pp
661 .It ASL_MSG_FMT_STD
662 Messages are formatted using the standard ASL message format of the form
663 .Pp
664 .Dl Time Host Sender[PID] <Level>: Message
665 .Pp
666 Time formats are described below.
667 .Pp
668 .It ASL_MSG_FMT_BSD
669 The legacy format used for plain-text log files.
670 Similar to the ASL_MSG_FMT_STD format, but the message priority level is excluded.
671 .Pp
672 .It ASL_MSG_FMT_MSG
673 The output line contains only the value of the Message key in each ASL message dictionary.
674 .Pp
675 .It ASL_MSG_FMT_XML
676 Produces multiple lines of output for each ASL message.
677 The message is formatted as an XML dictionary:
678 .Pp
679 .Dl <dict>
680 .Dl \t<key>ASLMessageKey1</key>
681 .Dl \t<string>Key 1 Value</string>
682 .Dl \t<key>ASLMessageKey2</key>
683 .Dl \t<string>Key 2 Value</string>
684 .Dl \t\t...
685 .Dl </dict>
686 .Pp
687 .El
688 .Pp
689 A NULL value for
690 .Ar msg_fmt
691 causes the library to use the ASL_MSG_FMT_STD format.
692 .Pp
693 Custom format strings may contain a mix of characters that are directly copied to the output line
694 and variables, which are a dollar sign
695 .Sq $
696 followed by specific ASL message dictionary keys, whose values will be interpolated into the output.
697 For example, the format string:
698 .Pp
699 .Dl This message from $Sender PID=$PID at $Time *** $Message
700 .Pp
701 would result in lines in the output file like, e.g.:
702 .Pp
703 .Dl This message from login PID=982 at Jul 27 08:41:27 *** USER_PROCESS: 330 ttys000
704 .Dl This message from Mail PID=987 at Jul 27 08:42:16 *** Using V2 Layout
705 .Pp
706 Normally, a space character terminates a variable name.
707 However, the name may be wrapped in parentheses if a space character is not desired in the output.
708 For example:
709 .Pp
710 .Dl $(Sender)[$(PID)]: $Message
711 .Pp
712 A third form for specifying variables may be used for the ASL
713 .Dq Level
714 and
715 .Dq Time
716 message keys.
717 Note that a
718 .Dq Time
719 specification using one of the forms below will override the
720 .Ar time_fmt
721 argument to the function.
722 .Pp
723 The following forms are recognized:
724 .Pp
725 .Bl -tag -width "$((Time)([+|-]HH[:MM]))"
726 .It $((Level)(str))
727 Formats a Level value as a string, for example
728 .Dq Error ,
729 .Dq Alert ,
730 .Dq Warning ,
731 and so on.
732 Note that $(Level) or $Level formats the value as an integer 0 through 7.
733 .It $((Level)(char))
734 Formats a Level value as a single character from the set
735 .Dq PACEWNID ,
736 for levels 0 through 7.
737 These are abbreviations for Panic, Alert, Critical, Error, Warning, Notice, Info, and Debug.
738 .It $((Time)(sec))
739 Formats a Time value as the number of seconds since the Epoch.
740 .It $((Time)(raw))
741 Alias for $((Time)(sec)).
742 .It $((Time)(local))
743 Formats a Time value as a string of the form
744 .Dq "Mmm dd hh:mm:ss" ,
745 where Mmm is the abbreviation for the month, dd is the date (1 - 31) and hh:mm:ss is the time.
746 The local timezone is used.
747 .It $((Time)(lcl))
748 Alias for $((Time)(local)).
749 .It $((Time)(utc))
750 Formats a Time value as a string of the form
751 .Dq "yyyy-mm-dd hh:mm:ssZ" ,
752 using Coordinated Universal Time, or the
753 .Dq Zulu
754 time zone.
755 .It $((Time)(zulu))
756 Alias for $((Time)(utc)).
757 .It $((Time)(X))
758 Where X may be any letter in the range A - Z or a - z.
759 Formats the Time using the format
760 .Dq "yyyy-mm-dd hh:mm:ssX" ,
761 using the specified nautical timezone.
762 Z is the same as UTC/Zulu time. Timezones A - M (except J) decrease by one hour to the east of the
763 Zulu time zone.
764 Timezones N - Y increase by one hour to the west of Z.
765 M and Y have the same clock time, but differ by one day.
766 J is used to indicate the local timezone.
767 When printing using $((Time)(J)), the output format is
768 .Dq "yyyy-mm-dd hh:mm:ss" ,
769 without a trailing timezone letter.
770 .It $((Time)(JZ))
771 Specifies the local timezone.
772 The timezone offset from UTC follows the date and time.
773 The time is formatted as
774 .Dq "yyyy-mm-dd hh:mm:ss[+|-]HH[:MM]" .
775 Minutes in the timezone offset are only printed if they are non-zero.
776 .It $((Time)(ISO8601))
777 Specifies the local timezone, formatted as specified by ISO 8601.
778 The timezone offset from UTC follows the date and time.
779 The time is formatted as
780 .Dq "yyyy-mm-ddThh:mm:ss[+|-]HH[:MM]" .
781 Minutes in the timezone offset are only printed if they are non-zero.
782 Note that this differs from
783 .Dq JZ
784 format only in that a
785 .Dq T
786 character separates the date and time.
787 .It $((Time)([+|-]HH[:MM]))
788 Specifies an offset (+ or -) of the indicated number of hours (HH) and optionally minutes (MM) to UTC.
789 The value is formatted as a string of the form
790 .Dq "yyyy-mm-dd hh:mm:ss[+|-]HH[:MM]" .
791 Minutes in the timezone offset are only printed if they are non-zero.
792 .El
793 .Pp
794 Unless a custom message format uses one of the specialized forms for
795 .Dq Time
796 described above, then any timestamps in an output message will be formatted according the the
797 .Ar time_fmt
798 argument.
799 The known formats are identified by constants in the asl.h header file.
800 .Pp
801 .Bl -tag -width "ASL_TIME_FMT_SEC"
802 .It ASL_TIME_FMT_SEC
803 Formats timestamps as the number of seconds since the Epoch.
804 .Pp
805 .It ASL_TIME_FMT_UTC
806 Formats a Time value as a string of the form
807 .Dq "yyyy-mm-dd hh:mm:ssZ" ,
808 using Coordinated Universal Time, or the
809 .Dq Zulu
810 time zone.
811 .It ASL_TIME_FMT_LCL
812 Formats a Time value as a string of the form
813 .Dq "Mmm dd hh:mm:ss" ,
814 where Mmm is the abbreviation for the month, dd is the date (1 - 31) and hh:mm:ss is the time.
815 The local timezone is used.
816 .El
817 .Pp
818 A value of NULL for the
819 .Ar time_fmt
820 argument will cause the default format ASL_TIME_FMT_LCL to be used.
821 .Pp
822 The
823 .Ar encoding
824 parameter specifies how certain characters are to be treated when preparing a message for output.
825 The known encodings are:
826 .Bl -tag -width "ASL_ENCODE_NONE"
827 .It ASL_ENCODE_NONE
828 No special character encode is done.
829 .Pp
830 .It ASL_ENCODE_ASL
831 Newlines and tabs are also encoded as "\\n" and "\\t" respectively.
832 In
833 .Dq ASL_MSG_FMT_RAW
834 format, space characters embedded in log message keys are encoded as "\\s"
835 and embedded brackets are escaped to print as "\\[" and "\\]".
836 .Pp
837 .It ASL_ENCODE_SAFE
838 Encodes backspace characters as ^H.
839 Carriage returns are mapped to newlines.
840 A tab character is appended after newlines so that message text is indented.
841 .Pp
842 .It ASL_ENCODE_XML
843 This encoding should be used when formatting messages using ASL_MSG_FMT_XML.
844 XML format output requires that keys are valid UTF8 strings.
845 Keys which are not valid UTF8 are ignored, and the associated value is not printed.
846 .Pp
847 Values that contain legal UTF8 are printed as strings.
848 Ampersand, less than, greater than, quotation mark, and apostrophe characters are encoded according to XML conventions.
849 Embedded control characters are encoded as
850 .Dq &#xNN;
851 where NN is the character's hexadecimal value.
852 .Pp
853 Values that do not contain legal UTF8 are encoded in base-64 and printed as data objects.
854 .El
855 .Pp
856 .Fn asl_add_output_file
857 Returns 0 on success, non-zero on failure.
858 .Pp
859 .Pp
860 .Fo asl_add_log_file
861 .Fa asl
862 .Fa descriptor
863 .Fc
864 Is equivalent to
865 .Pp
866 .Dl asl_add_output_file(asl, descriptor, ASL_MSG_FMT_STD, ASL_TIME_FMT_LCL, ASL_FILTER_MASK_UPTO(ASL_LEVEL_DEBUG), ASL_ENCODE_SAFE);
867 .Pp
868 Returns 0 on success, non-zero on failure.
869 .Pp
870 .Fo asl_set_output_file_filter
871 .Fa asl
872 .Fa descriptor
873 .Fa filter
874 .Fc
875 replaces the current filter value associated with a file descriptor that has been added to a client handle.
876 Returns the previous filter value.
877 .Pp
878 .Fo asl_remove_log_file
879 .Fa asl
880 .Fa descriptor
881 .Fc
882 removes a file descriptor from the set of file descriptors associated with a client handle.
883 Returns 0 on success, non-zero on failure.
884 .Pp
885 .Fo asl_format
886 .Fa msg
887 .Fa msg_fmt
888 .Fa time_fmt
889 .Fa text_encoding
890 .Fc
891 formats the
892 .Fa msg
893 object using the message format string, time format string, and text encoding specified.
894 Message formatting is described above for the
895 .Fn asl_add_output_file
896 routine.
897 The caller must free the returned character string.
898 .Pp
899 .Fo asl_new
900 .Fa type
901 .Fc
902 allocates and returns an asl_object_t structure, or NULL in the case of a failure in the library.
903 The
904 .Ar type
905 argument should be ASL_TYPE_MSG, ASL_TYPE_QUERY, or ASL_TYPE_LIST.
906 .Pp
907 .Fo asl_get_type
908 .Fa obj
909 .Fc
910 Returns the type of the object
911 .Fa obj ,
912 or ASL_TYPE_UNDEF if the object is not a recognized type.
913 .Pp
914 .Fo asl_retain
915 .Fa obj
916 .Fc
917 Increments an internal reference count for
918 .Fa obj .
919 ASL objects are created with a reference count of 1.
920 Objects returned by ASL routines should be retained if they are used outside
921 of the immediate scope of the call that returned them.
922 .Pp
923 .Fo asl_release
924 .Fa obj
925 .Fc
926 Decrements the internal reference count for
927 .Fa obj .
928 It frees the object and its associated resources when the reference count becomes zero.
929 .Pp
930 .Em DEPRECATED
931 .Fo asl_free
932 .Fa obj
933 .Fc
934 This interface is deprecated in favor of
935 .Fn asl_release .
936 It is implemented as a call to
937 .Fn asl_release .
938 .Pp
939 .Fo asl_set
940 .Fa msg
941 .Fa key
942 .Fa value
943 .Fc
944 creates a new key and value in an asl_object_t structure, or replaces the value of an existing key.
945 Returns 0 on success, non-zero on failure.
946 .Pp
947 .Fo asl_set_query
948 .Fa msg
949 .Fa key
950 .Fa op
951 .Fa value
952 .Fc
953 is used to construct searches.
954 It is similar to
955 .Fn asl_set ,
956 except that it takes an additional
957 .Ar op
958 (operation) argument.
959 Creates a new (key, op, value) triple in an asl_object_t structure,
960 or replaces the value and operation for an existing key.
961 See the
962 .Sx SEARCHING
963 section for more information.
964 Returns 0 on success, non-zero on failure.
965 .Pp
966 .Fo asl_unset
967 .Fa msg
968 .Fa key
969 .Fc
970 removes a key and its associated value from an asl_object_t structure.
971 Returns 0 on success, non-zero on failure.
972 .Pp
973 .Fo asl_key
974 .Fa msg
975 .Fa n
976 .Fc
977 returns the nth key in an asl_object_t (beginning at zero),
978 allowing an application to iterate through the keys.
979 Returns NULL if
980 .Ar n
981 indexes beyond the number of keys in
982 .Ar msg .
983 .Pp
984 .Fo asl_get
985 .Fa msg
986 .Fa key
987 .Fc
988 returns the value associated with
989 .Ar key
990 in the asl_object_t
991 .Ar msg .
992 Returns NULL if
993 .Ar msg
994 does not contain
995 . Ar key .
996 .Pp
997 .Fo asl_fetch_key_val_op
998 .Fa msg
999 .Fa n
1000 .Fa key
1001 .Fa val
1002 .Fa op
1003 .Fc
1004 Returns, in the
1005 .Fa key ,
1006 .Fa val ,
1007 and
1008 .Fa op
1009 output parameters, the key, value, and operation (for ASL_TYPE_QUERY) at index
1010 .Fa n
1011 in the given object
1012 .Fa msg .
1013 The input
1014 .Fa msg
1015 should be of type ASL_TYPE_MSG or ASL_TYPE_QUERY.
1016 Returns 0 on success, or non-zero otherwise.
1017 Any of the output parameters may be NULL, in which case that parameter value will not
1018 be returned.
1019 .Pp
1020 .Fo asl_count
1021 .Fa obj
1022 .Fc
1023 returns a count of the number of elements contained in
1024 .Fa obj .
1025 For objects of type ASL_TYPE_MSG or ASL_TYPE_QUERY,
1026 this is the number of dictionary keys.
1027 For ASL_TYPE_LIST, it is the number of items in the list.
1028 For ASL_TYPE_FILE, returns the number of messages contained in the file.
1029 Returns zero for ASL_TYPE_STORE and ASL_TYPE_CLIENT.
1030 .Pp
1031 .Fo asl_append
1032 .Fa obj
1033 .Fa msg
1034 .Fc
1035 appends the
1036 .Fa msg
1037 object, which is typically of type ASL_TYPE_MSG or ASL_TYPE_QUERY, to the target
1038 .Fa obj .
1039 The target
1040 .Fa obj
1041 is typically a type that contains a collection of messages,
1042 i.e. ASL_TYPE_LIST, ASL_TYPE_FILE, ASL_TYPE_STORE, or ASL_TYPE_CLIENT
1043 (where the collection is the system ASL database).
1044 .Fn asl_append
1045 appends the
1046 .Fa msg
1047 object to the end of the target
1048 .Fa obj .
1049 .Pp
1050 If
1051 .Fa msg
1052 is of type ASL_TYPE_LIST and
1053 .Fa obj
1054 is of type ASL_TYPE_LIST, ASL_TYPE_FILE, ASL_TYPE_STORE, or ASL_TYPE_CLIENT,
1055 the each message in the
1056 .Fa msg
1057 list is appended in sequence to the the target
1058 .Fa obj .
1059 .Pp
1060 If both
1061 .Fa msg
1062 and
1063 .Fa obj
1064 are of type ASL_TYPE_MSG or ASL_TYPE_QUERY, then the message dictionary from
1065 .Fa msg
1066 is merged with
1067 .Fa obj .
1068 Existing keys in
1069 .Fa obj
1070 are preserved.
1071 For keys that are in
1072 .Fa msg
1073 that are not in
1074 .Fa obj ,
1075 the key and its value and operation are added to
1076 .Fa obj .
1077 .Pp
1078 .Fo asl_prepend
1079 .Fa obj
1080 .Fa msg
1081 .Fc
1082 is similar to
1083 .Fn asl_append ,
1084 except that the
1085 .Fa msg
1086 object is prepended to the target
1087 .Fa obj.
1088 In the case where both parameters are of type ASL_TYPE_MSG or ASL_TYPE_QUERY,
1089 all keys from
1090 .Fa msg
1091 are copied to
1092 .Fa obj .
1093 Existing keys are not preserved.
1094 .Pp
1095 .Fo asl_next
1096 .Fa obj
1097 .Fc
1098 returns the next item in the target
1099 .Fa obj ,
1100 which may be of type ASL_TYPE_LIST, ASL_TYPE_FILE, ASL_TYPE_STORE, or of type ASL_TYPE_CLIENT
1101 in which case the routine fetches messages consecutively from the system ASL database.
1102 Returned objects are of type ASL_TYPE_MSG, or of type ASL_TYPE_QUERY if the target object is a
1103 list containing query objects.
1104 Returns NULL when there are no more objects to return from the target.
1105 .Pp
1106 .Fo asl_prev
1107 .Fa obj
1108 .Fc
1109 is similar to
1110 .Fn asl_next ,
1111 except that it returns objects in reverse order.
1112 Objects that contain messages have an internal index for the
1113 .Dq current
1114 item.
1115 .Fn asl_next
1116 and
1117 .Fn asl_prev
1118 simply return the current item and move the index forward or backward.
1119 The index position can be set using
1120 .Fn asl_reset_iteration .
1121 .Pp
1122 .Fo asl_reset_iteration
1123 .Fa obj
1124 .Fa position
1125 .Fc
1126 sets the current position index used be
1127 .Fn asl_next
1128 and
1129 .Fn asl_prev .
1130 The value of
1131 .Fa position
1132 may be zero to set the position index for
1133 .Fa obj
1134 at the beginning of its contents,
1135 or it may be SIZE_MAX to set the position index for
1136 .Fa obj
1137 at the end of its contents.
1138 For objects of type ASL_TYPE_LIST, the position index is an actual index into the list.
1139 For other message containing objects, the index is an ID number which may not be sequential.
1140 .Pp
1141 .Fo asl_get_index
1142 .Fa list
1143 .Fa index
1144 .Fc
1145 returns the object at position
1146 .Fa index
1147 in the target
1148 .Fa list
1149 object, which must be of type ASL_TYPE_LIST.
1150 Returns NULL if the index is out of range or if
1151 .Fa list
1152 is not a list type.
1153 .Pp
1154 .Fo asl_remove_index
1155 .Fa list
1156 .Fa index
1157 .Fc
1158 removes the object at position
1159 .Fa index
1160 from the target
1161 .Fa list
1162 object, which must be of type ASL_TYPE_LIST.
1163 .Pp
1164 .Fo asl_log_descriptor
1165 .Fa asl
1166 .Fa msg
1167 .Fa level
1168 .Fa descriptor
1169 .Fa fd_type
1170 .Fc
1171 provides functionality to use file descriptors to send logging data to ASL.
1172 .Ar asl
1173 is retained by ASL and must still be closed by the caller by calling
1174 .Fn asl_close
1175 if the caller loses reference to it.
1176 .Ar msg
1177 is copied by ASL and similarly must still be releaser by the caller by calling
1178 .Fn asl_release
1179 if the caller loses reference to it. Any changes made to it after calling
1180 .Fn asl_log_descriptor()
1181 are not applicable to the message used.
1182 .Ar descriptor is treated differently based on the value of
1183 .Ar fd_type .
1184 .Pp
1185 If
1186 .Ar fd_type
1187 is ASL_LOG_DESCRIPTOR_READ, the descriptor must be open for read access. ASL
1188 uses
1189 .Xr dispatch 2
1190 to read from the descriptor as data becomes available. These data are line
1191 buffered and passed to
1192 .Fn asl_log .
1193 When EOF is read, ASL will
1194 .Xr close 2
1195 .Ar descriptor ..
1196 .Pp
1197 If
1198 .Ar fd_type
1199 is ASL_LOG_DESCRIPTOR_WRITE, the descriptor is closed and a new writable
1200 descriptor is created with the same fileno. Any data written to this new
1201 descriptor are line buffered and passed to
1202 .Fn asl_log .
1203 When EOF is sent, no further data are read. The caller is responsible for
1204 closing the new descriptor. One common use for this API is to redirect writes
1205 to stdout or stderr to ASL by passing STDOUT_FILENO or STDERR_FILENO as
1206 .Ar descriptor .
1207 .Pp
1208 .Fo asl_search
1209 .Fa obj
1210 .Fa query
1211 .Fc
1212 searches messages in the
1213 .Fa obj
1214 object for messages that match the keys and values in
1215 .Fa query ,
1216 subject to matching operations associated with those keys and values.
1217 The return returns an object of type ASL_TYPE_LIST containing matching messages,
1218 or NULL if no matches are found.
1219 The
1220 .Ar query
1221 argument should be constructed using
1222 .Fn asl_set_query .
1223 See the
1224 .Sx SEARCHING
1225 section for details on constructing queries.
1226 .Pp
1227 The
1228 .Fa obj
1229 parameter may be any ASL object.
1230 For type ASL_TYPE_CLIENT, the main ASL system database is searched.
1231 If the object type is ASL_TYPE_STORE or ASL_TYPE_FILE,
1232 then the corresponding data store or data file is searched.
1233 For ASL_TYPE_LIST, matches are found in a message list.
1234 If
1235 .Fa obj
1236 is of type ASL_TYPE_MSG and query is of type ASL_TYPE_QUERY,
1237 .Fa obj
1238 is matched against the query,
1239 and a list containing
1240 .Fa obj
1241 is returned if the match succeeds.
1242 If both
1243 .Fa obj
1244 and
1245 .Fa query
1246 are objects of type ASL_TYPE_MSG or both are of type ASL_TYPE_QUERY,
1247 they are tested for exact match.
1248 A list containing
1249 .Fa obj
1250 is returned if the match is exact.
1251 If
1252 .Fa obj
1253 is of type ASL_TYPE_QUERY and
1254 .Fa query
1255 is of type ASL_TYPE_MSG, the routine returns NULL.
1256 .Pp
1257 .Fo asl_match
1258 .Fa obj
1259 .Fa querylist
1260 .Fa last
1261 .Fa start
1262 .Fa count
1263 .Fa duration
1264 .Fa direction
1265 .Fc
1266 is similar to
1267 .Fn asl_search ,
1268 but allows more advanced searching of ASL objects.
1269 The
1270 .Fa obj
1271 parameter may be of any type, as with
1272 .Fn asl_search .
1273 The
1274 .Fa querylist
1275 parameter must be an object of type ASL_TYPE_LIST,
1276 containing zero or more objects of type ASL_TYPE_QUERY.
1277 A NULL
1278 .Fa querylist
1279 or a list containing zero objects matches all messages in the target
1280 .Fa obj.
1281 .Pp
1282 The caller may provide a starting ASL message ID, a direction, and a count.
1283 A
1284 .Fa start
1285 ID value of 0 means that matching should commence at the beginning of the target
1286 .Fa obj .
1287 A value of SIZE_MAX indicates that matching should commence at the end (most recent message)
1288 in the target.
1289 If a non-zero
1290 .Fa count
1291 value is supplied, the routine will return when it has found that many messages,
1292 or it has checked all messages.
1293 If a non-zero
1294 .Fa duration
1295 is supplied, the routine will return after the specified time (in microseconds).
1296 If both
1297 .Fa count
1298 and
1299 .Fa duration
1300 are non-zero, the routine will return when the desired number of items has been matched
1301 or when the specified duration has been exceeded, whichever occurs first.
1302 The search direction may be ASL_MATCH_DIRECTION_FORWARD or ASL_MATCH_DIRECTION_REVERSE.
1303 The routine sets the value of the out parameter
1304 .Fa last
1305 to be an index of the last message checked while matching.
1306 To fetch matching messages in batches (using a small count or duration value), the
1307 .Fa start
1308 value for each iteration should be set to
1309 .Fa last
1310 + 1 if searching forward, or
1311 .Fa last
1312 - 1 for reverse search.
1313 .Pp
1314 .Em DEPRECATED
1315 .Fo aslresponse_next
1316 .Fa r
1317 .Fc
1318 This interface is deprecated in favor of
1319 .Fn asl_next .
1320 It is implemented as a call to
1321 .Fn asl_next .
1322 .Pp
1323 .Em DEPRECATED
1324 .Fo aslresponse_free
1325 .Fa r
1326 .Fc
1327 This interface is deprecated in favor of
1328 .Fn asl_release .
1329 It is implemented as a call to
1330 .Fn asl_release .
1331 .Pp
1332 .Fo asl_create_auxiliary_file
1333 .Fa msg
1334 .Fa title
1335 .Fa uti
1336 .Fa out_descriptor
1337 .Fc
1338 Creates an auxiliary file that may be used by the client to save arbitrary data.
1339 When the file is closed using
1340 .Fo asl_close_auxiliary_file
1341 .Fc ,
1342 .Nm syslogd
1343 will log the specified
1344 .Fa msg
1345 along with the
1346 .Fa title
1347 and the Uniform Type Identifier provided by
1348 .Fa uti .
1349 If a NULL value is supplied for
1350 .Fa uti
1351 the type
1352 .Dq public.data
1353 will be used.
1354 The
1355 .Nm Console
1356 application will display the message with a link to the file.
1357 .Pp
1358 Auxiliary files are saved in the ASL data store.
1359 They are automatically deleted at the same time that the log message expires.
1360 Messages expire in 7 days by default.
1361 A value set for the ASLExpireTime key will override the default.
1362 Read access for the auxiliary file will be the same as read access for
1363 .Fa msg .
1364 By default, messages (and auxiliary files) are world-readable.
1365 Access may be limited by setting values for the ReadUID and ReadGID keys.
1366 .Pp
1367 .Fo asl_close_auxiliary_file
1368 .Fa descriptor
1369 .Fc
1370 closes the file descriptor
1371 .Ar descriptor
1372 previously returned by a call to
1373 .Fn asl_create_auxiliary_file .
1374 .Pp
1375 .Fo asl_log_auxiliary_location
1376 .Fa msg
1377 .Fa title
1378 .Fa uti
1379 .Fa url
1380 .Fc
1381 will log the specified
1382 .Fa msg
1383 along with the
1384 .Fa title ,
1385 the Uniform Type Identifier provided by
1386 .Fa uti ,
1387 and the Uniform Resource Locator provided by
1388 .Fa url .
1389 The
1390 .Nm Console
1391 application will display the message with a link to the file.
1392 This allows a client to save data in an auxiliary file, but unlike
1393 .Fn asl_create_auxiliary_file ,
1394 the life-cycle of this file must be managed by some external system.
1395 The file will not be removed when the corresponding log message expired from the ASL data store.
1396 .Pp
1397 .Fo asl_open_from_file
1398 .Fa descriptor
1399 .Fa facility
1400 .Fa opts
1401 .Fc
1402 creates a client handle for an open file descriptor
1403 .Fa descriptor .
1404 This routine may be used in conjunction with
1405 .Fn asl_create_auxiliary_file
1406 or
1407 .Fn asl_log_auxiliary_location
1408 to save ASL format log messages in an auxiliary file.
1409 The UTI type
1410 .Dq com.apple.asl-file
1411 should be used for ASL format auxiliary files.
1412 .Pp
1413 Files with this format may be read from the command line using
1414 .Nm syslog Fl f Ar file ,
1415 or from the
1416 .Nm Console
1417 utility.
1418 .Pp
1419 The file must be open for read and write access.
1420 The file will be truncated and its existing contents will be lost.
1421 .Fo asl_close
1422 .Fc
1423 must be called to close the client handle when logging to this file is complete.
1424 The file should be closed using
1425 .Fo asl_close_auxiliary_file
1426 .Fc
1427 if it was returned by
1428 .Fo asl_create_auxiliary_file
1429 .Fc ,
1430 or
1431 .Fo close
1432 .Fc
1433 otherwise.
1434 .Pp
1435 The client handle returned by
1436 .Fn asl_open_from_file
1437 contains an internal lock, and may be used safely by multiple threads or from independent dispatch queues.
1438 Note that callers will contend for the internal lock when saving log messages to a file.
1439 .Pp
1440 Note that messages with ReadUID or ReadGID values will simply be saved to the file,
1441 and will not effect read access to either the message or the file itself.
1442 Similarly, messages with ASLExpireTime values will be saved, but will not effect the
1443 life-cycle of either the individual messages or the file.
1444 .Pp
1445 .Fo asl_encode_buffer
1446 .Fa in
1447 .Fa len
1448 .Fc
1449 is a utility routine for encoding arbitrary data buffers.
1450 ASL message dictionary keys and values are nul-terminated C strings.
1451 If an application wishes to include arbitrary data which may contain zero bytes,
1452 the data buffer must first be encoded in a manner that eliminates any embedded zeros.
1453 The
1454 .Fn asl_encode_buffer
1455 routine will encode an arbitrary data buffer at the address
1456 .Fa in
1457 containing
1458 .Fa len
1459 bytes (octets) of data.
1460 The output of the routine is a nul-terminated C string.
1461 The encoded string may be decoded using the companion
1462 .Fn asl_decode_buffer
1463 routine.
1464 .Pp
1465 This utility is used by the ASL server
1466 .Nm syslogd
1467 to encode the value associated with ASL_KEY_AUX_DATA in an ASL_TYPE_MSG object.
1468 An ASL_KEY_AUX_DATA key/value pair is used to hold the data written to a file descriptor
1469 created by
1470 .Fn asl_create_auxiliary_file
1471 on iOS systems, where the ASL database is stored in memory.
1472 .Pp
1473 .Fo asl_decode_buffer
1474 .Fa in
1475 .Fa buf
1476 .Fa len
1477 .Fc
1478 decodes a C string previously created by
1479 .Fn asl_encode_buffer
1480 back into a buffer, possibly containing embedded zero bytes (octets).
1481 The routine allocates memory for the buffer and returns a pointer in an output
1482 .Fa buf
1483 parameter.
1484 The caller is responsible for freeing the buffer.
1485 .Pp
1486 This routine should be used to decode the value associated with an
1487 ASL_KEY_AUX_DATA key in an ASL_TYPE_MSG object.
1488 .Pp
1489 .Ss MESSAGES
1490 At the core of this API is the asl_object_t structure.
1491 Although the structure is opaque and may not be directly manipulated,
1492 it contains a list of key/value pairs.
1493 All keys and values are NUL-character terminated C language strings.
1494 UTF-8 encoding may be used for non-ASCII characters.
1495 .Pp
1496 Message structures are generally used to send log messages,
1497 and are created thusly:
1498 .Pp
1499 asl_object_t m = asl_new(ASL_TYPE_MSG);
1500 .Pp
1501 Another message type, ASL_TYPE_QUERY,
1502 is used to create queries when searching the data store.
1503 Query type messages and searching are described in detail in the
1504 .Sx SEARCHING
1505 section.
1506 For the remainder of this section,
1507 the messages described will be of the ASL_TYPE_MSG variety.
1508 .Pp
1509 Each asl_object_t contains a default set of keys
1510 and values that are associated with them.
1511 These keys are listed in the asl.h header file.
1512 They are:
1513 .Pp
1514 #define ASL_KEY_TIME "Time"
1515 #define ASL_KEY_HOST "Host"
1516 #define ASL_KEY_SENDER "Sender"
1517 #define ASL_KEY_FACILITY "Facility"
1518 #define ASL_KEY_PID "PID"
1519 #define ASL_KEY_UID "UID"
1520 #define ASL_KEY_GID "GID"
1521 #define ASL_KEY_LEVEL "Level"
1522 #define ASL_KEY_MSG "Message"
1523 .Pp
1524 Many of these correspond to equivalent parts of messages described in the
1525 .Xr syslog 3
1526 API.
1527 Values associated with these message keys are assigned appropriate defaults.
1528 The value for ASL_KEY_HOST is the local host name,
1529 the value associated with ASL_KEY_SENDER is the process name,
1530 the ASL_KEY_PID is the client's process ID number, and so on.
1531 .Pp
1532 Note the addition of the UID and GID keys.
1533 The values for UID and GID are set in library code by the message sender.
1534 The server will attempt to confirm the values,
1535 but no claim is made that these values cannot be maliciously overridden
1536 in an attempt to deceive a log message reader
1537 as to the identity of the sender of a message.
1538 The contents of log messages must be regarded as insecure.
1539 .Pp
1540 The
1541 .Xr asl 3
1542 API does not require a process to choose a facility name.
1543 The
1544 .Nm syslogd
1545 server will use a default value of
1546 .Dq user
1547 if a facility is not set.
1548 However, a client may set a facility name as an argument in the
1549 .Fn asl_open
1550 call, or by setting a specific value for the ASL_KEY_FACILITY in a message:
1551 .Pp
1552 asl_set(m, ASL_KEY_FACILITY, "com.somename.greatservice");
1553 .Pp
1554 An application may choose any facility name at will.
1555 Different facility names may be attached to different messages, perhaps to distinguish different subsystems in log messages.
1556 Developers are encouraged to adopt a
1557 .Dq Reverse ICANN
1558 naming convention to avoid conflicting facility names.
1559 .Pp
1560 Default values are set in the message for each of the keys listed above,
1561 except for ASL_KEY_MSG,
1562 which may be explicitly set at any time using the
1563 .Fn asl_set
1564 routine, or implicitly set at the time the message is sent using the
1565 .Fn asl_log_message ,
1566 .Fn asl_log ,
1567 or
1568 .Fn asl_vlog
1569 routines.
1570 These three routines also have an integer-level parameter
1571 for specifying the log priority.
1572 The ASL_KEY_LEVEL value is set accordingly.
1573 Finally, the value associated with ASL_KEY_TIME
1574 is set in the sending routine.
1575 .Pp
1576 When logging from multiple threads,
1577 each thread
1578 .Em should
1579 open a separate client handle using
1580 .Fn asl_open .
1581 The client handle may then be closed when it is no longer required using
1582 .Fn asl_release .
1583 Multiple threads may log messages safely using a NULL asl_object_t argument,
1584 but the library will use an internal lock, so that in fact only one thread
1585 will log at a time.
1586 .Pp
1587 When an application requires additional keys and values
1588 to be associated with each log message,
1589 a single message structure may be allocated and set up as
1590 .Dq template
1591 message of sorts:
1592 .Pp
1593 asl_object_t m = asl_new(ASL_TYPE_MSG);
1594 asl_set(m, ASL_KEY_FACILITY, "com.secrets.r.us");
1595 asl_set(m, "Clearance", "Top Secret");
1596 ...
1597 asl_log(NULL, m, ASL_LEVEL_NOTICE, "Message One");
1598 ...
1599 asl_log(NULL, m, ASL_LEVEL_ERR, "Message Two");
1600 .Pp
1601 The message structure will carry the values set for the
1602 .Dq Facility
1603 and
1604 .Dq Clearance
1605 keys so that they are used in each call to
1606 .Fn asl_log ,
1607 while the log level and the message text
1608 are taken from the calling parameters.
1609 .Pp
1610 The
1611 .Ar format
1612 argument to
1613 .Fn asl_log
1614 and
1615 .Fn asl_vlog
1616 is identical to
1617 .Xr printf 3 ,
1618 and may include
1619 .Ql %m ,
1620 which is replaced by the current error message
1621 (as denoted by the global variable
1622 .Va errno ;
1623 see
1624 .Xr strerror 3 . )
1625 .Pp
1626 Key/value pairs may be removed from a message structure with
1627 .Fn asl_unset .
1628 A message may be freed using
1629 .Fn asl_release .
1630 .Pp
1631 The
1632 .Fn asl_send
1633 routine is used by
1634 .Fn asl_log
1635 and
1636 .Fn asl_vlog
1637 to transmit a message to the server.
1638 This routine sets the value associated with ASL_KEY_TIME
1639 and sends the message.
1640 It may be called directly if all of a message's key/value pairs
1641 have been created using
1642 .Fn asl_set .
1643 .Ss SECURITY
1644 Messages that are sent to the
1645 .Nm syslogd
1646 server may be saved in a message store.
1647 The store may be searched using
1648 .Fn asl_search ,
1649 as described below.
1650 By default, all messages are readable by any user.
1651 However, some applications may wish to restrict read access
1652 for some messages.
1653 To accommodate this,
1654 a client may set a value for the "ReadUID" and "ReadGID" keys.
1655 These keys may be associated with a value
1656 containing an ASCII representation of a numeric UID or GID.
1657 Only the root user (UID 0),
1658 the user with the given UID,
1659 or a member of the group with the given GID
1660 may fetch access-controlled messages from the database.
1661 .Pp
1662 Although the ASL system does not require a "Facility" key in a message,
1663 many processes specify a "Facility" value similar
1664 to the common usage of the BSD
1665 .Nm syslog
1666 API, although developers are encouraged to adopt facility names that make sense for their application.
1667 A
1668 .Dq Reverse ICANN
1669 naming convention (e.g. "com.apple.system.syslog") should be adopted to avoid conflicting names.
1670 The ASL system generally allows any string to be used as a facility value,
1671 with one exception.
1672 The value "com.apple.system",
1673 or any string that has "com.apple.system" as a prefix,
1674 may only be used by processes running with the UID 0.
1675 This allows system processes to log messages that can not be "spoofed" by user processes.
1676 Non-UID 0 client processes that specify "com.apple.system" as a facility, will be assigned the value "user"
1677 by the
1678 .Nm syslogd
1679 server.
1680 .Ss CLIENT HANDLES
1681 A client handle contains various parameters and control settings that are used when a message is logged.
1682 This includes an identification string, a facility name, filtering controls, additional file descriptors, and other data.
1683 Client handles are not thread-safe.
1684 Applications that log from multiple threads should create a client handle for each thread.
1685 .Pp
1686 Applications that use libdispatch must also avoid using a single client handle from multiple dispatch queues if those queues may run concurrently.
1687 A good approach is to create one or more serial dispatch queues specifically for logging.
1688 Each such queue should use its own ASL client handle.
1689 .Pp
1690 If a single handle must be accessed by multiple dispatch queues,
1691 then the application must use locks, semaphores, or some other mechanism to prevent concurrent access to a client handle.
1692 .Pp
1693 A NULL value may be used in any of the routines
1694 that require an asl_object_t argument.
1695 In this case, the library will use an internal client handle.
1696 This internal handle contains its own lock, allowing multiple threads to safely use the NULL client handle.
1697 Note, however, that contention for the lock may cause undesirable synchronization behavior or reduced performance.
1698 .Pp
1699 The
1700 .Fn asl_open
1701 routine may be given an ident argument,
1702 which becomes the default value for the ASL_KEY_SENDER key,
1703 and a facility argument,
1704 which becomes the value associated with the ASL_KEY_FACILITY key.
1705 If NULL is passed as the value for
1706 .Ar ident ,
1707 the name of the currently running program will be used.
1708 If NULL is passed as the value for
1709 .Ar facility ,
1710 the value
1711 .Dq user
1712 will be used for non UID 0 processes, and
1713 .Dq
1714 daemon
1715 will be used for UID 0 processes.
1716 .Pp
1717 Several options are available when creating a client handle.
1718 They are:
1719 .Pp
1720 .Bl -tag -width "ASL_OPT_NO_REMOTE" -compact
1721 .It ASL_OPT_STDERR
1722 adds stderr as an output file descriptor
1723 .It ASL_OPT_NO_DELAY
1724 connects to the server immediately
1725 .It ASL_OPT_NO_REMOTE
1726 disables remote-control filter adjustment
1727 .El
1728 .Pp
1729 See the FILTERING section below, and the
1730 .Xr syslog 1
1731 for additional details on filter controls.
1732 .Pp
1733 A client handle is closed and its resources released using
1734 .Fn asl_close .
1735 Note that if additional file descriptors were added to the handle,
1736 either using the ASL_OPT_STDERR option
1737 or afterwards with the
1738 .Fn asl_add_log_file
1739 routine, those file descriptors are not closed by
1740 .Fn asl_close .
1741 .Ss LOGGING TO ADDITIONAL FILES
1742 If a client handle is opened with the ASL_OPT_STDERR option to
1743 .Fn asl_open ,
1744 a copy of each log message will be sent to stderr.
1745 Additional output streams may be include using
1746 .Fn asl_add_log_file .
1747 .Pp
1748 Messages sent to stderr or other files are printed in the "standard" message format
1749 also used as a default format by the
1750 .Xr syslog 1
1751 command line utility.
1752 Non-ASCII characters in a message are encoded using the
1753 .Dq safe
1754 encoding style used by
1755 .Xr syslog 1
1756 with the
1757 .Fl E Ar safe
1758 option.
1759 Backspace characters are printed as ^H.
1760 Carriage returns are mapped to newlines.
1761 A tab character is appended after newlines so that message text is indented.
1762 .Pp
1763 File descriptors may be removed from the list of outputs associated
1764 with a client handle with
1765 .Fn asl_remove_log_file .
1766 This routine simply removes the file descriptor from the output list.
1767 The file is not closed as a result.
1768 .Pp
1769 The ASL_OPT_STDERR option may not be unset
1770 after a client handle has been opened.
1771 .Ss SEARCHING
1772 The
1773 .Nm syslogd
1774 server archives received messages in a data store
1775 that may be searched using the
1776 .Fn asl_search ,
1777 .Fn asl_next ,
1778 and
1779 .Fn asl_release
1780 routines.
1781 A query message is created using:
1782 .Pp
1783 asl_object_t q = asl_new(ASL_TYPE_QUERY);
1784 .Pp
1785 Search settings are made in the query using
1786 .Fn asl_set_query .
1787 A search is performed on the data store with
1788 .Fn asl_search .
1789 It returns an object of type ASL_TYPE_LIST.
1790 The caller may use routines that operate on lists, such as
1791 .Fn asl_next ,
1792 .Fn asl_prev ,
1793 and
1794 .Fn asl_get_index
1795 to access the matching messages.
1796 .Pp
1797 Like other messages, ASL_TYPE_QUERY messages contain keys and values.
1798 They also associate an operation with each key and value.
1799 The operation is used to decide if a message matches the query.
1800 The simplest operation is ASL_QUERY_OP_EQUAL, which tests for equality.
1801 For example, the following code snippet searches for messages
1802 with a Sender value equal to
1803 .Dq MyApp .
1804 .Pp
1805 asl_object_t q, r;
1806 q = asl_new(ASL_TYPE_QUERY);
1807 asl_set_query(q, ASL_KEY_SENDER, "MyApp", ASL_QUERY_OP_EQUAL);
1808 r = asl_search(NULL, q);
1809 .Pp
1810 More complex searches may be performed using other query operations.
1811 .Pp
1812 .Bl -tag -width "ASL_QUERY_OP_GREATER_EQUAL" -compact
1813 .It ASL_QUERY_OP_EQUAL
1814 value equality
1815 .It ASL_QUERY_OP_GREATER
1816 value greater than
1817 .It ASL_QUERY_OP_GREATER_EQUAL
1818 value greater than or equal to
1819 .It ASL_QUERY_OP_LESS
1820 value less than
1821 .It ASL_QUERY_OP_LESS_EQUAL
1822 value less than or equal to
1823 .It ASL_QUERY_OP_NOT_EQUAL
1824 value not equal
1825 .It ASL_QUERY_OP_REGEX
1826 regular expression search
1827 .It ASL_QUERY_OP_TRUE
1828 always true - use to test for the existence of a key
1829 .El
1830 .Pp
1831 Regular expression search uses
1832 .Xr regex 3
1833 library.
1834 Patterns are compiled using the REG_EXTENDED and REG_NOSUB options.
1835 .Pp
1836 Modifiers that change the behavior of these operations
1837 may also be specified by ORing the modifier value with the operation.
1838 The modifiers are:
1839 .Pp
1840 .Bl -tag -width "ASL_QUERY_OP_SUBSTRING" -compact
1841 .It ASL_QUERY_OP_CASEFOLD
1842 string comparisons are case-folded
1843 .It ASL_QUERY_OP_PREFIX
1844 match a leading substring
1845 .It ASL_QUERY_OP_SUFFIX
1846 match a trailing substring
1847 .It ASL_QUERY_OP_SUBSTRING
1848 match any substring
1849 .It ASL_QUERY_OP_NUMERIC
1850 values are converted to integer using
1851 .Nm atoi
1852 .El
1853 .Pp
1854 The only modifier that is checked
1855 for ASL_QUERY_OP_REGEX search is ASL_QUERY_OP_CASEFOLD.
1856 This causes the regular expression to be compiled
1857 with the REG_ICASE option.
1858 .Pp
1859 If a query message contains more than one set of key/value/operation triples,
1860 the result will be a logical AND. For example, to find messages from
1861 .Dq MyApp
1862 with a priority level less than or equal to
1863 .Dq 3 :
1864 .Pp
1865 asl_object_t q, r;
1866 q = asl_new(ASL_TYPE_QUERY);
1867 asl_set_query(q, ASL_KEY_SENDER, "MyApp", ASL_QUERY_OP_EQUAL);
1868 asl_set_query(q, ASL_KEY_LEVEL, "3",
1869 ASL_QUERY_OP_LESS_EQUAL | ASL_QUERY_OP_NUMERIC);
1870 r = asl_search(NULL, q);
1871 .Pp
1872 After calling
1873 .Fn asl_search
1874 to get a list of matching messages, one can use
1875 .Fn asl_next
1876 to iterate through the list, and
1877 .Fn asl_fetch_key_val_op
1878 To iterate through the message dictionary.
1879 .Pp
1880 asl_object_t q, r;
1881 .Pp
1882 ...
1883 r = asl_search(NULL, q);
1884 while (NULL != (m = asl_next(r)))
1885 {
1886 int i, n;
1887 n = asl_count(m);
1888 for (i = 0; i < n; i++)
1889 {
1890 const char *key, *val;
1891 asl_fetch_key_val_op(m, i, key, val, NULL);
1892 ...
1893 }
1894 }
1895 asl_release(r);
1896 .Pp
1897 .Ss FILTERING AND REMOTE CONTROL
1898 Clients may set a filter mask value with
1899 .Fn asl_set_filter .
1900 The mask specifies which messages should be sent to the
1901 .Nm syslogd
1902 daemon by specifying a yes/no setting for each priority level.
1903 Clients typically set a filter mask
1904 to avoid sending relatively unimportant messages.
1905 For example, Debug or Info priority level messages
1906 are generally only useful for debugging operations.
1907 By setting a filter mask, a process can improve performance
1908 by avoiding sending messages that are in most cases unnecessary.
1909 .Pp
1910 .Fn asl_set_filter returns the previous value of the filter, i.e. the value of the filter before the routine was called.
1911 .Pp
1912 As a convenience, the macros ASL_FILTER_MASK(level) and ASL_FILTER_MASK_UPTO(level)
1913 may be used to construct a bit mask corresponding to a given priority level,
1914 or corresponding to a bit mask for all priority levels
1915 from ASL_LEVEL_EMERG to a given input level.
1916 .Pp
1917 The default filter mask is ASL_FILTER_MASK_UPTO(ASL_LEVEL_NOTICE).
1918 This means that by default,
1919 and in the absence of remote-control changes (described below),
1920 ASL_LEVEL_DEBUG and ASL_LEVEL_INFO priority level messages
1921 are not sent to the
1922 .Nm syslogd
1923 server.
1924 .Pp
1925 Three different filters exist for each application.
1926 The first is the filter mask set using
1927 .Fn asl_set_filter
1928 as described above.
1929 The Apple System Log facility also manages a
1930 .Dq master
1931 filter mask.
1932 The master filter mask usually has a value
1933 that indicates to the library that it is
1934 .Dq off ,
1935 and thus it has no effect.
1936 However, the mask filter mask may be enabled
1937 by giving it a value using the
1938 .Nm syslog
1939 command, using the
1940 .Fl c
1941 0 option.
1942 When the master filter mask has been set,
1943 it takes precedence over the client's filter mask.
1944 The client's mask is unmodified,
1945 and will become active again if remote-control filtering is disabled.
1946 .Pp
1947 In addition to the master filter mask,
1948 The Apple System Log facility
1949 also manages a per-client remote-control filter mask.
1950 Like the master filter mask, the per-client mask is usually
1951 .Dq off ,
1952 having no effect on a client.
1953 If a per-client filter mask is set using the
1954 .Nm syslog
1955 command, using the
1956 .Fl c Ar process
1957 option, then it takes precedence
1958 over both the client's filter mask and the master filter mask.
1959 As is the case with the master filter mask,
1960 a per-client mask ceases having any effect when if is disabled.
1961 .Pp
1962 The ASL_OPT_NO_REMOTE option to
1963 .Fn asl_open
1964 causes both the master and per-client remote-control masks
1965 to be ignored in the library.
1966 In that case, only the client's own filter mask
1967 is used to determine which messages are sent to the server.
1968 This may be useful for Applications that produce log messages
1969 that should never be filtered, due to security considerations.
1970 Note that root (administrator) access is required
1971 to set or change the master filter mask,
1972 and that only root may change a per-client remote-control filter mask
1973 for a root (UID 0) process.
1974 .Pp
1975 The per-process remote control filter value is kept as a state value
1976 associated with a key managed by
1977 .Nm notifyd .
1978 The key is protected by an access control mechanism that only permits the
1979 filter value to be accessed and modified by the same effective UID as the
1980 ASL client at the time that the first ASL connection was created.
1981 Remote filter control using
1982 .Nm syslog Fl c
1983 will fail for processes that change effective UID after starting an ASL connection.
1984 Those processes should close all ASL client handles and then re-open ASL connections
1985 if remote filter control support is desired.
1986 .Sh HISTORY
1987 These functions first appeared in
1988 Mac OS X 10.4.
1989 .Sh SEE ALSO
1990 .Xr syslog 1 ,
1991 .Xr strvis 3 ,
1992 .Xr syslogd 8