]> git.saurik.com Git - apple/syslog.git/blame - util.tproj/syslog.1
syslog-100.2.tar.gz
[apple/syslog.git] / util.tproj / syslog.1
CommitLineData
57b0aad2 1.\"Copyright (c) 2004-2008 Apple Inc. All rights reserved.
b16a592a 2.\"
57b0aad2 3.\"@APPLE_LICENSE_HEADER_START@
b16a592a 4.\"
57b0aad2
A
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
10.\"file.
b16a592a 11.\"
57b0aad2
A
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.
19.\"
20.\"@APPLE_LICENSE_HEADER_END@
b16a592a
A
21.\"
22.Dd October 18, 2004
23.Dt SYSLOG 1
24.Os "Mac OS X"
25.Sh NAME
26.Nm syslog
27.Nd Apple System Log utility
28.Sh SYNOPSIS
29.Nm
30.Fl help
31.D1 ""
32.Nm
33.Fl s
34.Op Fl r Ar host
35.Op Fl l Ar level
36message...
37.D1 ""
38.Nm
39.Fl s
40.Op Fl r Ar host
41.Fl k
42key val
43.Op key val
44.Li ...
45.D1 ""
46.Nm
5dd30d76
A
47.Fl C
48.D1 ""
49.Nm
57b0aad2
A
50.Op Fl f Ar file ...
51.Op Fl d Ar dir ...
5dd30d76 52.Op Fl w Op Ar n
b16a592a 53.Op Fl F Ar format
5dd30d76 54.Op Fl T Ar format
57b0aad2 55.Op Fl E Ar format
b16a592a
A
56.Ar expression
57.D1 ""
58.Nm
57b0aad2
A
59.Op Fl f Ar file ...
60.Op Fl d Ar dir ...
61.Fl x Ar file Ar expression
b16a592a
A
62.D1 ""
63.Nm
64.Fl c Ar process Op filter
65.Sh DESCRIPTION
66.Nm
57b0aad2 67is a command-line utility for a variety of tasks relating to the Apple System Log (ASL) facility.
b16a592a 68It provides mechanisms for sending and viewing log messages,
57b0aad2 69copying log messages to ASL format data store files,
b16a592a
A
70and for controlling the flow of log messages from client processes.
71.Pp
72When invoked with the
73.Fl help
74option,
75.Nm
76prints a usage message.
77.Ss SENDING MESSAGES
78The
79.Fl s
80option is used send log messages to the
81.Xr syslogd 8
82log message daemon,
83either locally or to a remote server if the
84.Fl r Ar host
85option in used.
86.Pp
87There are two main forms of the command.
88If the
89.Fl k
90option is used, then it must be followed by a list of keys and values.
91A structured message will be sent to the server with the keys and values given as arguments.
92If a key or a value has embedded white space, it must be enclosed in quotes.
93.Pp
57b0aad2
A
94Note that the text of the log message should be supplied as a value following the
95.Dq Message
96key.
97.Pp
b16a592a
A
98If the
99.Fl k
100option is not specified, then the rest of the command line is treated as the message text.
101The text may be preceded by
102.Fl l Ar level
103to set the log level (priority) of the message.
104Levels may be an integer value corresponding the the log levels specified in
105.Xr syslog 3
106or
107.Xr asl 3 ,
108or they may be a string.
109String values are case insensitive, and should be one of:
110.Pp
111.Bl -tag -compact
112.It Emergency
113(level 0)
114.It Alert
115(level 1)
116.It Critical
117(level 2)
118.It Error
119(level 3)
120.It Warning
121(level 4)
122.It Notice
123(level 5)
124.It Info
125(level 6)
126.It Debug
127(level 7)
128.El
129.Pp
130The string
131.Dq Panic
132is an alias for
133.Dq Emergency .
5dd30d76
A
134.Pp
135If the
136.Fl l
137option is omitted, the log level defaults to 7 (Debug).
138.Pp
b16a592a
A
139.Nm
140only requires one or two leading characters for a level specification.
141A single character suffices in most cases.
142Use
143.Dq P
144or
145.Dq \&Em
146for Panic / Emergency, and
147.Dq \&Er
148or
149.Dq X
150for Error).
151.Ss READING MESSAGES
152The
153.Nm syslogd
5dd30d76
A
154daemon filters and saves log messages to different output streams.
155One module saves messages to files specified in the
b16a592a
A
156.Xr syslog.conf 5
157file.
5dd30d76 158Those log files may be examined with any file printing or editing utility,
b16a592a
A
159e.g.
160.Pp
161.Dl cat /var/log/system.log
162.Pp
57b0aad2 163Another module saves messages in a data store (/var/log/asl).
b16a592a
A
164.Pp
165If invoked with no arguments,
166.Nm
57b0aad2
A
167fetchs all messages from the active data store.
168Messages are then printed to standard output,
169subject to formatting options and character encoding as described below.
170Some log messages are read-access controlled,
171so only messages that are readable by the user running
172.Nm
173will be fetched and printed.
5dd30d76
A
174.Pp
175If invoked with the
176.Fl C
177option,
178.Nm
179fetches and prints console messages.
180The
181.Fl C
182option is actually an alias for the expression:
183.Pp
184.Dl -k Facility com.apple.console
185.Pp
186See the EXPRESSIONS section below for more details.
187.Pp
57b0aad2
A
188Individual ASL data store files may be read by providing one or more file names as arguments to the
189.Fl f
190option.
191This may be useful when searching archived files, files on alternate disk volumes,
192or files created as export files with the
193.Fl x
194option.
195.Pp
196The
197.Fl d
198option may be followed by a list of directory paths.
5dd30d76 199.Nm
57b0aad2
A
200will read or search all ASL data store files in those directories.
201Any files that are not readable will be skipped.
202Specifying
203.Fl d
204with the name
205.Dq archive
206will open all readable files in the default ASL archive directory /var/log/asl.archive.
207Specifying
208.Fl d
209with the name
210.Dq store
211will open all readable files in the ASL store directory /var/log/asl.
212.Pp
213Legacy ASL database files that were written by
5dd30d76 214.Nm syslogd
57b0aad2
A
215on Mac OS X 10.5 (Leopard) may also be read using the
216.Fl f
5dd30d76 217option.
57b0aad2
A
218However only one such legacy database may be read or searched at a time.
219Note that a legacy database may be read and copied into a new ASL data store format file using a combination of
220.Fl f
221and
222.Fl x
223options.
5dd30d76
A
224.Pp
225The
b16a592a 226.Fl w
5dd30d76
A
227option causes
228.Nm
229to wait for new messages.
230By default,
b16a592a 231.Nm
5dd30d76 232prints the last 10 messages,
57b0aad2 233then waits for new messages to be added to the data store.
5dd30d76
A
234A number following the
235.Fl w
236option specifies the number of messages to print and overrides the default value of 10.
237For example:
238.Pp
239.Dl syslog -w 20
240.Pp
b16a592a
A
241This usage is similar to watching a log file using, e.g.
242.Pp
243.Dl tail -f /var/log/system.log
244.Pp
5dd30d76
A
245The
246.Fl w
57b0aad2
A
247option can only be used when reading the system's ASL data store or when reading a single data store file,
248and when printing messages to standard output.
b16a592a 249.Pp
5dd30d76 250If the
57b0aad2
A
251.Fl x Ar file
252option is specified, messages are copied to the named file rather than being printed.
253The file will be created if it does not exist.
5dd30d76
A
254.Pp
255When called without the
256.Fl x
257option, messages are printed to standard output.
258Messages are printed in a format similar to that used in the system.log file,
259except that the message priority level is printed between angle-brackets.
b16a592a
A
260.Pp
261The output format may by changed by specifying the
262.Fl F Ar format
263option.
57b0aad2
A
264Non-printable and control characters are encoded by default.
265Text encoding may be controlled using the
266.Fl E
267option (see below).
b16a592a
A
268The value of
269.Ar format
270may be one of the following:
271.Pp
272.Bl -tag -width "xxxx"
273.It bsd
274Format used by the
275.Nm syslogd
276daemon for system log files, e.g. /var/log/system.log.
277.It std
278Standard (default) format.
279Similar to
280.Dq bsd ,
281but includes the message priority level.
282.It raw
283Prints the complete message structure.
284Each key/value pair is enclosed in square brackets.
285Embedded closing brackets and white space are escaped.
5dd30d76
A
286Time stamps are printed as seconds since the epoch by default, but may also be
287printed in local time or UTC if the
288.Fl T
289option is specified (see below).
290.It xml
291The list of messages is printed as an XML property list.
292Each message is represented as a dictionary in a array.
293Dictionary keys represent message keys.
294Dictionary values are strings.
b16a592a
A
295.El
296.Pp
297The value of the
298.Ar format
299argument may also be a custom print format string.
300A custom format should in most cases be enclosed in single quotes to prevent the shell from substituting
301special characters and breaking at white space.
302.Pp
303Custom format strings may include variables of the form
304.Dq $Name
305(or
306.Dq $(Name)
307if the variable is not delimited by whitespace)
308which will be expanded to the associated with the named key.
309For example, the command:
310.Pp
311.Dl syslog -F '$Time $Host $(Sender)[$(PID)]: $Message'
312.Pp
313produces output similar to the
314.Dq bsd
315format.
316.Pp
5dd30d76
A
317Timestamps may be printed in three formats.
318Times are generally converted to local time, except when the
319.Fl F Ar sec
320option is used, in which case times are printed as the number of seconds since the epoch.
321The
322.Fl T Ar format
323option may be used to explicity control the format used for timestamps.
324The value of
325.Ar format
326may be one of the following:
327.Pp
328.Bl -tag -width "local"
329.It sec
330Times are printed as the number of seconds since the epoch.
331.It local
332Times are converted to the local time zone, and printed with the format
333.Dl MMM DD HH:MM:SS
334.It utc
335Times are converted to UTC, and printed with the format
336.Dl YYYY.MM.DD HH:MM:SS UTC
337.El
338.Pp
339The
340.Fl u
341option is a short form for
342.Fl T Ar utc .
343.Pp
57b0aad2
A
344By default, control characters and non-printable characters are encoded in the output stream.
345In some cases this may make messages less natural in appearance.
346The encoding is designed to preserve all the information in the log message,
5dd30d76
A
347and to prevent malicious users from spoofing or obsucring information in log messages.
348.Pp
57b0aad2 349Text in the
5dd30d76
A
350.Dq std ,
351.Dq bsd ,
352and
353.Dq raw
354formats is encoded as it is by the
57b0aad2 355.Nm vis
5dd30d76
A
356utility with the
357.Fl c
358option.
359Newlines and tabs are also encoded as "\\n" and "\\t" respectively.
360In
361.Dq raw
57b0aad2 362format, space characters embedded in log message keys are encoded as "\\s"
5dd30d76
A
363and embedded brackets are escaped to print as "\\[" and "\\]".
364.Pp
365XML format output requires that keys are valid UTF8 strings.
366Keys which are not valid UTF8 are ignored, and the associated value is not printed.
367.Pp
368Values that contain legal UTF8 are printed as strings.
369Ampersand, less than, greater than, quotation mark, and apostrophe characters are encoded according to XML conventions.
370Embedded control characters are encoded as
371.Dq &#xNN;
372where NN is the character's hexidecimal value.
373.Pp
374Values that do not contain legal UTF8 are encoded in base-64 and printed as data objects.
375.Pp
57b0aad2
A
376The
377.Fl E Ar format
378option may be used to explicity control the text encoding.
379The value of
380.Ar format
381may be one of the following:
382.Pp
383.Bl -tag -width "safe"
384.It vis
385The default encoding described above.
386.It safe
387Encodes backspace characters as ^H.
388Carriage returns are mapped to newlines.
389A tab character is appended after newlines so that message text is indented.
390.It none
391No encoding is used.
392.El
393.Pp
394The intent of the
395.Dq safe
396encoding is to prevent obvious message spoofing or damage.
397The appearance of messages printed will depend on terminal settings and UTF-8 string handling.
398It is possible that messages printed using the
399.Dq safe
400or
401.Dq none
402options may be garbled or subject to manipulation through the use of control characters and control sequences
403embedded in user-supplied message text.
404The default
405.Dq vis
406encoding should be used to view messages if there is any suspicion
407that message text may have been used to manipulate the printed representation.
408.Pp
b16a592a
A
409If no further command line options are specified,
410.Nm
57b0aad2 411displays all messages, or copies all messages to a data store file.
b16a592a
A
412However, an expression may be specified using the
413.Fl k
414and
415.Fl o
416options.
417.Ss EXPRESSIONS
418Expressions specify matching criteria.
5dd30d76 419They may be used to search for messages of interest.
b16a592a 420.Pp
57b0aad2
A
421A simple expression
422has the form:
423.Pp
424.Dl -k key [[op] val]
425.Pp
426The
427.Fl k
428option may be followed by one, two, or three arguments.
429A single argument causes a match to occur if a message has the specified key, regardless of value.
430If two arguments are specified, a match occurs when a message has exactly the specified value for a given key.
5dd30d76 431For example, to find all messages sent by the portmap process:
b16a592a
A
432.Pp
433.Dl syslog -k Sender portmap
434.Pp
5dd30d76
A
435Note that the
436.Fl C
437option is treated as an alias for the expression:
438.Pp
439.Dl -k Facility com.apple.console
440.Pp
441This provides a quick way to search for console messages.
442.Pp
b16a592a
A
443If three arguments are given, they are of the form
444.Fl k Ar key operation value .
445.Nm
446supports the following matching operators:
447.Pp
448.Bl -tag -width "xxx" -compact
449.It eq
450equal
451.It ne
452not equal
453.It gt
454greater than
455.It ge
456greater than or equal to
457.It lt
458less than
459.It le
460less than or equal to
461.El
462.Pp
463Additionally, the operator may be preceded by one or more of the following modifiers:
464.Pp
465.Bl -tag -width "xxx" -compact
466.It C
467case-fold
468.It R
469regular expression (see
470.Xr regex 3 )
471.It S
472substring
473.It A
474prefix
475.It Z
476suffix
477.It N
478numeric comparison
479.El
480.Pp
57b0aad2
A
481More complex search expressions may be built by combining two or more simple expressions.
482A complex expression that has more than one
483.Dq -k key [[op] val]
484term matches a message if all of the key-value operations match.
b16a592a 485Logically, the result is an AND of all of key-value operations.
57b0aad2
A
486For example:
487.Pp
488.Dl syslog -k Sender portmap -k Time ge -2h
489.Pp
490finds all messages sent by portmap in the last 2 hours
491(-2h means "two hours ago").
492.Pp
b16a592a
A
493The
494.Fl o
57b0aad2
A
495option may be used to build even more complex searches by providing an OR operation.
496If two or more sub-expressions are given, separated by
b16a592a 497.Fl o
57b0aad2 498options, then a match occurs is a message matches any of the sub-expressions.
b16a592a
A
499For example, to find all messages which have either a
500.Dq Sender
501value of
502.Dq portmap
503or that have a numeric priority level of 4 or less:
504.Pp
505.Dl syslog -k Sender portmap -o -k Level Nle 4
506.Pp
c4fdb7d1
A
507Log priority levels are internally handled as an integer value between 0 and 7.
508Level values in expressions may either be given as integers, or as string equivalents.
509See the table string values in the SENDING MESSAGES section for details.
510The example query above could also be specified with the command:
511.Pp
512.Dl syslog -k Sender portmap -o -k Level Nle warning
513.Pp
514.Pp
b16a592a
A
515A special convention exists for matching time stamps.
516An unsigned integer value is regarded as the given number of seconds since
5170 hours, 0 minutes, 0 seconds, January 1, 1970, Coordinated Universal Time.
518An negative integer value is regarded as the given number of seconds before the current time.
c4fdb7d1 519For example, to find all messages of Error priority level (3) or less which were logged in the last 30 seconds:
b16a592a 520.Pp
c4fdb7d1 521.Dl syslog -k Level Nle error -k Time ge -30
b16a592a
A
522.Pp
523a relative time value may be optionally followed by one of the characters
524.Dq s ,
525.Dq m ,
526.Dq h ,
527.Dq d ,
528or
529.Dq w
530to specify seconds, minutes, hours, days, or weeks respectively.
531Upper case may be used equivalently.
532A week is taken to be 7 complete days (i.e. 604800 seconds).
b16a592a
A
533.Ss FILTERING CONTROLS
534Clients of the Apple System Log facility using either the
535.Xr asl 3
536or
537.Xr syslog 3
538interfaces may specify a log filter mask.
539The mask specifies which messages should be sent to the
540.Nm syslogd
541daemon by specifying a yes/no setting for each priority level.
542Many clients set a filter mask to avoid sending relatively unimportant messages.
543Debug or Info priority level messages are generally only useful for debugging operations.
544By setting a filter mask, a process can improve performance by avoiding spending
545time sending messages that are in most cases unnecessary.
546.Pp
547The
548.Fl c
549option may be used to control filtering.
550In addition to the internal filter value that processes may set as described above,
551the system maintains a global
552.Dq master
553filter.
554This filter is normally
555.Dq off ,
556meaning that it has no effect.
557If a value is set for the master filter, it overrides the local filter for all processes.
558Root user access is required to set the master filter value.
559.Pp
560The current setting of the master filter mask may be inspected using:
561.Pp
562.Dl syslog -c 0
563.Pp
564The value of the master filter mask my be set by providing a second argument following
565.Fl c Ar 0 .
566The value may a set of characters from the set
567.Dq pacewnid .
568These correspond to the priority levels Emergency (Panic), Alert, Critical, Error, Warning, Notice, Info, and Debug.
569The character
570.Dq x
571may be used for Error, as it is used for sending messages.
572The master filter may be unset with:
573.Pp
574.Dl syslog -c 0 off
575.Pp
576Since it is common to use the filter as a
577.Dq cutoff
578mechanism, for example to cut off messages with Debug and Info priority,
579a single character from the list above may be specified, preceded by a minus sign.
580In this case,
581.Nm
582uses a filter mask starting at level 0 (Emergency)
583.Dq up to
584the given level.
585For example, to set the master filter level to cause all processes to log messages from Emergency up to Debug:
586.Pp
587.Dl syslog -c 0 -d
588.Pp
589While the master filter level may be set to control the messages produced by all processes,
590another filter mask may be specified for an individual process.
591If a per-process filter mask is set, it overrides both the local filter mask and the master filter mask.
592The current setting for a per-process filter mask may be inspected using
593.Fl c Ar process ,
594where
595.Ar process
596is either a PID or the name of a process.
597If a name is used, it must uniquely identify a process.
598To set a per-process filter mask, an second argument may be supplied following
599.Fl c Ar process
600as described above for the master filter mask.
601Root access is required to set the per-process filter mask for system (UID 0) processes.
602.Pp
603The filtering described above takes place in the client library to determine which messages are sent to the
604.Nm syslogd
605daemon.
c4fdb7d1
A
606The daemon also contains filters which determines which messages are saved in the data store.
607This determines which messages are seen when reading messages using the
b16a592a 608.Nm
c4fdb7d1 609utility, or when viewing data store messages in the Console utility application.
b16a592a 610.Pp
c4fdb7d1 611The default data store filter mask permits all messages with priority levels from Emergency to Debug (level 0 to 7).
b16a592a
A
612The level may be inspected using:
613.Pp
614.Dl syslog -c syslogd
615.Pp
616To set the data store filter mask, an second argument may be supplied following
617.Fl c Li syslog
618as described above.
619For example, to save messages with priority level Error or less in the data store:
620.Pp
621.Dl syslog -c syslog -e
c4fdb7d1
A
622.Pp
623The
624.Nm syslogd
625server also follows filtering rules specified in the /etc/asl.conf file.
626When the remote-control mechanism is used to change the filter of a process,
627.Nm syslogd
628will save any messages received from that process until the remote-control filter is turned off.
629It is no longer necessary to adjust the filtering for both a process and for
630.Nm syslogd
631to have messages saved in the ASL data store.
b16a592a
A
632.Sh SEE ALSO
633.Xr syslogd 8 ,
634.Xr logger 1 ,
635.Xr asl 3 ,
636.Xr syslog 3 ,
637.Sh HISTORY
638The
639.Nm
640utility appeared in Mac OS X 10.4.