The Apple System Log facility is a logging API with a simular goal to the classic unix syslog API, but with a richer interface and with an API for querying the logging system.
There is more information on the ASL library in Apple’s manual page for ASL
Note
All APIs accept unicode strings, and require them for Python 3.
The strings will be converted to the C strings expected by the C API using the UTF-8 encoding.
Note
Functions and methods raise OSError when the C API fails.
Parameters: |
|
---|
Connection to the ASL backend. These objects implement the context protocol and can be used with the “with” statement.
Parameters: | fd – A file descriptor |
---|
Log messages will be written to the file descriptor as well as to the logging subsystem.
Parameters: | fd – A file descriptor |
---|
No longer write log messages to the file descriptor. The file descriptor should be one that’s added earlier with add_log_file().
Parameters: | filter – an integer with the levels that should be sent to the server |
---|
filter is an bitwise or of values from Message priority levels, and only messages whose log level is set in filter will be sent to the logging subsystem.
Returns the previous value of the filter.
Parameters: |
|
---|
Note
The C API uses a printf-style format string instead of a message. In Python you can use string formatting to format the string.
Parameters: | msg – an aslmsg object |
---|---|
Returns: | an iterator that yields the result messages. |
Send a query message to the logging subsystem.
Parameters: |
|
---|
If fd_type is ASL_LOG_DESCRIPTOR_READ ASL will read lines from the file descriptor and forward those lines to the logging subsystem as log messages.
If fd_type is ASL_LOG_DESCRIPTOR_WRITE the file descriptor is closed and reopened as a pipe where the application can write lines that will be converted to log messages.
The msg is a template for the log messages created by this API.
This method is available on OSX 10.8 or later.
Explicitly close the client.
Note
The connection will also de closed when the object is garbage collected.
Parameters: |
|
---|
This is an alias for asclient.
Parameters: |
|
---|
Opens an ASL log file for writing using an existing file descriptor, for example one returned by create_auxiliary_file(). The file descriptor must be open for reading and writing.
Avaliable on Mac OS X 10.7 or later.
Parameters: | key – An attribute name |
---|
Return the attribute value for key. The key is a unicode string.
See Standard message attributes for a list of standard attributes.
Parameters: |
|
---|
Set the value for attribute key to value. Both arguments are unicode strings.
See Standard message attributes for a list of standard attributes.
Parameters: | key – An attribute name |
---|
Remove an attribute from the message.
Parameters: |
|
---|
Add a query element to the message. The operation is ... .
A second call to set_query() for the same key will replace that query. Calls to set_query() for different values of key are combined into an AND query (that is, all query elements must match).
Note
It is not possible to perform OR queries, to do those you’ll have to fetch and merge the various subsets yourself.
Note
For basic equality tests (ASL_QUERY_OP_EQUAL) you can also set the key and value using the mapping interface. That is,
m[key] = value
is equivalent to:
m.set_query(key, value, ASL_QUERY_OP_EQUAL)
Returns the set of attribute names for this message.
Return a dict with all attributes of this message. Equivalent to:
{ k: msg[k] for k in msg.keys() }
Note
It is not possible to retrieve the “operation” for query messages, the C API doesn’t provide this information.
Parameters: | level – A message priority level |
---|
Converts one of the values from Message priority levels into a bit mask that can be used with aslclient.set_filter().
Parameters: | level – A message priority level |
---|
Returns a mask where all bits from ASL_LEVEL_DEBUG upto level are set.
Parameters: |
---|
Creates an auxiliary file that may be used to store arbitrary data associated with the mssage. Returns a file descriptor for the file. This file descriptor must be closed with close_auxiliary_file().
When uti is None the system will use “public.data” instead.
The Console.app application will show auxiliary file as an file icon that can be opened.
This function is available on Mac OS X 10.7 or later.
Parameters: |
---|
Write a log message to the logging system with a URL in the message.
When uti is None the system will use “public.data” instead.
The Console.app application will show the URL as a clickable link.
This method is available on Mac OS X 10.7 or later.
Parameters: | fd – File descriptor returned by create_auxiliary_file(). |
---|
Close the file descriptor for an auxiliary file that was created earlier with aslmsg.create_auxiliary_file(). A side effect of this is that the message is logged with the logging system.
The levels are listed from highest to lowest priority.
These are the string representation of the constants in the previous section, and are used as the value for the ASL_KEY_LEVEL key in aslmsg objects.
A directionary mapping numeric levels to the equivalent string value
A directionary mapping string levels to the equivalent integer value
String comparisons are case folded
The match is done on a leading substring
The match is done on a trailing substring
Match any substring
Perform the comparison after converting the value to an integer using the C function atoi.
Perform a regular expression match using the regex library. When the ALS_QUERY_OP_CASEFOLD modifier is specified the regular expression is compiled case insensitive (REG_ICASE). All other modifiers are ignored.
Value equality
Value greater than
Value greater than or equal to
Value less than
Value less than or equal to
Value not equal
Always true. Use this to test if an attribute is present.
These are the names of well-known attributes of ASL messages, you can add other attributes as well but those won’t be used by the ASL backend.
Timestamp. Set automatically
Nanosecond time.
Sender’s address (set by the server).
Sender’s identification string. Default is process name.
Sender’s facility. Default is “user”.
Sending process ID encoded as a string. Set automatically.
UID that sent the log message (set by the server).
GID that sent the log message (set by the server).
Log level number encoded as a string. See levels above.
Message text.
User read access (-1 is any user).
Group read access (-1 is any group).
Expiration time for messages with long TTL.
64-bit message ID number (set by the server).
Session (set by the launchd).
Reference PID for messages proxied by launchd
Reference process for messages proxied by launchd
Auxiliary title string
Auxiliary Uniform Type ID
Auxiliary Uniform Resource Locator
Auxiliary in-line data
Internal
Sender instance UUID.
These are used for client-side filtering.
Write a copy of log lines to the stderr stream.
Immediately create a connection to the logging subsystem, instead of waiting for the first log message.
Ignore the server side log filter for messages send using this connection. Using this option requires root privileges.
File descriptor is readable, ASL will read log lines from it.
File descriptor is writable. ASL will convert the file descriptor to another writable descriptor where the application can write lines that will be converted to log messages.