]> git.saurik.com Git - apple/syslog.git/blame - util.tproj/syslog.1
syslog-13.tar.gz
[apple/syslog.git] / util.tproj / syslog.1
CommitLineData
b16a592a
A
1.\" Copyright (c) 2004 Apple Computer
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
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.
15.\"
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
26.\" SUCH DAMAGE.
27.\"
28.\"
29.Dd October 18, 2004
30.Dt SYSLOG 1
31.Os "Mac OS X"
32.Sh NAME
33.Nm syslog
34.Nd Apple System Log utility
35.Sh SYNOPSIS
36.Nm
37.Fl help
38.D1 ""
39.Nm
40.Fl s
41.Op Fl r Ar host
42.Op Fl l Ar level
43message...
44.D1 ""
45.Nm
46.Fl s
47.Op Fl r Ar host
48.Fl k
49key val
50.Op key val
51.Li ...
52.D1 ""
53.Nm
54.Op Fl w
55.Op Fl F Ar format
56.Ar expression
57.D1 ""
58.Nm
59.Fl p Ar expression
60.D1 ""
61.Nm
62.Fl c Ar process Op filter
63.Sh DESCRIPTION
64.Nm
65is a command-line utility for a variety of tasks relating to the Apple System Log facility.
66It provides mechanisms for sending and viewing log messages,
67pruning the contents of the system's log message data store,
68and for controlling the flow of log messages from client processes.
69.Pp
70When invoked with the
71.Fl help
72option,
73.Nm
74prints a usage message.
75.Ss SENDING MESSAGES
76The
77.Fl s
78option is used send log messages to the
79.Xr syslogd 8
80log message daemon,
81either locally or to a remote server if the
82.Fl r Ar host
83option in used.
84.Pp
85There are two main forms of the command.
86If the
87.Fl k
88option is used, then it must be followed by a list of keys and values.
89A structured message will be sent to the server with the keys and values given as arguments.
90If a key or a value has embedded white space, it must be enclosed in quotes.
91.Pp
92If the
93.Fl k
94option is not specified, then the rest of the command line is treated as the message text.
95The text may be preceded by
96.Fl l Ar level
97to set the log level (priority) of the message.
98Levels may be an integer value corresponding the the log levels specified in
99.Xr syslog 3
100or
101.Xr asl 3 ,
102or they may be a string.
103String values are case insensitive, and should be one of:
104.Pp
105.Bl -tag -compact
106.It Emergency
107(level 0)
108.It Alert
109(level 1)
110.It Critical
111(level 2)
112.It Error
113(level 3)
114.It Warning
115(level 4)
116.It Notice
117(level 5)
118.It Info
119(level 6)
120.It Debug
121(level 7)
122.El
123.Pp
124The string
125.Dq Panic
126is an alias for
127.Dq Emergency .
128.Nm
129only requires one or two leading characters for a level specification.
130A single character suffices in most cases.
131Use
132.Dq P
133or
134.Dq \&Em
135for Panic / Emergency, and
136.Dq \&Er
137or
138.Dq X
139for Error).
140.Ss READING MESSAGES
141The
142.Nm syslogd
143daemon receives messages from a variety of input sources.
144Received messages are processed by a set of output modules,
145each of which may act on messages in different ways.
146.Pp
147Two of the standard modules filter messages using criteria like the sender and the priority level of the message,
148and write copies of these messages to different output streams.
149One module does this filtering and filing task using the configuration specified in the
150.Xr syslog.conf 5
151file.
152The output files specified in that configuration may be examined by any file printing or editing utility,
153e.g.
154.Pp
155.Dl cat /var/log/system.log
156.Pp
157Another module saves messages in a data store, which may be searched using the
158.Nm
159command.
160.Pp
161If invoked with no arguments,
162.Nm
163simply prints all of the messages saved in the data store. If the
164.Fl w
165option is used,
166.Nm
167waits for new messages to be added to the data store.
168Messages already in the store are ignored.
169This usage is similar to watching a log file using, e.g.
170.Pp
171.Dl tail -f /var/log/system.log
172.Pp
173Messages are printed in a format similar to that used in the system.log file,
174except that the message priority level is printed between angle-brackets.
175.Pp
176The
177.Fl u
178option forces all time stamps to be printed using UTC.
179This overrides printing of time stamps using the local time zone.
180.Pp
181The output format may by changed by specifying the
182.Fl F Ar format
183option.
184The value of
185.Ar format
186may be one of the following:
187.Pp
188.Bl -tag -width "xxxx"
189.It bsd
190Format used by the
191.Nm syslogd
192daemon for system log files, e.g. /var/log/system.log.
193.It std
194Standard (default) format.
195Similar to
196.Dq bsd ,
197but includes the message priority level.
198.It raw
199Prints the complete message structure.
200Each key/value pair is enclosed in square brackets.
201Embedded closing brackets and white space are escaped.
202Time stamps are printed using UTC rather than being converted to the local time zone.
203.El
204.Pp
205The value of the
206.Ar format
207argument may also be a custom print format string.
208A custom format should in most cases be enclosed in single quotes to prevent the shell from substituting
209special characters and breaking at white space.
210.Pp
211Custom format strings may include variables of the form
212.Dq $Name
213(or
214.Dq $(Name)
215if the variable is not delimited by whitespace)
216which will be expanded to the associated with the named key.
217For example, the command:
218.Pp
219.Dl syslog -F '$Time $Host $(Sender)[$(PID)]: $Message'
220.Pp
221produces output similar to the
222.Dq bsd
223format.
224.Pp
225If no further command line options are specified,
226.Nm
227displays all messages,
228either all those saved in the data store,
229or all new messages if
230.Fl w
231is used.
232However, an expression may be specified using the
233.Fl k
234and
235.Fl o
236options.
237.Ss EXPRESSIONS
238Expressions specify matching criteria.
239They may be used when reading messages to filter for messages of interest.
240Expressions are also required when pruning the system log file with the
241.Fl p
242option.
243.Pp
244A simple expression is a list of one or more key/value pairs.
245A match is made when a message has the given value for the specified key.
246For example, to find all messages send by the portmap process:
247.Pp
248.Dl syslog -k Sender portmap
249.Pp
250The
251.Fl k
252option may be followed by one, two, or three arguments.
253A single argument causes a match to occur if a message has the specified key, regardless of value.
254If a pair of arguments is specified, a match occurs when a message has exactly the specified value for a given key.
255If three arguments are given, they are of the form
256.Fl k Ar key operation value .
257.Nm
258supports the following matching operators:
259.Pp
260.Bl -tag -width "xxx" -compact
261.It eq
262equal
263.It ne
264not equal
265.It gt
266greater than
267.It ge
268greater than or equal to
269.It lt
270less than
271.It le
272less than or equal to
273.El
274.Pp
275Additionally, the operator may be preceded by one or more of the following modifiers:
276.Pp
277.Bl -tag -width "xxx" -compact
278.It C
279case-fold
280.It R
281regular expression (see
282.Xr regex 3 )
283.It S
284substring
285.It A
286prefix
287.It Z
288suffix
289.It N
290numeric comparison
291.El
292.Pp
293An simple expression matches a message if all of the key-value operations match.
294Logically, the result is an AND of all of key-value operations.
295The
296.Fl o
297option separates simple expressions and provides an OR operation.
298If two or more simple expressions are given, separated by
299.Fl o
300options, then a match occurs is a message matches any of the simple expressions.
301For example, to find all messages which have either a
302.Dq Sender
303value of
304.Dq portmap
305or that have a numeric priority level of 4 or less:
306.Pp
307.Dl syslog -k Sender portmap -o -k Level Nle 4
308.Pp
309A special convention exists for matching time stamps.
310An unsigned integer value is regarded as the given number of seconds since
3110 hours, 0 minutes, 0 seconds, January 1, 1970, Coordinated Universal Time.
312An negative integer value is regarded as the given number of seconds before the current time.
313For example, to find all messages of priority level 3 (error) or less which were logged in the last 30 seconds:
314.Pp
315.Dl syslog -k Level Nle 3 -k Time ge -30
316.Pp
317a relative time value may be optionally followed by one of the characters
318.Dq s ,
319.Dq m ,
320.Dq h ,
321.Dq d ,
322or
323.Dq w
324to specify seconds, minutes, hours, days, or weeks respectively.
325Upper case may be used equivalently.
326A week is taken to be 7 complete days (i.e. 604800 seconds).
327.Ss PRUNING
328The Apple System Log facility saves received messages, subject to filtering criteria described in the
329FILTERING CONTROLS section below.
330Pruning is required to prevent unlimited growth of the data store.
331.Pp
332The
333.Nm syslogd
334daemon itself will prune the data store shortly after it starts up.
335See the
336.Xr syslogd 8
337manual for more details on startup pruning.
338During extended operation of
339.Nm syslogd ,
340pruning is accomplished by using the
341.Fl p
342option of
343.Nm syslog .
344The
345.Fl p
346option must be followed by an expression (see above).
347The contents of the data store are filtered using the given expression.
348Messages that match the expression are deleted.
349.Pp
350A daily pruning operation is performed by the
351.Nm cron
352utility.
353The command is specified in the /etc/periodic/daily/500.daily file.
354.Ss FILTERING CONTROLS
355Clients of the Apple System Log facility using either the
356.Xr asl 3
357or
358.Xr syslog 3
359interfaces may specify a log filter mask.
360The mask specifies which messages should be sent to the
361.Nm syslogd
362daemon by specifying a yes/no setting for each priority level.
363Many clients set a filter mask to avoid sending relatively unimportant messages.
364Debug or Info priority level messages are generally only useful for debugging operations.
365By setting a filter mask, a process can improve performance by avoiding spending
366time sending messages that are in most cases unnecessary.
367.Pp
368The
369.Fl c
370option may be used to control filtering.
371In addition to the internal filter value that processes may set as described above,
372the system maintains a global
373.Dq master
374filter.
375This filter is normally
376.Dq off ,
377meaning that it has no effect.
378If a value is set for the master filter, it overrides the local filter for all processes.
379Root user access is required to set the master filter value.
380.Pp
381The current setting of the master filter mask may be inspected using:
382.Pp
383.Dl syslog -c 0
384.Pp
385The value of the master filter mask my be set by providing a second argument following
386.Fl c Ar 0 .
387The value may a set of characters from the set
388.Dq pacewnid .
389These correspond to the priority levels Emergency (Panic), Alert, Critical, Error, Warning, Notice, Info, and Debug.
390The character
391.Dq x
392may be used for Error, as it is used for sending messages.
393The master filter may be unset with:
394.Pp
395.Dl syslog -c 0 off
396.Pp
397Since it is common to use the filter as a
398.Dq cutoff
399mechanism, for example to cut off messages with Debug and Info priority,
400a single character from the list above may be specified, preceded by a minus sign.
401In this case,
402.Nm
403uses a filter mask starting at level 0 (Emergency)
404.Dq up to
405the given level.
406For example, to set the master filter level to cause all processes to log messages from Emergency up to Debug:
407.Pp
408.Dl syslog -c 0 -d
409.Pp
410While the master filter level may be set to control the messages produced by all processes,
411another filter mask may be specified for an individual process.
412If a per-process filter mask is set, it overrides both the local filter mask and the master filter mask.
413The current setting for a per-process filter mask may be inspected using
414.Fl c Ar process ,
415where
416.Ar process
417is either a PID or the name of a process.
418If a name is used, it must uniquely identify a process.
419To set a per-process filter mask, an second argument may be supplied following
420.Fl c Ar process
421as described above for the master filter mask.
422Root access is required to set the per-process filter mask for system (UID 0) processes.
423.Pp
424The filtering described above takes place in the client library to determine which messages are sent to the
425.Nm syslogd
426daemon.
427The daemon also contains a filter which determines which messages are saved in the data store.
428Note that this additionally determines which messages are seen when reading messages using the
429.Nm
430utility.
431.Pp
432The default data store filter mask saves messages with priority levels from Emergency to Notice (level 0 to 5).
433The level may be inspected using:
434.Pp
435.Dl syslog -c syslogd
436.Pp
437To set the data store filter mask, an second argument may be supplied following
438.Fl c Li syslog
439as described above.
440For example, to save messages with priority level Error or less in the data store:
441.Pp
442.Dl syslog -c syslog -e
443.Sh SEE ALSO
444.Xr syslogd 8 ,
445.Xr logger 1 ,
446.Xr asl 3 ,
447.Xr syslog 3 ,
448.Sh HISTORY
449The
450.Nm
451utility appeared in Mac OS X 10.4.