]> git.saurik.com Git - apple/syslog.git/blob - util.tproj/syslog.1
6c7924f6aabe828e21b38d72c53a1f7807e40a8b
[apple/syslog.git] / util.tproj / syslog.1
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
43 message...
44 .D1 ""
45 .Nm
46 .Fl s
47 .Op Fl r Ar host
48 .Fl k
49 key val
50 .Op key val
51 .Li ...
52 .D1 ""
53 .Nm
54 .Fl C
55 .D1 ""
56 .Nm
57 .Op Fl db Op Ar file ...
58 .Op Fl w Op Ar n
59 .Op Fl F Ar format
60 .Op Fl T Ar format
61 .Ar expression
62 .D1 ""
63 .Nm
64 .Op Fl db Op Ar file ...
65 .Fl x Ar expression
66 .D1 ""
67 .Nm
68 .Op Fl db Op Ar file ...
69 .Fl p Ar expression
70 .D1 ""
71 .Nm
72 .Fl c Ar process Op filter
73 .Sh DESCRIPTION
74 .Nm
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.
79 .Pp
80 When invoked with the
81 .Fl help
82 option,
83 .Nm
84 prints a usage message.
85 .Ss SENDING MESSAGES
86 The
87 .Fl s
88 option is used send log messages to the
89 .Xr syslogd 8
90 log message daemon,
91 either locally or to a remote server if the
92 .Fl r Ar host
93 option in used.
94 .Pp
95 There are two main forms of the command.
96 If the
97 .Fl k
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.
101 .Pp
102 If the
103 .Fl k
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
106 .Fl l Ar level
107 to set the log level (priority) of the message.
108 Levels may be an integer value corresponding the the log levels specified in
109 .Xr syslog 3
110 or
111 .Xr asl 3 ,
112 or they may be a string.
113 String values are case insensitive, and should be one of:
114 .Pp
115 .Bl -tag -compact
116 .It Emergency
117 (level 0)
118 .It Alert
119 (level 1)
120 .It Critical
121 (level 2)
122 .It Error
123 (level 3)
124 .It Warning
125 (level 4)
126 .It Notice
127 (level 5)
128 .It Info
129 (level 6)
130 .It Debug
131 (level 7)
132 .El
133 .Pp
134 The string
135 .Dq Panic
136 is an alias for
137 .Dq Emergency .
138 .Pp
139 If the
140 .Fl l
141 option is omitted, the log level defaults to 7 (Debug).
142 .Pp
143 .Nm
144 only requires one or two leading characters for a level specification.
145 A single character suffices in most cases.
146 Use
147 .Dq P
148 or
149 .Dq \&Em
150 for Panic / Emergency, and
151 .Dq \&Er
152 or
153 .Dq X
154 for Error).
155 .Ss READING MESSAGES
156 The
157 .Nm syslogd
158 daemon filters and saves log messages to different output streams.
159 One module saves messages to files specified in the
160 .Xr syslog.conf 5
161 file.
162 Those log files may be examined with any file printing or editing utility,
163 e.g.
164 .Pp
165 .Dl cat /var/log/system.log
166 .Pp
167 Another module saves messages in an active database,
168 and may also be configured to keep archive databases.
169 .Pp
170 If invoked with no arguments,
171 .Nm
172 sends a query to
173 .Nm syslogd
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.
176 .Pp
177 If invoked with the
178 .Fl C
179 option,
180 .Nm
181 fetches and prints console messages.
182 The
183 .Fl C
184 option is actually an alias for the expression:
185 .Pp
186 .Dl -k Facility com.apple.console
187 .Pp
188 See the EXPRESSIONS section below for more details.
189 .Pp
190 If the system is running in single-user mode,
191 .Nm
192 will open the ASL active database file (/var/log/asl.db) directly, rather than queying
193 .Nm syslogd
194 for messages.
195 The database file is opened in read-only mode, and read access permissions are required.
196 Specifying the
197 .Fl db
198 option with no argument also forces raw database access.
199 .Pp
200 Archive log databases may be read by providing one or more database names as arguments to the
201 .Fl db
202 option.
203 Each database is read in sequence.
204 As a special case, the name
205 .Dq -
206 may be used in place of a database file name.
207 In this case,
208 .Nm
209 will connect to
210 .Nm syslogd
211 and query for the contents of the active database.
212 .Pp
213 The
214 .Fl w
215 option causes
216 .Nm
217 to wait for new messages.
218 By default,
219 .Nm
220 prints the last 10 messages,
221 then waits for new messages to be added to the database.
222 A number following the
223 .Fl w
224 option specifies the number of messages to print and overrides the default value of 10.
225 For example:
226 .Pp
227 .Dl syslog -w 20
228 .Pp
229 This usage is similar to watching a log file using, e.g.
230 .Pp
231 .Dl tail -f /var/log/system.log
232 .Pp
233 The
234 .Fl w
235 option can only be used for a single database, and when printing messages to standard output.
236 .Pp
237 If the
238 .Fl x Ar database
239 option is specified, messages are copied to the named
240 .Ar database
241 file rather than being printed.
242 The
243 .Ar database
244 file will be created if it does not exist.
245 .Pp
246 When called without the
247 .Fl x
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.
251 .Pp
252 The output format may by changed by specifying the
253 .Fl F Ar format
254 option.
255 Non-printable and control characters are encoded in the output, as described below.
256 The value of
257 .Ar format
258 may be one of the following:
259 .Pp
260 .Bl -tag -width "xxxx"
261 .It bsd
262 Format used by the
263 .Nm syslogd
264 daemon for system log files, e.g. /var/log/system.log.
265 .It std
266 Standard (default) format.
267 Similar to
268 .Dq bsd ,
269 but includes the message priority level.
270 .It raw
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
276 .Fl T
277 option is specified (see below).
278 .It xml
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.
283 .El
284 .Pp
285 The value of the
286 .Ar format
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.
290 .Pp
291 Custom format strings may include variables of the form
292 .Dq $Name
293 (or
294 .Dq $(Name)
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:
298 .Pp
299 .Dl syslog -F '$Time $Host $(Sender)[$(PID)]: $Message'
300 .Pp
301 produces output similar to the
302 .Dq bsd
303 format.
304 .Pp
305 Timestamps may be printed in three formats.
306 Times are generally converted to local time, except when the
307 .Fl F Ar sec
308 option is used, in which case times are printed as the number of seconds since the epoch.
309 The
310 .Fl T Ar format
311 option may be used to explicity control the format used for timestamps.
312 The value of
313 .Ar format
314 may be one of the following:
315 .Pp
316 .Bl -tag -width "local"
317 .It sec
318 Times are printed as the number of seconds since the epoch.
319 .It local
320 Times are converted to the local time zone, and printed with the format
321 .Dl MMM DD HH:MM:SS
322 .It utc
323 Times are converted to UTC, and printed with the format
324 .Dl YYYY.MM.DD HH:MM:SS UTC
325 .El
326 .Pp
327 The
328 .Fl u
329 option is a short form for
330 .Fl T Ar utc .
331 .Pp
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.
336 .Pp
337 Output in the
338 .Dq std ,
339 .Dq bsd ,
340 and
341 .Dq raw
342 formats is encoded as it is by the
343 .Xr vis
344 utility with the
345 .Fl c
346 option.
347 Newlines and tabs are also encoded as "\\n" and "\\t" respectively.
348 In
349 .Dq raw
350 format, space chanacters embedded in log message keys are encoded as "\\s"
351 and embedded brackets are escaped to print as "\\[" and "\\]".
352 .Pp
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.
355 .Pp
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
359 .Dq &#xNN;
360 where NN is the character's hexidecimal value.
361 .Pp
362 Values that do not contain legal UTF8 are encoded in base-64 and printed as data objects.
363 .Pp
364 If no further command line options are specified,
365 .Nm
366 displays all messages, or copies all messages to a database file.
367 However, an expression may be specified using the
368 .Fl k
369 and
370 .Fl o
371 options.
372 .Ss EXPRESSIONS
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
376 .Fl p
377 option.
378 .Pp
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:
382 .Pp
383 .Dl syslog -k Sender portmap
384 .Pp
385 Note that the
386 .Fl C
387 option is treated as an alias for the expression:
388 .Pp
389 .Dl -k Facility com.apple.console
390 .Pp
391 This provides a quick way to search for console messages.
392 .Pp
393 The
394 .Fl k
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 .
400 .Nm
401 supports the following matching operators:
402 .Pp
403 .Bl -tag -width "xxx" -compact
404 .It eq
405 equal
406 .It ne
407 not equal
408 .It gt
409 greater than
410 .It ge
411 greater than or equal to
412 .It lt
413 less than
414 .It le
415 less than or equal to
416 .El
417 .Pp
418 Additionally, the operator may be preceded by one or more of the following modifiers:
419 .Pp
420 .Bl -tag -width "xxx" -compact
421 .It C
422 case-fold
423 .It R
424 regular expression (see
425 .Xr regex 3 )
426 .It S
427 substring
428 .It A
429 prefix
430 .It Z
431 suffix
432 .It N
433 numeric comparison
434 .El
435 .Pp
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.
438 The
439 .Fl o
440 option separates simple expressions and provides an OR operation.
441 If two or more simple expressions are given, separated by
442 .Fl o
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
445 .Dq Sender
446 value of
447 .Dq portmap
448 or that have a numeric priority level of 4 or less:
449 .Pp
450 .Dl syslog -k Sender portmap -o -k Level Nle 4
451 .Pp
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:
457 .Pp
458 .Dl syslog -k Level Nle 3 -k Time ge -30
459 .Pp
460 a relative time value may be optionally followed by one of the characters
461 .Dq s ,
462 .Dq m ,
463 .Dq h ,
464 .Dq d ,
465 or
466 .Dq w
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).
470 .Ss PRUNING
471 The Apple System Log facility saves received messages, subject to filtering criteria described in the
472 FILTERING CONTROLS section below.
473 The
474 .Nm syslogd
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.
477 See the
478 .Xr syslogd 8
479 manual for more details on archiving messages.
480 .Pp
481 Messages may be removed from either the active database or from an archive database by using the
482 .Fl p
483 option of
484 .Nm syslog .
485 The
486 .Fl p
487 option must be followed by an expression (see above).
488 Messages that match the expression are deleted.
489 .Pp
490 If the
491 .Fl db
492 option is not specified
493 .Nm
494 sends a request to
495 .Nm syslogd
496 to perform the requested pruning operation.
497 If
498 .Fl db
499 is given without a database file name,
500 .Nm
501 prunes the active database file.
502 This may only be done if the
503 .Nm syslogd
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
509 .Xr asl 3
510 or
511 .Xr syslog 3
512 interfaces may specify a log filter mask.
513 The mask specifies which messages should be sent to the
514 .Nm syslogd
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.
520 .Pp
521 The
522 .Fl c
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
526 .Dq master
527 filter.
528 This filter is normally
529 .Dq off ,
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.
533 .Pp
534 The current setting of the master filter mask may be inspected using:
535 .Pp
536 .Dl syslog -c 0
537 .Pp
538 The value of the master filter mask my be set by providing a second argument following
539 .Fl c Ar 0 .
540 The value may a set of characters from the set
541 .Dq pacewnid .
542 These correspond to the priority levels Emergency (Panic), Alert, Critical, Error, Warning, Notice, Info, and Debug.
543 The character
544 .Dq x
545 may be used for Error, as it is used for sending messages.
546 The master filter may be unset with:
547 .Pp
548 .Dl syslog -c 0 off
549 .Pp
550 Since it is common to use the filter as a
551 .Dq cutoff
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.
554 In this case,
555 .Nm
556 uses a filter mask starting at level 0 (Emergency)
557 .Dq up to
558 the given level.
559 For example, to set the master filter level to cause all processes to log messages from Emergency up to Debug:
560 .Pp
561 .Dl syslog -c 0 -d
562 .Pp
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
567 .Fl c Ar process ,
568 where
569 .Ar process
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
573 .Fl c Ar process
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.
576 .Pp
577 The filtering described above takes place in the client library to determine which messages are sent to the
578 .Nm syslogd
579 daemon.
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
582 .Nm
583 utility.
584 .Pp
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:
587 .Pp
588 .Dl syslog -c syslogd
589 .Pp
590 To set the data store filter mask, an second argument may be supplied following
591 .Fl c Li syslog
592 as described above.
593 For example, to save messages with priority level Error or less in the data store:
594 .Pp
595 .Dl syslog -c syslog -e
596 .Sh SEE ALSO
597 .Xr syslogd 8 ,
598 .Xr logger 1 ,
599 .Xr asl 3 ,
600 .Xr syslog 3 ,
601 .Sh HISTORY
602 The
603 .Nm
604 utility appeared in Mac OS X 10.4.