]>
git.saurik.com Git - apple/syslog.git/blob - libsystem_asl.tproj/include/asl.h
1cc2662d55dc5cb998cd4da3374fc43c71be62d0
2 * Copyright (c) 2004-2013 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
30 #include <sys/cdefs.h>
31 #include <Availability.h>
33 /* Version number encodes the date YYYYMMDD */
34 #define ASL_API_VERSION 20131108
36 typedef struct __asl_object_s
*asl_object_t
;
37 typedef asl_object_t aslclient
;
38 typedef asl_object_t aslmsg
;
39 typedef asl_object_t aslresponse
;
42 * These routines provide an interface to the Apple System Log facility.
43 * The API allows client applications to create flexible, structured messages
44 * and send them to the syslogd server. Messages received by the server are
45 * saved in a data store, subject to input filtering constraints.
46 * This API also permits clients to create queries and search the message
47 * data store for matching messages.
53 * These are added to allow headerdoc2html to process
54 * the prototypes of asl_log and asl_vlog correctly.
55 * The "-p" option to headerdoc2html is required.
59 #define __printflike(a,b)
64 /*! @defineblock Log Message Priority Levels
65 * Log levels of the message.
67 #define ASL_LEVEL_EMERG 0
68 #define ASL_LEVEL_ALERT 1
69 #define ASL_LEVEL_CRIT 2
70 #define ASL_LEVEL_ERR 3
71 #define ASL_LEVEL_WARNING 4
72 #define ASL_LEVEL_NOTICE 5
73 #define ASL_LEVEL_INFO 6
74 #define ASL_LEVEL_DEBUG 7
79 /*! @defineblock Log Message Priority Level Strings
80 * Strings corresponding to log levels.
82 #define ASL_STRING_EMERG "Emergency"
83 #define ASL_STRING_ALERT "Alert"
84 #define ASL_STRING_CRIT "Critical"
85 #define ASL_STRING_ERR "Error"
86 #define ASL_STRING_WARNING "Warning"
87 #define ASL_STRING_NOTICE "Notice"
88 #define ASL_STRING_INFO "Info"
89 #define ASL_STRING_DEBUG "Debug"
94 /*! @defineblock Attribute Matching
95 * Attribute value comparison operations.
97 #define ASL_QUERY_OP_CASEFOLD 0x0010
98 #define ASL_QUERY_OP_PREFIX 0x0020
99 #define ASL_QUERY_OP_SUFFIX 0x0040
100 #define ASL_QUERY_OP_SUBSTRING 0x0060
101 #define ASL_QUERY_OP_NUMERIC 0x0080
102 #define ASL_QUERY_OP_REGEX 0x0100
104 #define ASL_QUERY_OP_EQUAL 0x0001
105 #define ASL_QUERY_OP_GREATER 0x0002
106 #define ASL_QUERY_OP_GREATER_EQUAL 0x0003
107 #define ASL_QUERY_OP_LESS 0x0004
108 #define ASL_QUERY_OP_LESS_EQUAL 0x0005
109 #define ASL_QUERY_OP_NOT_EQUAL 0x0006
110 #define ASL_QUERY_OP_TRUE 0x0007
115 /*! @defineblock Message Attributes
116 * These attributes are known by ASL, and are generally
117 * associated with all log messages.
118 * Additional attributes may be added as desired.
120 #define ASL_KEY_TIME "Time" /* Timestamp. Set automatically */
121 #define ASL_KEY_TIME_NSEC "TimeNanoSec" /* Nanosecond time. */
122 #define ASL_KEY_HOST "Host" /* Sender's address (set by the server). */
123 #define ASL_KEY_SENDER "Sender" /* Sender's identification string. Default is process name. */
124 #define ASL_KEY_FACILITY "Facility" /* Sender's facility. Default is "user". */
125 #define ASL_KEY_PID "PID" /* Sending process ID encoded as a string. Set automatically. */
126 #define ASL_KEY_UID "UID" /* UID that sent the log message (set by the server). */
127 #define ASL_KEY_GID "GID" /* GID that sent the log message (set by the server). */
128 #define ASL_KEY_LEVEL "Level" /* Log level number encoded as a string. See levels above. */
129 #define ASL_KEY_MSG "Message" /* Message text. */
130 #define ASL_KEY_READ_UID "ReadUID" /* User read access (-1 is any user). */
131 #define ASL_KEY_READ_GID "ReadGID" /* Group read access (-1 is any group). */
132 #define ASL_KEY_EXPIRE_TIME "ASLExpireTime" /* Expiration time for messages with long TTL. */
133 #define ASL_KEY_MSG_ID "ASLMessageID" /* 64-bit message ID number (set by the server). */
134 #define ASL_KEY_SESSION "Session" /* Session (set by the launchd). */
135 #define ASL_KEY_REF_PID "RefPID" /* Reference PID for messages proxied by launchd */
136 #define ASL_KEY_REF_PROC "RefProc" /* Reference process for messages proxied by launchd */
137 #define ASL_KEY_AUX_TITLE "ASLAuxTitle" /* Auxiliary title string */
138 #define ASL_KEY_AUX_UTI "ASLAuxUTI" /* Auxiliary Uniform Type ID */
139 #define ASL_KEY_AUX_URL "ASLAuxURL" /* Auxiliary Uniform Resource Locator */
140 #define ASL_KEY_AUX_DATA "ASLAuxData" /* Auxiliary in-line data */
141 #define ASL_KEY_OPTION "ASLOption" /* Internal */
142 #define ASL_KEY_MODULE "ASLModule" /* Internal */
143 #define ASL_KEY_SENDER_INSTANCE "SenderInstance" /* Sender instance UUID. */
144 #define ASL_KEY_SENDER_MACH_UUID "SenderMachUUID" /* Sender Mach-O UUID. */
145 #define ASL_KEY_FINAL_NOTIFICATION "ASLFinalNotification" /* syslogd posts value as a notification when message has been processed */
146 #define ASL_KEY_OS_ACTIVITY_ID "OSActivityID" /* Current OS Activity for the logging thread */
151 /*! @defineblock ASL Object Types
152 * The library uses only one opaque type - asl_object_t.
153 * Many of the routines can operate on several different types.
154 * For example, asl_search() can be used to search a list of messages,
155 * an ASL database directory or data file, or the main ASL database.
156 * It can even be used to check a single message against a query
157 * message, or against another message to check for exact match.
159 * The first three types are container objects - messages, queries,
160 * and lists of messages or queries. The following types are
161 * abstractions for ASL data files and ASL data stores (directories
162 * containing data files).
164 * ASL_TYPE_CLIENT is a high-level object that abstracts ASL
165 * interactions. It may access ASL stores or files directly,
166 * and it may communicate with ASL daemons.
169 #define ASL_TYPE_UNDEF 0xffffffff
170 #define ASL_TYPE_MSG 0
171 #define ASL_TYPE_QUERY 1
172 #define ASL_TYPE_LIST 2
173 #define ASL_TYPE_FILE 3
174 #define ASL_TYPE_STORE 4
175 #define ASL_TYPE_CLIENT 5
180 /*! @defineblock search directions
181 * Used for asl_store_match(), asl_file_match(), and asl_match().
183 #define ASL_MATCH_DIRECTION_FORWARD 1
184 #define ASL_MATCH_DIRECTION_REVERSE -1
189 /*! @defineblock Filter Masks
190 * Used in client-side filtering, which determines which
191 * messages are sent by the client to the syslogd server.
193 #define ASL_FILTER_MASK_EMERG 0x01
194 #define ASL_FILTER_MASK_ALERT 0x02
195 #define ASL_FILTER_MASK_CRIT 0x04
196 #define ASL_FILTER_MASK_ERR 0x08
197 #define ASL_FILTER_MASK_WARNING 0x10
198 #define ASL_FILTER_MASK_NOTICE 0x20
199 #define ASL_FILTER_MASK_INFO 0x40
200 #define ASL_FILTER_MASK_DEBUG 0x80
205 /*! @defineblock Filter Mask Macros
206 * Macros to create bitmasks for filter settings - see asl_set_filter().
208 #define ASL_FILTER_MASK(level) (1 << (level))
209 #define ASL_FILTER_MASK_UPTO(level) ((1 << ((level) + 1)) - 1)
214 /*! @defineblock Client Creation Options
215 * Options for asl_open().
216 * Note that ASL_OPT_NO_DELAY no longer has any effect.
218 #define ASL_OPT_STDERR 0x00000001
219 #define ASL_OPT_NO_DELAY 0x00000002
220 #define ASL_OPT_NO_REMOTE 0x00000004
225 /*! @defineblock File and Store Open Options
226 * Options for asl_open_path().
228 #define ASL_OPT_OPEN_WRITE 0x00000001
229 #define ASL_OPT_CREATE_STORE 0x00000002
234 /*! @defineblock File Descriptor Types
235 * Instructions on how to treat the file descriptor in asl_log_descriptor().
237 #define ASL_LOG_DESCRIPTOR_READ 1
238 #define ASL_LOG_DESCRIPTOR_WRITE 2
242 /*! @defineblock Output file message and time formats.
243 * These select internally defined formats for printed log messages for
244 * asl_add_output_file(). Custom message and time formats may also be
245 * used. These pre-defined formats and custom formats are described in detail
246 * in the syslog(1) manual page.
248 #define ASL_MSG_FMT_RAW "raw"
249 #define ASL_MSG_FMT_STD "std"
250 #define ASL_MSG_FMT_BSD "bsd"
251 #define ASL_MSG_FMT_XML "xml"
252 #define ASL_MSG_FMT_MSG "msg"
254 #define ASL_TIME_FMT_SEC "sec"
255 #define ASL_TIME_FMT_UTC "utc"
256 #define ASL_TIME_FMT_LCL "lcl"
260 /*! @defineblock Text Encoding Types
261 * These are used by the library when formatting messages to be written
262 * to file descriptors associated with an ASL client handle with
263 * asl_add_output_file(). The syslog(1) manual page describes text encoding
264 * in detail. ASL_ENCODE_ASL corresponds to the "vis" encoding option
265 * described in the syslog(1) manual. ASL_ENCODE_XML should be used in
266 * combination with ASL_MSG_FMT_XML to ensure that special XML characters
267 * are correctly encoded.
269 #define ASL_ENCODE_NONE 0
270 #define ASL_ENCODE_SAFE 1
271 #define ASL_ENCODE_ASL 2
272 #define ASL_ENCODE_XML 3
277 * ASL_PREFILTER_LOG is a macro similar to asl_log(), but it first checks
278 * if the message will simply be ignored due to local filter settings.
279 * This prevents the variable argument list from being evaluated.
280 * Note that the message may still be processed if it will be written
281 * to a file or stderr.
284 * (input) An ASL_TYPE_CLIENT object.
286 * (input) An asl_object_t of type ASL_TYPE_MSG (default attributes will be supplied if msg is NULL).
288 * (input) Log level (ASL_LEVEL_DEBUG to ASL_LEVEL_EMERG).
290 * (input) A printf() - style format string followed by a list of arguments.
292 #define ASL_PREFILTER_LOG(client, msg, level, format, ...) \
294 asl_object_t _client = (client); \
295 asl_object_t _msg = (msg); \
296 uint32_t _asl_eval = _asl_evaluate_send(_client, _msg, (level)); \
297 if (_asl_eval != 0) _asl_lib_log(_client, _asl_eval, _msg, (format), ## __VA_ARGS__); \
304 /* ASL Library SPI - do not call directly */
305 int _asl_lib_log(asl_object_t client
, uint32_t eval
, asl_object_t msg
, const char *format
, ...) __printflike(4, 5);
306 uint32_t _asl_evaluate_send(asl_object_t client
, asl_object_t msg
, int level
);
309 * Initialize a connection to the ASL server.
311 * This call is optional in many cases. The library will perform any
312 * necessary initializations on the fly. A call to asl_open() is required
313 * if optional settings must be made before messages are sent to the server.
314 * These include setting the client filter and managing additional output
315 * file descriptors. Note that the default setting of the client filter is
316 * ASL_FILTER_MASK_UPTO(ASL_LEVEL_NOTICE), so ASL_LEVEL_DEBUG and ASL_LEVEL_INFO
317 * messages are not sent to the server by default.
318 * A separate client connection is required for multiple threads or
321 * Options (defined above) may be set using the opts parameter. They are:
323 * ASL_OPT_STDERR - adds stderr as an output file descriptor
325 * ASL_OPT_NO_REMOTE - disables the remote-control mechanism for adjusting
326 * filter levers for processes using e.g. syslog -c ...
329 * (input) Sender name.
331 * (input) Facility name.
333 * (input) Options (see Client Creation Options).
334 * @result Returns an ASL client handle (asl_object_t of type ASL_TYPE_CLIENT).
336 asl_object_t
asl_open(const char *ident
, const char *facility
, uint32_t opts
) __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
);
339 * Open an ASL database or ASL data file for read or write access.
341 * Opens an ASL database if the path specifies a directory, or
342 * an ASL data file if the path specifies a file. Opens the system
343 * ASL database if path is NULL.
345 * If the ASL_OPT_OPEN_READ option is specified, the database or data file may be
346 * searched with asl_search() or asl_match(). asl_next() and asl_prev() may be used
347 * to iterate over the messages in the database or file.
349 * If the ASL_OPT_OPEN_WRITE option is specified, an existing file or database is
350 * opened for writing. New messages may be added to the file or database using
351 * asl_append(), asl_send(), asl_log(), or asl_vlog(). Existing messages in the
352 * store or file may not be deleted or modified.
354 * If the path does not exist, asl_open_path() will create a new database if
355 * ASL_OPT_CREATE_STORE is set in the options, or a new data file otherwise.
356 * The file will be created with the user's effective UID and GID as owner and
357 * group. The mode will be 0644. If a different mode, UID, or GID is desired,
358 * an empty file or directory may be pre-created with the desired settings.
361 * (input) Location of the ASL database or ASL data file in the filesystem.
362 * A value of NULL may be used to open the system's database.
364 * (input) Options (see File and Store Open Options).
365 * @result Returns an ASL object of type ASL_TYPE_STORE or ASL_TYPE_FILE, or NULL on failure.
367 asl_object_t
asl_open_path(const char *path
, uint32_t opts
) __OSX_AVAILABLE_STARTING(__MAC_10_10
, __IPHONE_7_0
);
370 * Shuts down a connection to the server.
371 * This routine is identical to asl_release().
374 * (input) An ASL object.
376 void asl_close(asl_object_t obj
) __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
);
379 * Write log messages to the given file descriptor.
381 * Log messages will be written to this file as well as to the server.
382 * This is equivalent to calling:
383 * asl_add_output_file(asl, descriptor, ASL_MSG_FMT_STD, ASL_TIME_FMT_LCL, ASL_FILTER_MASK_UPTO(ASL_LEVEL_DEBUG), ASL_ENCODE_SAFE)
386 * (input) An ASL client handle (asl_object_t of type ASL_TYPE_CLIENT).
388 * (input) A file descriptor.
389 * @result Returns 0 on success, non-zero on failure.
391 int asl_add_log_file(asl_object_t client
, int descriptor
) __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
);
394 * Write log messages to the given file descriptor.
396 * Log messages will be written to this file as well as to the server.
397 * This routine extends the basic interface offered by asl_add_log_file(),
398 * allowing control of the format used to write log message written to the file.
399 * control of the time zone used when printing time values, and allowing
400 * individual filtering control for each log file.
403 * (input) An ASL client handle (asl_object_t of type ASL_TYPE_CLIENT).
405 * (input) A file descriptor.
407 * (input) A character string specifying the message format.
409 * (input) A character string specifying the time format.
411 * (input) A filter value.
412 * @param text_encoding
413 * (input) A text encoding type.
414 * @result Returns 0 on success, non-zero on failure.
416 int asl_add_output_file(asl_object_t client
, int fd
, const char *mfmt
, const char *tfmt
, int filter
, int text_encoding
) __OSX_AVAILABLE_STARTING(__MAC_10_10
, __IPHONE_7_0
);
419 * Write log messages to the given file descriptor.
421 * Sets or changes a filter value for filtering messages written to a file associated
422 * with an ASL client handle using asl_add_output_file() or asl_add_log_file().
425 * (input) An ASL client handle (asl_object_t of type ASL_TYPE_CLIENT).
427 * (input) A file descriptor.
429 * (input) A filter value.
430 * @result Returns the previous filter value.
432 int asl_set_output_file_filter(asl_object_t client
, int fd
, int filter
) __OSX_AVAILABLE_STARTING(__MAC_10_10
, __IPHONE_7_0
);
435 * Stop writing log messages to the given file descriptor.
436 * The file descripter is not closed by this routine.
439 * (input) An ASL client handle (asl_object_t of type ASL_TYPE_CLIENT).
441 * (input) A file descriptor.
442 * @result Returns 0 on success, non-zero on failure.
444 int asl_remove_log_file(asl_object_t client
, int descriptor
) __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
);
447 * Set a filter for messages being sent to the server.
448 * The filter is a bitmask representing priorities. The ASL_FILTER_MASK
449 * macro may be used to convert a priority level into a bitmask for that
450 * level. The ASL_FILTER_MASK_UPTO macro creates a bitmask for all
451 * priorities up to and including a given priority.
452 * Messages with priority levels that do not have a corresponding bit
453 * set in the filter are not sent to the server, although they will be
454 * sent to any file descripters added with asl_add_log_file().
455 * The default setting is ASL_FILTER_MASK_UPTO(ASL_LEVEL_NOTICE).
456 * Returns the previous filter value.
459 * (input) An ASL client handle (asl_object_t of type ASL_TYPE_CLIENT).
461 * (input) A filter value.
462 * @result Returns the previous filter value.
464 int asl_set_filter(asl_object_t client
, int f
) __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
);
467 * Examine attribute keys.
470 * (input) An ASL message or query (asl_object_t of type ASL_TYPE_MSG or ASL_TYPE_QUERY).
472 * (input) An index value.
473 * @result Returns the key of the nth attribute in a message (beginning at zero),
474 * or NULL if n is greater than the largest message index.
476 const char *asl_key(asl_object_t msg
, uint32_t n
) __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
);
479 * Examine attribute keys.
482 * (input) An ASL message or query (asl_object_t of type ASL_TYPE_MSG or ASL_TYPE_QUERY).
484 * (output) key at the given index. May be NULL.
486 * (output) val at the given index. May be NULL.
488 * (output) op at the given index. May be NULL.
490 * (input) An index value.
491 * @result returns 0 for success, non-zero for failure.
493 int asl_fetch_key_val_op(asl_object_t msg
, uint32_t n
, const char **key
, const char **val
, uint32_t *op
) __OSX_AVAILABLE_STARTING(__MAC_10_10
, __IPHONE_7_0
);
496 * Create a new log message, query message, message list, or a connection to the system database.
499 * (input) ASL_TYPE_MSG, ASL_TYPE_QUERY, ASL_TYPE_LIST, or ASL_TYPE_CLIENT.
500 * @result Returns a newly allocated asl_object_t of the specified type.
503 * New objects of type ASL_TYPE_CLIENT will be created with default settings for
504 * a client connection, equivalent to asl_open(NULL, NULL, 0).
505 * The Sender and Facility values associated with an ASL_TYPE_CLIENT may
506 * be reset using asl_set().
508 asl_object_t
asl_new(uint32_t type
) __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
);
511 * Set or re-set a message or query attribute.
512 * May also be used to set values associated with an ASL_TYPE_CLIENT object,
513 * such as Sender and Facility.
516 * (input) An ASL object of type ASL_TYPE_MSG, ASL_TYPE_QUERY, or ASL_TYPE_CLIENT.
518 * (input) Attribute key.
520 * (input) Attribute value.
521 * @result returns 0 for success, non-zero for failure.
523 int asl_set(asl_object_t obj
, const char *key
, const char *value
) __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
);
526 * Remove a key/value attribute.
529 * (input) An ASL object of type ASL_TYPE_MSG, ASL_TYPE_QUERY, or ASL_TYPE_CLIENT.
531 * (input) Attribute key.
532 * returns 0 for success, non-zero for failure.
534 int asl_unset(asl_object_t obj
, const char *key
) __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
);
537 * Get the value associated with an attribute key.
540 * (input) An ASL object of type ASL_TYPE_MSG, ASL_TYPE_QUERY, or ASL_TYPE_CLIENT.
542 * (input) Attribute key.
543 * @result Returns the attribute value, or NULL if the object does not contain the key.
545 const char *asl_get(asl_object_t msg
, const char *key
) __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
);
548 * Log a message with a particular log level.
551 * (input) An asl_object_t or NULL.
553 * (input) An asl_object_t of type ASL_TYPE_MSG (default attributes will be supplied if msg is NULL).
555 * (input) Log level (ASL_LEVEL_DEBUG to ASL_LEVEL_EMERG).
557 * (input) A printf() - style format string followed by a list of arguments.
558 * @result Returns 0 for success, non-zero for failure.
561 * The input object may be of any type.
562 * In typical usage, obj is of type ASL_TYPE_CLIENT or obj is NULL.
563 * NULL causes the library to use the default ASL client handle.
564 * This routine prepares a message for tranmission to the ASL server daemon (syslogd),
565 * The message is sent to the server subject to filter settings. The message may also
566 * be formatted and printed to various output files.
568 * For ASL_TYPE_MSG, this routine will set all key/value pairs in the input object as
569 * they would appear if the message were being sent to the server. This includes
570 * setting alues for ASL_KEY_TIME, ASL_KEY_TIME_NSEC, ASL_KEY_HOST, and so on.
572 * If the object is of type ASL_TYPE_STORE or ASL_TYPE_FILE, a message will be
573 * constructed (as above) and saved in the file or data store. No filtering is done.
575 * If obj is of type ASL_TYPE_LIST, a message is created and appended to the list.
577 * The object type ASL_TYPE_QUERY is supported, but the key/value pairs set in the
578 * object will have an operator value of zero.
580 int asl_log(asl_object_t client
, asl_object_t msg
, int level
, const char *format
, ...) __printflike(4, 5) __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
);
583 * Log a message with a particular log level.
585 * This API is a simplified version of asl_log(). It uses the default (NULL) ASL client handle,
586 * and does not have a msg parameter to supply additonal key/value pairs to be attached to the
587 * message sent to the syslogd server.
590 * (input) Log level (ASL_LEVEL_DEBUG to ASL_LEVEL_EMERG).
592 * (input) A printf() - style format string followed by a list of arguments.
593 * @result Returns 0 for success, non-zero for failure.
595 int asl_log_message(int level
, const char *format
, ...) __printflike(2, 3) __OSX_AVAILABLE_STARTING(__MAC_10_10
, __IPHONE_7_0
);
598 * Log a message with a particular log level.
599 * Similar to asl_log, but takes a va_list argument.
602 * (input) An ASL object or NULL.
604 * (input) An asl_object_t of type ASL_TYPE_MSG (default attributes will be supplied if msg is NULL).
606 * (input) Log level (ASL_LEVEL_DEBUG to ASL_LEVEL_EMERG).
608 * (input) A printf() - style format string followed by a list of arguments.
610 * (input) A va_list containing the values for the format string.
611 * @result Returns 0 for success, non-zero for failure.
613 * See the discussion for asl_log() for a description of how this routine treats different
614 * types of input object.
617 int asl_vlog(asl_object_t obj
, asl_object_t msg
, int level
, const char *format
, va_list ap
) __printflike(4, 0) __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
);
622 * This routine may be used instead of asl_log() or asl_vlog() if asl_set()
623 * has been used to set all of a message's attributes.
626 * (input) An ASL object or NULL.
628 * (input) An asl_object_t of type ASL_TYPE_MSG.
629 * @result Returns 0 for success, non-zero for failure.
631 * See the discussion for asl_log() for a description of how this routine treats different
632 * types of input object.
634 int asl_send(asl_object_t obj
, asl_object_t msg
) __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
);
637 * DEPRECATED: Free an ASL object and all internal resources associated with it.
638 * This routine is identical to asl_release(), which should be used instead.
639 * Note that we don't issue a deprecation warning - yet.
642 * (input) An ASL object to free.
644 void asl_free(asl_object_t obj
) __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
);
647 * Increment the internal reference count of an ASL object.
650 * (input) An ASL object to retain.
651 * @result Returns the object.
653 asl_object_t
asl_retain(asl_object_t obj
) __OSX_AVAILABLE_STARTING(__MAC_10_10
, __IPHONE_7_0
);
656 * Decrement the internal reference count of an ASL object.
657 * Frees the object when the reference count becomes zero.
660 * (input) An ASL object to release.
662 void asl_release(asl_object_t obj
) __OSX_AVAILABLE_STARTING(__MAC_10_10
, __IPHONE_7_0
);
665 * Get the internal type of an ASL object.
668 * (input) An ASL object.
669 * @result Returns the object type.
671 uint32_t asl_get_type(asl_object_t obj
) __OSX_AVAILABLE_STARTING(__MAC_10_10
, __IPHONE_7_0
);
674 * Set arbitrary parameters of a query.
675 * This is similar to asl_set, but allows richer query operations.
676 * See ASL_QUERY_OP_* above.
679 * (input) An ASL object of type ASL_TYPE_QUERY.
681 * (input) Attribute key
683 * (input) Attribute value
685 * (input) An operation (ASL_QUERY_OP_*)
686 * @result Returns 0 for success, non-zero for failure
688 int asl_set_query(asl_object_t msg
, const char *key
, const char *value
, uint32_t op
) __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
);
691 * Search for messages matching the criteria described by an query object.
692 * The caller should set the attributes to match using asl_set_query() or asl_set().
693 * The operation ASL_QUERY_OP_EQUAL is used for attributes set with asl_set().
696 * (input) An ASL object to search.
698 * (input) An asl_object_t of type ASL_TYPE_QUERY or ASL_TYPE_MSG.
699 * query may be NULL, which matches anything.
700 * @result Returns an ASL object containing messages matching the query, or NULL if there are no matches.
703 * The object to search may be of any type.
704 * ASL_TYPE_CLIENT searches the main ASL database.
705 * ASL_TYPE_STORE searches an ASL database in the filesystem.
706 * ASL_TYPE_FILE searches an ASL data file in the filesystem.
707 * ASL_TYPE_LIST searches for matches in a list of messages.
709 * A NULL query matches anything.
711 * If obj is of type ASL_TYPE_MSG and query is of type ASL_TYPE_QUERY, obj is matched against the query,
712 * and a list containing the "obj" object is returned if the match succeeds.
714 * If both obj and query are objects of type ASL_TYPE_MSG or both are of type ASL_TYPE_QUERY,
715 * they are tested for exact match. A list containing the "obj" object is returned if the match is exact.
717 * If obj is of type ASL_TYPE_QUERY and query is of type ASL_TYPE_MSG, the routine returns NULL.
720 asl_object_t
asl_search(asl_object_t obj
, asl_object_t query
) __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
);
723 * DEPRECATED: Iterate over messages in an asl_object_t (same as an aslresponse).
724 * This routine is identical to asl_next().
727 * (input) An asl_object_t (aslresponse).
728 * @result Returns the next message contained in an ASL object, or NULL when there are no more messages.
731 * This routine is deprecated in favor of asl_next().
733 asl_object_t
aslresponse_next(asl_object_t obj
) __OSX_AVAILABLE_BUT_DEPRECATED_MSG(__MAC_10_4
,__MAC_10_10
,__IPHONE_2_0
,__IPHONE_7_0
, "Use asl_next instead");
736 * DEPRECATED: Free an asl_object_t.
737 * This routine is identical to asl_release().
740 * (input) An asl_object_t (aslresponse).
743 * This routine is deprecated in favor of asl_release().
745 void aslresponse_free(asl_object_t obj
) __OSX_AVAILABLE_BUT_DEPRECATED_MSG(__MAC_10_4
,__MAC_10_10
,__IPHONE_2_0
,__IPHONE_7_0
, "Use asl_release instead");
748 * Append messages to an object of type ASL_TYPE_LIST. The input "obj"
749 * parameter may be of type ASL_TYPE_MSG or ASL_TYPE_QUERY, in which case
750 * the object is appended to the list, or "obj" may be of type ASL_TYPE_LIST,
751 * in which case each object in that list is appended to the "list" object.
752 * Does nothing if either list or obj are NULL.
755 * (input) An object of type ASLTYPE_CLIENT or ASL_TYPE_LIST, or an object of type
756 * ASL_TYPE_FILE or ASL_TYPE_STORE that is open for write operations.
758 * (input) An object of type ASL_TYPE_MSG, ASL_TYPE_QUERY or type ASL_TYPE_LIST.
760 void asl_append(asl_object_t obj
, asl_object_t obj_to_add
) __OSX_AVAILABLE_STARTING(__MAC_10_10
, __IPHONE_7_0
);
763 * Prepend messages to an object of type ASL_TYPE_LIST. The input "obj"
764 * parameter may be of type ASL_TYPE_MSG or ASL_TYPE_QUERY, in which case
765 * the object is prepended to the list, or "obj" may be of type ASL_TYPE_LIST,
766 * in which case each object in that list is prepended to the "list" object.
767 * Does nothing if either list or obj are NULL.
770 * (input) An object of type ASL_TYPE_LIST.
772 * (input) An object of type ASL_TYPE_MSG, ASL_TYPE_QUERY or type ASL_TYPE_LIST.
774 void asl_prepend(asl_object_t obj
, asl_object_t obj_to_add
) __OSX_AVAILABLE_STARTING(__MAC_10_10
, __IPHONE_7_0
);
777 * Get the number of key/value pairs in an object of type ASL_TYPE_MSG or ASL_TYPE_QUERY,
778 * or the number of components in an object of type ASL_TYPE_LIST.
781 * (input) An asl_object_t of type ASL_TYPE_MSG, ASL_TYPE_QUERY, or ASL_TYPE_LIST.
782 * @result The number of components in the object.
783 * Returns zero if object is empty or NULL, or if the type is not
784 * ASL_TYPE_MSG, ASL_TYPE_QUERY, or ASL_TYPE_LIST.
786 size_t asl_count(asl_object_t obj
) __OSX_AVAILABLE_STARTING(__MAC_10_10
, __IPHONE_7_0
);
789 * Retreive a message from an object of type ASL_TYPE_LIST.
792 * (input) An asl_object_t of type ASL_TYPE_LIST
793 * @result Returns the message (an object of type ASL_TYPE_MSG or ASL_TYPE_QUERY) at the specified index.
794 * Returns NULL if the index is out of range or if list is not an object of type ASL_TYPE_LIST.
796 asl_object_t
asl_get_index(asl_object_t list
, size_t index
) __OSX_AVAILABLE_STARTING(__MAC_10_10
, __IPHONE_7_0
);
799 * Remove the message at a specified index from an object of type ASL_TYPE_LIST.
802 * (input) An object of type ASL_TYPE_LIST.
804 void asl_remove_index(asl_object_t list
, size_t index
) __OSX_AVAILABLE_STARTING(__MAC_10_10
, __IPHONE_7_0
);
807 * Creates an auxiliary file that may be used to save arbitrary data. The ASL message msg
808 * will be saved at the time that the auxiliary file is closed with asl_close_auxiliary_file().
809 * The log entry will include any keys and values found in msg, and it will include the title
810 * and Uniform Type Identifier specified. If NULL is supplied as a value for the uti parameter,
811 * the type "public.data" is used. Console.app will display a hyperlink to the file.
812 * Output parameter out_descriptor will contain a readable and writable file descriptor for the new
815 * By default, the file will be world-readable. If the message contains a ReadUID and/or a
816 * ReadGID key, then the values for those keys will determine read access to the file.
818 * The file will be deleted at the same time that the message expires from the ASL data store.
819 * The aslmanager utility manages message expiry. If msg contains a value for ASLExpireTime,
820 * then the message and the file will not be deleted before that time. The value may be in
821 * seconds after the Epoch, or it may be ctime() format, e.g "Thu Jun 24 18:22:48 2010".
824 * (input) An object of type ASL_TYPE_MSG.
826 * (input) A title string for the file.
828 * (input) Uniform Type Identifier for the file.
829 * @param out_descriptor
830 * (output) A writable file descriptor.
831 * @result Returns 0 for success, non-zero for failure
833 int asl_create_auxiliary_file(asl_object_t msg
, const char *title
, const char *uti
, int *out_descriptor
) __OSX_AVAILABLE_STARTING(__MAC_10_7
,__IPHONE_5_0
);
836 * Close an auxiliary file opened by asl_create_auxiliary_file() when writing is complete.
837 * syslogd will log the message provided to asl_create_auxiliary_file() when this routine
841 * (input) The file descriptor
842 * @result Returns 0 for success, non-zero for failure
844 int asl_close_auxiliary_file(int descriptor
) __OSX_AVAILABLE_STARTING(__MAC_10_7
,__IPHONE_5_0
);
847 * Sends an ASL message to syslogd along with a title string, Uniform Resource Locator,
848 * and Uniform Type Identifier specified. Console.app will hyperlink the title string to
849 * the specified URL. If NULL is supplied as a value for the uti parameter, the default
850 * type "public.data" is used.
853 * (input) An object of type ASL_TYPE_MSG.
855 * (input) A title string for the file
857 * (input) Uniform Type Identifier for the file
859 * (input) Uniform Type Locator
860 * @result Returns 0 for success, non-zero for failure
862 int asl_log_auxiliary_location(asl_object_t msg
, const char *title
, const char *uti
, const char *url
) __OSX_AVAILABLE_STARTING(__MAC_10_7
,__IPHONE_5_0
);
865 * Creates an object of type ASL_TYPE_CLIENT for logging to a file descriptor.
866 * The file must be opened for read and write access. This routine may be used in conjunction
867 * with asl_create_auxiliary_file() to save ASL format log messages to an auxiliary file.
869 * When logging to the file is complete, the returned object should be released with asl_release().
870 * The file descriptor should be closed using asl_close_auxiliary_file() if it was returned by
871 * asl_create_auxiliary_file(), or close() otherwise.
873 * The returned client object is thread-safe. It contains a lock that is aquired by
874 * the calling thread. Note that this may cause unexpected syncronization behavior
875 * if multiple threads log to the returned object, or in applications that use the
876 * object in multiple dispatch queues.
878 * Note that per-message read access controls (ReadUID and ReadGID) and message expire
879 * times (ASLExpireTime) keys have no effect for messages written to this file.
881 * Also note that files are NOT truncated. This is a change in OS X 10.9 and iOS 7.0.
882 * Previous versions of this routine truncated the file before writing. Callers
883 * may use ftruncate() to truncate the file if desired. If an existing non-empty
884 * file is used, it must be an ASL format data file.
887 * (input) A file descriptor
889 * (input) Sender name
891 * (input) Facility name
892 * @result An object of type ASL_TYPE_CLIENT.
894 asl_object_t
asl_open_from_file(int descriptor
, const char *ident
, const char *facility
) __OSX_AVAILABLE_STARTING(__MAC_10_7
,__IPHONE_5_0
);
897 * This API provides functionality to use file descriptors to send logging
900 * asl is retained by ASL and must still be closed by the caller by calling
901 * asl_close() if the caller loses reference to it. msg is copied by ASL and
902 * similarly must still be freed by the caller by calling asl_free() if the
903 * caller loses reference to it. Any changes made to it after calling
904 * asl_log_descriptor() are not applicable to the message used. descriptor
905 * is treated differentlty based on the value of fd_type.
907 * If fd_type is ASL_LOG_DESCRIPTOR_READ, the descriptor must be open for read
908 * access. ASL uses GCD to read from the descriptor as data becomes available.
909 * These data are line buffered and passed to asl_log. When EOF is read, the
910 * descriptor is closed.
913 * asl_log_descriptor(c, m, ASL_LEVEL_NOTICE, STDIN_FILENO, ASL_LOG_DESCRIPTOR_READ);
915 * If fd_type is ASL_LOG_DESCRIPTOR_WRITE, the descriptor is closed and a new
916 * writable descriptor is created with the same fileno. Any data written to
917 * this new descriptor are line buffered and passed to asl_log. When EOF is
918 * sent, no further data are read. The caller is responsible for closing the
919 * new descriptor. One common use for this API is to redirect writes to stdout
920 * or stderr to ASL by passing STDOUT_FILENO or STDERR_FILENO as descriptor.
923 * asl_log_descriptor(c, m, ASL_LEVEL_NOTICE, STDOUT_FILENO, ASL_LOG_DESCRIPTOR_WRITE);
924 * asl_log_descriptor(c, m, ASL_LEVEL_ERR, STDERR_FILENO, ASL_LOG_DESCRIPTOR_WRITE);
927 * (input) An ASL object of type ASL_TYPE_CLIENT.
929 * (input) An asl_object_t of type ASL_TYPE_MSG (default attributes will be supplied if msg is NULL).
931 * (input) Log level (ASL_LEVEL_DEBUG to ASL_LEVEL_EMERG)
933 * (input) An open file descriptor to read from
935 * (input) Either ASL_LOG_DESCRIPTOR_READ or ASL_LOG_DESCRIPTOR_WRITE
936 * @result Returns 0 for success, non-zero for failure
938 int asl_log_descriptor(asl_object_t asl
, asl_object_t msg
, int level
, int descriptor
, uint32_t fd_type
) __OSX_AVAILABLE_STARTING(__MAC_10_8
,__IPHONE_5_1
);
944 * Creates a string representation of an ASL message.
946 * This utility creates a character string suitable for printing an ASL message.
947 * The returned string ends with a newline character. The caller is responsible
948 * for freeing the returned string.
949 * The message is formatted according to the specified format string. Timestamps
950 * are formatted accoring to the specified time format string. Special characters
951 * are enoded as specified by the text_encoding parameter.
954 * (input) An asl_object_t of type ASL_TYPE_MSG.
956 * (input) A format specification string. See "Output file message and time formats"
957 * for standard formats. See the syslog(1) man page for more discussion on formats.
959 * (input) A time format specification string. See "Output file message and time formats"
960 * for standard formats. See the syslog(1) man page for more discussion on time formats.
961 * @param text_encoding
962 * (input) Text encoding control (for special characters). See "Text Encoding Types".
963 * @result Returns a character string, or NULL in case of a failure.
965 char *asl_format(asl_object_t msg
, const char *msg_fmt
, const char *time_fmt
, uint32_t text_encoding
) __OSX_AVAILABLE_STARTING(__MAC_10_10
, __IPHONE_7_0
);
968 * Encodes a buffer with embedded nul characters into a nul terminated C string.
969 * The result must be freed by the caller.
971 * This utility is used to encode the value associated with ASL_KEY_AUX_DATA
972 * in an ASL_TYPE_MSG object. An ASL_KEY_AUX_DATA key/value pair is used to hold the
973 * data written to a file descriptor created by asl_create_auxiliary_file on iOS
974 * systems, where the ASL database is stored in memory.
977 * (input) Pointer to a data buffer.
979 * (input) Length (in octets) of data buffer.
980 * @result Returns an encoded character string.
982 char *asl_encode_buffer(const char *buf
, size_t len
) __OSX_AVAILABLE_STARTING(__MAC_10_10
, __IPHONE_7_0
);
985 * Decodes a C string previously created by asl_encode_buffer back into a buffer,
986 * possibly containing embedded nul characters. Allocates memory for the buffer
987 * and returns a pointer in an output parameter "buf".
988 * The caller is responsible for freeing the buffer.
990 * This routine should be used to decode the value associated with an
991 * ASL_KEY_AUX_DATA key in an ASL_TYPE_MSG object.
994 * (input) Pointer to nul-terminated string created by asl_encode_buffer.
996 * (output) Pointer to a newly allocated data buffer.
998 * (input) Length (in octets) of data buffer.
999 * @result Returns 0 on success, non-zero on failure.
1001 int asl_decode_buffer(const char *in
, char **buf
, size_t *len
) __OSX_AVAILABLE_STARTING(__MAC_10_10
, __IPHONE_7_0
);
1004 * Iterate forward through messages in an asl_object_t.
1005 * The asl_object_t object maintains an internal position index for the underlying
1006 * collection of ASL messages, whether the asl_object_t represents a list, a
1007 * data file, or an ASL database. The position index is moved forward and the
1008 * "next" message is returned.
1011 * (input) An asl_object_t.
1012 * @result Returns the next message (an object of type ASL_TYPE_MSG or ASL_TYPE_QUERY) from the object,
1013 * which should be of type ASL_TYPE_CLIENT, ASL_TYPE_LIST, ASL_TYPE_STORE, or ASL_TYPE_FILE.
1014 * Returns NULL when there are no more messages or if obj is not a type that holds messages.
1016 asl_object_t
asl_next(asl_object_t obj
) __OSX_AVAILABLE_STARTING(__MAC_10_10
, __IPHONE_7_0
);
1019 * Iterate backwards through messages in an asl_object_t.
1020 * The asl_object_t object maintains an internal position index for the underlying
1021 * collection of ASL messages, whether the asl_object_t represents a list, a
1022 * data file, or an ASL database. The position index is moved backward and the
1023 * "previous" message is returned.
1026 * (input) An asl_object_t.
1027 * @result Returns the previous message (an object of type ASL_TYPE_MSG or ASL_TYPE_QUERY) from the object,
1028 * which should be of type ASL_TYPE_CLIENT, ASL_TYPE_LIST, ASL_TYPE_STORE, or ASL_TYPE_FILE.
1029 * Returns NULL when there are no more messages or if obj is not a type that holds messages.
1031 asl_object_t
asl_prev(asl_object_t obj
) __OSX_AVAILABLE_STARTING(__MAC_10_10
, __IPHONE_7_0
);
1034 * Reset internal interation index in an asl_object_t.
1037 * (input) An object of type ASL_TYPE_CLIENT, ASL_TYPE_LIST, ASL_TYPE_STORE, or ASL_TYPE_FILE.
1039 * (input) Use 0 to position the internal interation index at the beginning of the asl_object_t object,
1040 * and SIZE_MAX to position it at the end. Other values of position may cause unpredictable behavior.
1042 void asl_reset_iteration(asl_object_t obj
, size_t position
) __OSX_AVAILABLE_STARTING(__MAC_10_10
, __IPHONE_7_0
);
1045 * Searches an asl_object_t.
1046 * The search is controlled by a list of queries, and returns a list with matching messages.
1047 * A message is returned if it matches any of the queries in the query list.
1048 * A NULL querylist matches anything.
1050 * The caller may provide a starting ASL message ID, a direction, and a count.
1051 * A start ID value of 0 means that matching should commence at the beginning of the target obj.
1052 * A value of SIZE_MAX indicates that matching should commence at the end (most recent message)
1053 * in the target. If a non-zero count value is supplied, the routine will return when it has
1054 * found that many messages, or it has checked all messages. If a non-zero duration is supplied,
1055 * the routine will return after the specified time (in microseconds).
1056 * If both count and duration are non-zero, the routine will return when the desired number of
1057 * items has been matched or when the specified duration has been exceeded, whichever occurs first.
1058 * The search direction may be ASL_MATCH_DIRECTION_FORWARD or ASL_MATCH_DIRECTION_REVERSE.
1059 * The routine sets the value of the out parameter last to be an index of the last message
1060 * checked while matching. To fetch matching messages in batches (using a small count or
1061 * duration value), the start value for each iteration should be set to (last + 1) if searching
1062 * forward, or (last - 1)for reverse search.
1065 * (input) An asl_object_t object.
1067 * (input) An asl_object_t object containing zero or more queries.
1069 * (output) An internal position index of the last message checked while matching in the asl_object_t object.
1071 * (input) A position index specifying where matching should commence.
1073 * (input) The maximum number of messages to be returned in the res output list (zero indicates no limit).
1075 * (input) A limit (in microseconds) on the time to be spent searching for results. Zero indicates no time limit.
1077 * (input) ASL_MATCH_DIRECTION_FORWARD or ASL_MATCH_DIRECTION_REVERSE.
1078 * @result Returns an ASL object containing messages matching the querylist, or NULL if there are no matches.
1080 asl_object_t
asl_match(asl_object_t data
, asl_object_t querylist
, size_t *last
, size_t start
, size_t count
, uint32_t duration
, int32_t direction
) __OSX_AVAILABLE_STARTING(__MAC_10_10
, __IPHONE_7_0
);
1084 #endif /* __ASL_H__ */