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).
138 Note that the log message server
140 filters messages based on log level.
141 The default filter for the ASL database excludes Debug and Info level messages.
144 only requires one or two leading characters for a level specification.
145 A single character suffices in most cases.
150 for Panic / Emergency, and
158 daemon filters and saves log messages to different output streams.
159 One module saves messages to files specified in the
162 Those log files may be examined with any file printing or editing utility,
165 .Dl cat /var/log/system.log
167 Another module saves messages in a data store (/var/log/asl).
169 If invoked with no arguments,
171 fetchs all messages from the active data store.
172 Messages are then printed to standard output,
173 subject to formatting options and character encoding as described below.
174 Some log messages are read-access controlled,
175 so only messages that are readable by the user running
177 will be fetched and printed.
183 fetches and prints console messages.
186 option is actually an alias for the expression:
188 .Dl -k Facility com.apple.console
190 See the EXPRESSIONS section below for more details.
192 Individual ASL data store files may be read by providing one or more file names as arguments to the
195 This may be useful when searching archived files, files on alternate disk volumes,
196 or files created as export files with the
202 option may be followed by a list of directory paths.
204 will read or search all ASL data store files in those directories.
205 Any files that are not readable will be skipped.
210 will open all readable files in the default ASL archive directory /var/log/asl.archive.
215 will open all readable files in the ASL store directory /var/log/asl.
217 Legacy ASL database files that were written by
219 on Mac OS X 10.5 (Leopard) may also be read using the
222 However only one such legacy database may be read or searched at a time.
223 Note that a legacy database may be read and copied into a new ASL data store format file using a combination of
233 to wait for new messages.
236 prints the last 10 messages,
237 then waits for new messages to be added to the data store.
238 A number following the
240 option specifies the number of messages to print and overrides the default value of 10.
245 This usage is similar to watching a log file using, e.g.
247 .Dl tail -f /var/log/system.log
251 option can only be used when reading the system's ASL data store or when reading a single data store file,
252 and when printing messages to standard output.
256 option is specified, messages are copied to the named file rather than being printed.
257 The file will be created if it does not exist.
259 When called without the
261 option, messages are printed to standard output.
262 Messages are printed in a format similar to that used in the system.log file,
263 except that the message priority level is printed between angle-brackets.
265 The output format may by changed by specifying the
268 Non-printable and control characters are encoded by default.
269 Text encoding may be controlled using the
274 may be one of the following:
276 .Bl -tag -width "xxxx"
280 daemon for system log files, e.g. /var/log/system.log.
282 Standard (default) format.
285 but includes the message priority level.
287 Prints the complete message structure.
288 Each key/value pair is enclosed in square brackets.
289 Embedded closing brackets and white space are escaped.
290 Time stamps are printed as seconds since the epoch by default, but may also be
291 printed in local time or UTC if the
293 option is specified (see below).
295 The list of messages is printed as an XML property list.
296 Each message is represented as a dictionary in a array.
297 Dictionary keys represent message keys.
298 Dictionary values are strings.
303 argument may also be a custom print format string.
304 A custom format should in most cases be enclosed in single quotes to prevent the shell from substituting
305 special characters and breaking at white space.
307 Custom format strings may include variables of the form
311 if the variable is not delimited by whitespace)
312 which will be expanded to the associated with the named key.
313 For example, the command:
315 .Dl syslog -F '$Time $Host $(Sender)[$(PID)]: $Message'
317 produces output similar to the
321 Timestamps may be printed in three formats.
322 Times are generally converted to local time, except when the
324 option is used, in which case times are printed as the number of seconds since the epoch.
327 option may be used to explicity control the format used for timestamps.
330 may be one of the following:
332 .Bl -tag -width "local"
334 Times are printed as the number of seconds since the epoch.
336 Times are converted to the local time zone, and printed with the format
339 Times are converted to UTC, and printed with the format
340 .Dl YYYY.MM.DD HH:MM:SS UTC
345 option is a short form for
348 By default, control characters and non-printable characters are encoded in the output stream.
349 In some cases this may make messages less natural in appearance.
350 The encoding is designed to preserve all the information in the log message,
351 and to prevent malicious users from spoofing or obsucring information in log messages.
358 formats is encoded as it is by the
363 Newlines and tabs are also encoded as "\\n" and "\\t" respectively.
366 format, space characters embedded in log message keys are encoded as "\\s"
367 and embedded brackets are escaped to print as "\\[" and "\\]".
369 XML format output requires that keys are valid UTF8 strings.
370 Keys which are not valid UTF8 are ignored, and the associated value is not printed.
372 Values that contain legal UTF8 are printed as strings.
373 Ampersand, less than, greater than, quotation mark, and apostrophe characters are encoded according to XML conventions.
374 Embedded control characters are encoded as
376 where NN is the character's hexidecimal value.
378 Values that do not contain legal UTF8 are encoded in base-64 and printed as data objects.
382 option may be used to explicity control the text encoding.
385 may be one of the following:
387 .Bl -tag -width "safe"
389 The default encoding described above.
391 Encodes backspace characters as ^H.
392 Carriage returns are mapped to newlines.
393 A tab character is appended after newlines so that message text is indented.
400 encoding is to prevent obvious message spoofing or damage.
401 The appearance of messages printed will depend on terminal settings and UTF-8 string handling.
402 It is possible that messages printed using the
406 options may be garbled or subject to manipulation through the use of control characters and control sequences
407 embedded in user-supplied message text.
410 encoding should be used to view messages if there is any suspicion
411 that message text may have been used to manipulate the printed representation.
413 If no further command line options are specified,
415 displays all messages, or copies all messages to a data store file.
416 However, an expression may be specified using the
422 Expressions specify matching criteria.
423 They may be used to search for messages of interest.
428 .Dl -k key [[op] val]
432 option may be followed by one, two, or three arguments.
433 A single argument causes a match to occur if a message has the specified key, regardless of value.
434 If two arguments are specified, a match occurs when a message has exactly the specified value for a given key.
435 For example, to find all messages sent by the portmap process:
437 .Dl syslog -k Sender portmap
441 option is treated as an alias for the expression:
443 .Dl -k Facility com.apple.console
445 This provides a quick way to search for console messages.
447 If three arguments are given, they are of the form
448 .Fl k Ar key operation value .
450 supports the following matching operators:
452 .Bl -tag -width "xxx" -compact
460 greater than or equal to
464 less than or equal to
467 Additionally, the operator may be preceded by one or more of the following modifiers:
469 .Bl -tag -width "xxx" -compact
473 regular expression (see
485 More complex search expressions may be built by combining two or more simple expressions.
486 A complex expression that has more than one
487 .Dq -k key [[op] val]
488 term matches a message if all of the key-value operations match.
489 Logically, the result is an AND of all of key-value operations.
492 .Dl syslog -k Sender portmap -k Time ge -2h
494 finds all messages sent by portmap in the last 2 hours
495 (-2h means "two hours ago").
499 option may be used to build even more complex searches by providing an OR operation.
500 If two or more sub-expressions are given, separated by
502 options, then a match occurs is a message matches any of the sub-expressions.
503 For example, to find all messages which have either a
507 or that have a numeric priority level of 4 or less:
509 .Dl syslog -k Sender portmap -o -k Level Nle 4
511 A special convention exists for matching time stamps.
512 An unsigned integer value is regarded as the given number of seconds since
513 0 hours, 0 minutes, 0 seconds, January 1, 1970, Coordinated Universal Time.
514 An negative integer value is regarded as the given number of seconds before the current time.
515 For example, to find all messages of priority level 3 (error) or less which were logged in the last 30 seconds:
517 .Dl syslog -k Level Nle 3 -k Time ge -30
519 a relative time value may be optionally followed by one of the characters
526 to specify seconds, minutes, hours, days, or weeks respectively.
527 Upper case may be used equivalently.
528 A week is taken to be 7 complete days (i.e. 604800 seconds).
529 .Ss FILTERING CONTROLS
530 Clients of the Apple System Log facility using either the
534 interfaces may specify a log filter mask.
535 The mask specifies which messages should be sent to the
537 daemon by specifying a yes/no setting for each priority level.
538 Many clients set a filter mask to avoid sending relatively unimportant messages.
539 Debug or Info priority level messages are generally only useful for debugging operations.
540 By setting a filter mask, a process can improve performance by avoiding spending
541 time sending messages that are in most cases unnecessary.
545 option may be used to control filtering.
546 In addition to the internal filter value that processes may set as described above,
547 the system maintains a global
550 This filter is normally
552 meaning that it has no effect.
553 If a value is set for the master filter, it overrides the local filter for all processes.
554 Root user access is required to set the master filter value.
556 The current setting of the master filter mask may be inspected using:
560 The value of the master filter mask my be set by providing a second argument following
562 The value may a set of characters from the set
564 These correspond to the priority levels Emergency (Panic), Alert, Critical, Error, Warning, Notice, Info, and Debug.
567 may be used for Error, as it is used for sending messages.
568 The master filter may be unset with:
572 Since it is common to use the filter as a
574 mechanism, for example to cut off messages with Debug and Info priority,
575 a single character from the list above may be specified, preceded by a minus sign.
578 uses a filter mask starting at level 0 (Emergency)
581 For example, to set the master filter level to cause all processes to log messages from Emergency up to Debug:
585 While the master filter level may be set to control the messages produced by all processes,
586 another filter mask may be specified for an individual process.
587 If a per-process filter mask is set, it overrides both the local filter mask and the master filter mask.
588 The current setting for a per-process filter mask may be inspected using
592 is either a PID or the name of a process.
593 If a name is used, it must uniquely identify a process.
594 To set a per-process filter mask, an second argument may be supplied following
596 as described above for the master filter mask.
597 Root access is required to set the per-process filter mask for system (UID 0) processes.
599 The filtering described above takes place in the client library to determine which messages are sent to the
602 The daemon also contains a filter which determines which messages are saved in the data store.
603 Note that this additionally determines which messages are seen when reading messages using the
607 The default data store filter mask saves messages with priority levels from Emergency to Notice (level 0 to 5).
608 The level may be inspected using:
610 .Dl syslog -c syslogd
612 To set the data store filter mask, an second argument may be supplied following
615 For example, to save messages with priority level Error or less in the data store:
617 .Dl syslog -c syslog -e
626 utility appeared in Mac OS X 10.4.