1 .\" Copyright (c) 2004 Apple Computer
2 .\" All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
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.
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
34 .Nd Apple System Log utility
57 .Op Fl db Op Ar file ...
64 .Op Fl db Op Ar file ...
68 .Op Fl db Op Ar file ...
72 .Fl c Ar process Op filter
75 is a command-line utility for a variety of tasks relating to the Apple System Log facility.
76 It provides mechanisms for sending and viewing log messages,
77 pruning the contents of the log message databases,
78 and for controlling the flow of log messages from client processes.
84 prints a usage message.
88 option is used send log messages to the
91 either locally or to a remote server if the
95 There are two main forms of the command.
98 option is used, then it must be followed by a list of keys and values.
99 A structured message will be sent to the server with the keys and values given as arguments.
100 If a key or a value has embedded white space, it must be enclosed in quotes.
104 option is not specified, then the rest of the command line is treated as the message text.
105 The text may be preceded by
107 to set the log level (priority) of the message.
108 Levels may be an integer value corresponding the the log levels specified in
112 or they may be a string.
113 String values are case insensitive, and should be one of:
141 option is omitted, the log level defaults to 7 (Debug).
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 an active database,
168 and may also be configured to keep archive databases.
170 If invoked with no arguments,
174 to fetch all messages from the active database.
175 The messages are then printed to standard output, subject to formatting options and character encoding as described below.
181 fetches and prints console messages.
184 option is actually an alias for the expression:
186 .Dl -k Facility com.apple.console
188 See the EXPRESSIONS section below for more details.
190 If the system is running in single-user mode,
192 will open the ASL active database file (/var/log/asl.db) directly, rather than queying
195 The database file is opened in read-only mode, and read access permissions are required.
198 option with no argument also forces raw database access.
200 Archive log databases may be read by providing one or more database names as arguments to the
203 Each database is read in sequence.
204 As a special case, the name
206 may be used in place of a database file name.
211 and query for the contents of the active database.
217 to wait for new messages.
220 prints the last 10 messages,
221 then waits for new messages to be added to the database.
222 A number following the
224 option specifies the number of messages to print and overrides the default value of 10.
229 This usage is similar to watching a log file using, e.g.
231 .Dl tail -f /var/log/system.log
235 option can only be used for a single database, and when printing messages to standard output.
239 option is specified, messages are copied to the named
241 file rather than being printed.
244 file will be created if it does not exist.
246 When called without the
248 option, messages are printed to standard output.
249 Messages are printed in a format similar to that used in the system.log file,
250 except that the message priority level is printed between angle-brackets.
252 The output format may by changed by specifying the
255 Non-printable and control characters are encoded in the output, as described below.
258 may be one of the following:
260 .Bl -tag -width "xxxx"
264 daemon for system log files, e.g. /var/log/system.log.
266 Standard (default) format.
269 but includes the message priority level.
271 Prints the complete message structure.
272 Each key/value pair is enclosed in square brackets.
273 Embedded closing brackets and white space are escaped.
274 Time stamps are printed as seconds since the epoch by default, but may also be
275 printed in local time or UTC if the
277 option is specified (see below).
279 The list of messages is printed as an XML property list.
280 Each message is represented as a dictionary in a array.
281 Dictionary keys represent message keys.
282 Dictionary values are strings.
287 argument may also be a custom print format string.
288 A custom format should in most cases be enclosed in single quotes to prevent the shell from substituting
289 special characters and breaking at white space.
291 Custom format strings may include variables of the form
295 if the variable is not delimited by whitespace)
296 which will be expanded to the associated with the named key.
297 For example, the command:
299 .Dl syslog -F '$Time $Host $(Sender)[$(PID)]: $Message'
301 produces output similar to the
305 Timestamps may be printed in three formats.
306 Times are generally converted to local time, except when the
308 option is used, in which case times are printed as the number of seconds since the epoch.
311 option may be used to explicity control the format used for timestamps.
314 may be one of the following:
316 .Bl -tag -width "local"
318 Times are printed as the number of seconds since the epoch.
320 Times are converted to the local time zone, and printed with the format
323 Times are converted to UTC, and printed with the format
324 .Dl YYYY.MM.DD HH:MM:SS UTC
329 option is a short form for
332 Control characters and non-printable characters are encoded in the output stream.
333 In some cases this may make messages slightly less natural in appearance.
334 However, the encoding is designed to preserve all the information in the log message,
335 and to prevent malicious users from spoofing or obsucring information in log messages.
342 formats is encoded as it is by the
347 Newlines and tabs are also encoded as "\\n" and "\\t" respectively.
350 format, space chanacters embedded in log message keys are encoded as "\\s"
351 and embedded brackets are escaped to print as "\\[" and "\\]".
353 XML format output requires that keys are valid UTF8 strings.
354 Keys which are not valid UTF8 are ignored, and the associated value is not printed.
356 Values that contain legal UTF8 are printed as strings.
357 Ampersand, less than, greater than, quotation mark, and apostrophe characters are encoded according to XML conventions.
358 Embedded control characters are encoded as
360 where NN is the character's hexidecimal value.
362 Values that do not contain legal UTF8 are encoded in base-64 and printed as data objects.
364 If no further command line options are specified,
366 displays all messages, or copies all messages to a database file.
367 However, an expression may be specified using the
373 Expressions specify matching criteria.
374 They may be used to search for messages of interest.
375 Expressions are also required when pruning the system log file with the
379 A simple expression is a list of one or more key/value pairs.
380 A match is made when a message has the given value for the specified key.
381 For example, to find all messages sent by the portmap process:
383 .Dl syslog -k Sender portmap
387 option is treated as an alias for the expression:
389 .Dl -k Facility com.apple.console
391 This provides a quick way to search for console messages.
395 option may be followed by one, two, or three arguments.
396 A single argument causes a match to occur if a message has the specified key, regardless of value.
397 If a pair of arguments is specified, a match occurs when a message has exactly the specified value for a given key.
398 If three arguments are given, they are of the form
399 .Fl k Ar key operation value .
401 supports the following matching operators:
403 .Bl -tag -width "xxx" -compact
411 greater than or equal to
415 less than or equal to
418 Additionally, the operator may be preceded by one or more of the following modifiers:
420 .Bl -tag -width "xxx" -compact
424 regular expression (see
436 An simple expression matches a message if all of the key-value operations match.
437 Logically, the result is an AND of all of key-value operations.
440 option separates simple expressions and provides an OR operation.
441 If two or more simple expressions are given, separated by
443 options, then a match occurs is a message matches any of the simple expressions.
444 For example, to find all messages which have either a
448 or that have a numeric priority level of 4 or less:
450 .Dl syslog -k Sender portmap -o -k Level Nle 4
452 A special convention exists for matching time stamps.
453 An unsigned integer value is regarded as the given number of seconds since
454 0 hours, 0 minutes, 0 seconds, January 1, 1970, Coordinated Universal Time.
455 An negative integer value is regarded as the given number of seconds before the current time.
456 For example, to find all messages of priority level 3 (error) or less which were logged in the last 30 seconds:
458 .Dl syslog -k Level Nle 3 -k Time ge -30
460 a relative time value may be optionally followed by one of the characters
467 to specify seconds, minutes, hours, days, or weeks respectively.
468 Upper case may be used equivalently.
469 A week is taken to be 7 complete days (i.e. 604800 seconds).
471 The Apple System Log facility saves received messages, subject to filtering criteria described in the
472 FILTERING CONTROLS section below.
475 daemon deletes messages after given time-to-live values to prevent the database from growing too large.
476 When messages expire, they are either removed entirely, or copied to an archive database.
479 manual for more details on archiving messages.
481 Messages may be removed from either the active database or from an archive database by using the
487 option must be followed by an expression (see above).
488 Messages that match the expression are deleted.
492 option is not specified
496 to perform the requested pruning operation.
499 is given without a database file name,
501 prunes the active database file.
502 This may only be done if the
504 server is not running.
505 If one or more database file names are given, those databases are pruned subject to the specified expression.
506 Read and write access to the database files are required.
507 .Ss FILTERING CONTROLS
508 Clients of the Apple System Log facility using either the
512 interfaces may specify a log filter mask.
513 The mask specifies which messages should be sent to the
515 daemon by specifying a yes/no setting for each priority level.
516 Many clients set a filter mask to avoid sending relatively unimportant messages.
517 Debug or Info priority level messages are generally only useful for debugging operations.
518 By setting a filter mask, a process can improve performance by avoiding spending
519 time sending messages that are in most cases unnecessary.
523 option may be used to control filtering.
524 In addition to the internal filter value that processes may set as described above,
525 the system maintains a global
528 This filter is normally
530 meaning that it has no effect.
531 If a value is set for the master filter, it overrides the local filter for all processes.
532 Root user access is required to set the master filter value.
534 The current setting of the master filter mask may be inspected using:
538 The value of the master filter mask my be set by providing a second argument following
540 The value may a set of characters from the set
542 These correspond to the priority levels Emergency (Panic), Alert, Critical, Error, Warning, Notice, Info, and Debug.
545 may be used for Error, as it is used for sending messages.
546 The master filter may be unset with:
550 Since it is common to use the filter as a
552 mechanism, for example to cut off messages with Debug and Info priority,
553 a single character from the list above may be specified, preceded by a minus sign.
556 uses a filter mask starting at level 0 (Emergency)
559 For example, to set the master filter level to cause all processes to log messages from Emergency up to Debug:
563 While the master filter level may be set to control the messages produced by all processes,
564 another filter mask may be specified for an individual process.
565 If a per-process filter mask is set, it overrides both the local filter mask and the master filter mask.
566 The current setting for a per-process filter mask may be inspected using
570 is either a PID or the name of a process.
571 If a name is used, it must uniquely identify a process.
572 To set a per-process filter mask, an second argument may be supplied following
574 as described above for the master filter mask.
575 Root access is required to set the per-process filter mask for system (UID 0) processes.
577 The filtering described above takes place in the client library to determine which messages are sent to the
580 The daemon also contains a filter which determines which messages are saved in the data store.
581 Note that this additionally determines which messages are seen when reading messages using the
585 The default data store filter mask saves messages with priority levels from Emergency to Notice (level 0 to 5).
586 The level may be inspected using:
588 .Dl syslog -c syslogd
590 To set the data store filter mask, an second argument may be supplied following
593 For example, to save messages with priority level Error or less in the data store:
595 .Dl syslog -c syslog -e
604 utility appeared in Mac OS X 10.4.