1 .\"Copyright (c) 2004-2008 Apple Inc. All rights reserved.
3 .\"@APPLE_LICENSE_HEADER_START@
5 .\"This file contains Original Code and/or Modifications of Original Code
6 .\"as defined in and that are subject to the Apple Public Source License
7 .\"Version 2.0 (the 'License'). You may not use this file except in
8 .\"compliance with the License. Please obtain a copy of the License at
9 .\"http://www.opensource.apple.com/apsl/ and read it before using this
12 .\"The Original Code and all software distributed under the License are
13 .\"distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 .\"EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 .\"INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 .\"FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
17 .\"Please see the License for the specific language governing rights and
18 .\"limitations under the License.
20 .\"@APPLE_LICENSE_HEADER_END@
27 .Nd Apple System Log utility
61 .Fl x Ar file Ar expression
64 .Fl c Ar process Op filter
67 is a command-line utility for a variety of tasks relating to the Apple System Log (ASL) facility.
68 It provides mechanisms for sending and viewing log messages,
69 copying log messages to ASL format data store files,
70 and for controlling the flow of log messages from client processes.
76 prints a usage message.
80 option is used send log messages to the
83 either locally or to a remote server if the
87 There are two main forms of the command.
90 option is used, then it must be followed by a list of keys and values.
91 A structured message will be sent to the server with the keys and values given as arguments.
92 If a key or a value has embedded white space, it must be enclosed in quotes.
94 Note that the text of the log message should be supplied as a value following the
100 option is not specified, then the rest of the command line is treated as the message text.
101 The text may be preceded by
103 to set the log level (priority) of the message.
104 Levels may be an integer value corresponding the the log levels specified in
108 or they may be a string.
109 String values are case insensitive, and should be one of:
137 option is omitted, the log level defaults to 7 (Debug).
140 only requires one or two leading characters for a level specification.
141 A single character suffices in most cases.
146 for Panic / Emergency, and
154 daemon filters and saves log messages to different output streams.
155 One module saves messages to files specified in the
158 Those log files may be examined with any file printing or editing utility,
161 .Dl cat /var/log/system.log
163 Another module saves messages in a data store (/var/log/asl).
165 If invoked with no arguments,
167 fetchs all messages from the active data store.
168 Messages are then printed to standard output,
169 subject to formatting options and character encoding as described below.
170 Some log messages are read-access controlled,
171 so only messages that are readable by the user running
173 will be fetched and printed.
179 fetches and prints console messages.
182 option is actually an alias for the expression:
184 .Dl -k Facility com.apple.console
186 See the EXPRESSIONS section below for more details.
188 Individual ASL data store files may be read by providing one or more file names as arguments to the
191 This may be useful when searching archived files, files on alternate disk volumes,
192 or files created as export files with the
198 option may be followed by a list of directory paths.
200 will read or search all ASL data store files in those directories.
201 Any files that are not readable will be skipped.
206 will open all readable files in the default ASL archive directory /var/log/asl.archive.
211 will open all readable files in the ASL store directory /var/log/asl.
213 Legacy ASL database files that were written by
215 on Mac OS X 10.5 (Leopard) may also be read using the
218 However only one such legacy database may be read or searched at a time.
219 Note that a legacy database may be read and copied into a new ASL data store format file using a combination of
229 to wait for new messages.
232 prints the last 10 messages,
233 then waits for new messages to be added to the data store.
234 A number following the
236 option specifies the number of messages to print and overrides the default value of 10.
241 This usage is similar to watching a log file using, e.g.
243 .Dl tail -f /var/log/system.log
247 option can only be used when reading the system's ASL data store or when reading a single data store file,
248 and when printing messages to standard output.
252 option is specified, messages are copied to the named file rather than being printed.
253 The file will be created if it does not exist.
255 When called without the
257 option, messages are printed to standard output.
258 Messages are printed in a format similar to that used in the system.log file,
259 except that the message priority level is printed between angle-brackets.
261 The output format may by changed by specifying the
264 Non-printable and control characters are encoded by default.
265 Text encoding may be controlled using the
270 may be one of the following:
272 .Bl -tag -width "xxxx"
276 daemon for system log files, e.g. /var/log/system.log.
278 Standard (default) format.
281 but includes the message priority level.
283 Prints the complete message structure.
284 Each key/value pair is enclosed in square brackets.
285 Embedded closing brackets and white space are escaped.
286 Time stamps are printed as seconds since the epoch by default, but may also be
287 printed in local time or UTC if the
289 option is specified (see below).
291 The list of messages is printed as an XML property list.
292 Each message is represented as a dictionary in a array.
293 Dictionary keys represent message keys.
294 Dictionary values are strings.
299 argument may also be a custom print format string.
300 A custom format should in most cases be enclosed in single quotes to prevent the shell from substituting
301 special characters and breaking at white space.
303 Custom format strings may include variables of the form
307 if the variable is not delimited by whitespace)
308 which will be expanded to the associated with the named key.
309 For example, the command:
311 .Dl syslog -F '$Time $Host $(Sender)[$(PID)]: $Message'
313 produces output similar to the
317 Timestamps may be printed in three formats.
318 Times are generally converted to local time, except when the
320 option is used, in which case times are printed as the number of seconds since the epoch.
323 option may be used to explicity control the format used for timestamps.
326 may be one of the following:
328 .Bl -tag -width "local"
330 Times are printed as the number of seconds since the epoch.
332 Times are converted to the local time zone, and printed with the format
335 Times are converted to UTC, and printed with the format
336 .Dl YYYY.MM.DD HH:MM:SS UTC
341 option is a short form for
344 By default, control characters and non-printable characters are encoded in the output stream.
345 In some cases this may make messages less natural in appearance.
346 The encoding is designed to preserve all the information in the log message,
347 and to prevent malicious users from spoofing or obsucring information in log messages.
354 formats is encoded as it is by the
359 Newlines and tabs are also encoded as "\\n" and "\\t" respectively.
362 format, space characters embedded in log message keys are encoded as "\\s"
363 and embedded brackets are escaped to print as "\\[" and "\\]".
365 XML format output requires that keys are valid UTF8 strings.
366 Keys which are not valid UTF8 are ignored, and the associated value is not printed.
368 Values that contain legal UTF8 are printed as strings.
369 Ampersand, less than, greater than, quotation mark, and apostrophe characters are encoded according to XML conventions.
370 Embedded control characters are encoded as
372 where NN is the character's hexidecimal value.
374 Values that do not contain legal UTF8 are encoded in base-64 and printed as data objects.
378 option may be used to explicity control the text encoding.
381 may be one of the following:
383 .Bl -tag -width "safe"
385 The default encoding described above.
387 Encodes backspace characters as ^H.
388 Carriage returns are mapped to newlines.
389 A tab character is appended after newlines so that message text is indented.
396 encoding is to prevent obvious message spoofing or damage.
397 The appearance of messages printed will depend on terminal settings and UTF-8 string handling.
398 It is possible that messages printed using the
402 options may be garbled or subject to manipulation through the use of control characters and control sequences
403 embedded in user-supplied message text.
406 encoding should be used to view messages if there is any suspicion
407 that message text may have been used to manipulate the printed representation.
409 If no further command line options are specified,
411 displays all messages, or copies all messages to a data store file.
412 However, an expression may be specified using the
418 Expressions specify matching criteria.
419 They may be used to search for messages of interest.
424 .Dl -k key [[op] val]
428 option may be followed by one, two, or three arguments.
429 A single argument causes a match to occur if a message has the specified key, regardless of value.
430 If two arguments are specified, a match occurs when a message has exactly the specified value for a given key.
431 For example, to find all messages sent by the portmap process:
433 .Dl syslog -k Sender portmap
437 option is treated as an alias for the expression:
439 .Dl -k Facility com.apple.console
441 This provides a quick way to search for console messages.
443 If three arguments are given, they are of the form
444 .Fl k Ar key operation value .
446 supports the following matching operators:
448 .Bl -tag -width "xxx" -compact
456 greater than or equal to
460 less than or equal to
463 Additionally, the operator may be preceded by one or more of the following modifiers:
465 .Bl -tag -width "xxx" -compact
469 regular expression (see
481 More complex search expressions may be built by combining two or more simple expressions.
482 A complex expression that has more than one
483 .Dq -k key [[op] val]
484 term matches a message if all of the key-value operations match.
485 Logically, the result is an AND of all of key-value operations.
488 .Dl syslog -k Sender portmap -k Time ge -2h
490 finds all messages sent by portmap in the last 2 hours
491 (-2h means "two hours ago").
495 option may be used to build even more complex searches by providing an OR operation.
496 If two or more sub-expressions are given, separated by
498 options, then a match occurs is a message matches any of the sub-expressions.
499 For example, to find all messages which have either a
503 or that have a numeric priority level of 4 or less:
505 .Dl syslog -k Sender portmap -o -k Level Nle 4
507 Log priority levels are internally handled as an integer value between 0 and 7.
508 Level values in expressions may either be given as integers, or as string equivalents.
509 See the table string values in the SENDING MESSAGES section for details.
510 The example query above could also be specified with the command:
512 .Dl syslog -k Sender portmap -o -k Level Nle warning
515 A special convention exists for matching time stamps.
516 An unsigned integer value is regarded as the given number of seconds since
517 0 hours, 0 minutes, 0 seconds, January 1, 1970, Coordinated Universal Time.
518 An negative integer value is regarded as the given number of seconds before the current time.
519 For example, to find all messages of Error priority level (3) or less which were logged in the last 30 seconds:
521 .Dl syslog -k Level Nle error -k Time ge -30
523 a relative time value may be optionally followed by one of the characters
530 to specify seconds, minutes, hours, days, or weeks respectively.
531 Upper case may be used equivalently.
532 A week is taken to be 7 complete days (i.e. 604800 seconds).
533 .Ss FILTERING CONTROLS
534 Clients of the Apple System Log facility using either the
538 interfaces may specify a log filter mask.
539 The mask specifies which messages should be sent to the
541 daemon by specifying a yes/no setting for each priority level.
542 Many clients set a filter mask to avoid sending relatively unimportant messages.
543 Debug or Info priority level messages are generally only useful for debugging operations.
544 By setting a filter mask, a process can improve performance by avoiding spending
545 time sending messages that are in most cases unnecessary.
549 option may be used to control filtering.
550 In addition to the internal filter value that processes may set as described above,
551 the system maintains a global
554 This filter is normally
556 meaning that it has no effect.
557 If a value is set for the master filter, it overrides the local filter for all processes.
558 Root user access is required to set the master filter value.
560 The current setting of the master filter mask may be inspected using:
564 The value of the master filter mask my be set by providing a second argument following
566 The value may a set of characters from the set
568 These correspond to the priority levels Emergency (Panic), Alert, Critical, Error, Warning, Notice, Info, and Debug.
571 may be used for Error, as it is used for sending messages.
572 The master filter may be unset with:
576 Since it is common to use the filter as a
578 mechanism, for example to cut off messages with Debug and Info priority,
579 a single character from the list above may be specified, preceded by a minus sign.
582 uses a filter mask starting at level 0 (Emergency)
585 For example, to set the master filter level to cause all processes to log messages from Emergency up to Debug:
589 While the master filter level may be set to control the messages produced by all processes,
590 another filter mask may be specified for an individual process.
591 If a per-process filter mask is set, it overrides both the local filter mask and the master filter mask.
592 The current setting for a per-process filter mask may be inspected using
596 is either a PID or the name of a process.
597 If a name is used, it must uniquely identify a process.
598 To set a per-process filter mask, an second argument may be supplied following
600 as described above for the master filter mask.
601 Root access is required to set the per-process filter mask for system (UID 0) processes.
603 The filtering described above takes place in the client library to determine which messages are sent to the
606 The daemon also contains filters which determines which messages are saved in the data store.
607 This determines which messages are seen when reading messages using the
609 utility, or when viewing data store messages in the Console utility application.
611 The default data store filter mask permits all messages with priority levels from Emergency to Debug (level 0 to 7).
612 The level may be inspected using:
614 .Dl syslog -c syslogd
616 To set the data store filter mask, an second argument may be supplied following
619 For example, to save messages with priority level Error or less in the data store:
621 .Dl syslog -c syslog -e
625 server also follows filtering rules specified in the /etc/asl.conf file.
626 When the remote-control mechanism is used to change the filter of a process,
628 will save any messages received from that process until the remote-control filter is turned off.
629 It is no longer necessary to adjust the filtering for both a process and for
631 to have messages saved in the ASL data store.
640 utility appeared in Mac OS X 10.4.