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