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