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