/usr/share/doc/glibc-doc/html/libc_18.html is in glibc-doc 2.15-0ubuntu10.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html401/loose.dtd">
<html>
<!-- This file documents the GNU C library.
This is Edition 0.13, last updated 2011-07-19,
of The GNU C Library Reference Manual, for version
2.14 (Ubuntu EGLIBC 2.15-0ubuntu10) .
Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2001, 2002,
2003, 2007, 2008, 2010, 2011 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "Free Software Needs Free Documentation"
and "GNU Lesser General Public License", the Front-Cover texts being
"A GNU Manual", and with the Back-Cover Texts as in (a) below. A
copy of the license is included in the section entitled "GNU Free
Documentation License".
(a) The FSF's Back-Cover Text is: "You have the freedom to
copy and modify this GNU manual. Buying copies from the FSF
supports it in developing GNU and promoting software freedom."
-->
<!-- Created on April 20, 2012 by texi2html 1.82
texi2html was written by:
Lionel Cons <Lionel.Cons@cern.ch> (original author)
Karl Berry <karl@freefriends.org>
Olaf Bachmann <obachman@mathematik.uni-kl.de>
and many others.
Maintained by: Many creative people.
Send bugs and suggestions to <texi2html-bug@nongnu.org>
-->
<head>
<title>The GNU C Library: 18. Syslog</title>
<meta name="description" content="The GNU C Library: 18. Syslog">
<meta name="keywords" content="The GNU C Library: 18. Syslog">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="texi2html 1.82">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.smallquotation {font-size: smaller}
pre.display {font-family: serif}
pre.format {font-family: serif}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: serif; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: serif; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.roman {font-family:serif; font-weight:normal;}
span.sansserif {font-family:sans-serif; font-weight:normal;}
ul.toc {list-style: none}
-->
</style>
</head>
<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
<a name="Syslog"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="libc_17.html#Pseudo_002dTerminal-Pairs" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#Overview-of-Syslog" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="libc_17.html#Low_002dLevel-Terminal-Interface" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="libc.html#Top" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="libc_19.html#Mathematics" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="libc.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="libc_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="libc_42.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="libc_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Syslog-1"></a>
<h1 class="chapter">18. Syslog</h1>
<p>This chapter describes facilities for issuing and logging messages of
system administration interest. This chapter has nothing to do with
programs issuing messages to their own users or keeping private logs
(One would typically do that with the facilities described in
<a href="libc_12.html#I_002fO-on-Streams">Input/Output on Streams</a>).
</p>
<p>Most systems have a facility called “Syslog” that allows programs to
submit messages of interest to system administrators and can be
configured to pass these messages on in various ways, such as printing
on the console, mailing to a particular person, or recording in a log
file for future reference.
</p>
<p>A program uses the facilities in this chapter to submit such messages.
</p>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top"><a href="#Overview-of-Syslog">18.1 Overview of Syslog</a></td><td> </td><td align="left" valign="top"> Overview of a system’s Syslog facility
</td></tr>
<tr><td align="left" valign="top"><a href="#Submitting-Syslog-Messages">18.2 Submitting Syslog Messages</a></td><td> </td><td align="left" valign="top"> Functions to submit messages to Syslog
</td></tr>
</table>
<hr size="6">
<a name="Overview-of-Syslog"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Syslog" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#Submitting-Syslog-Messages" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#Syslog" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#Syslog" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="libc_19.html#Mathematics" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="libc.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="libc_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="libc_42.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="libc_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Overview-of-Syslog-1"></a>
<h2 class="section">18.1 Overview of Syslog</h2>
<p>System administrators have to deal with lots of different kinds of
messages from a plethora of subsystems within each system, and usually
lots of systems as well. For example, an FTP server might report every
connection it gets. The kernel might report hardware failures on a disk
drive. A DNS server might report usage statistics at regular intervals.
</p>
<p>Some of these messages need to be brought to a system administrator’s
attention immediately. And it may not be just any system administrator
– there may be a particular system administrator who deals with a
particular kind of message. Other messages just need to be recorded for
future reference if there is a problem. Still others may need to have
information extracted from them by an automated process that generates
monthly reports.
</p>
<p>To deal with these messages, most Unix systems have a facility called
"Syslog." It is generally based on a daemon called “Syslogd”
Syslogd listens for messages on a Unix domain socket named
‘<tt>/dev/log</tt>’. Based on classification information in the messages
and its configuration file (usually ‘<tt>/etc/syslog.conf</tt>’), Syslogd
routes them in various ways. Some of the popular routings are:
</p>
<ul>
<li>
Write to the system console
</li><li>
Mail to a specific user
</li><li>
Write to a log file
</li><li>
Pass to another daemon
</li><li>
Discard
</li></ul>
<p>Syslogd can also handle messages from other systems. It listens on the
<code>syslog</code> UDP port as well as the local socket for messages.
</p>
<p>Syslog can handle messages from the kernel itself. But the kernel
doesn’t write to ‘<tt>/dev/log</tt>’; rather, another daemon (sometimes
called “Klogd”) extracts messages from the kernel and passes them on to
Syslog as any other process would (and it properly identifies them as
messages from the kernel).
</p>
<p>Syslog can even handle messages that the kernel issued before Syslogd or
Klogd was running. A Linux kernel, for example, stores startup messages
in a kernel message ring and they are normally still there when Klogd
later starts up. Assuming Syslogd is running by the time Klogd starts,
Klogd then passes everything in the message ring to it.
</p>
<p>In order to classify messages for disposition, Syslog requires any process
that submits a message to it to provide two pieces of classification
information with it:
</p>
<dl compact="compact">
<dt> facility</dt>
<dd><p>This identifies who submitted the message. There are a small number of
facilities defined. The kernel, the mail subsystem, and an FTP server
are examples of recognized facilities. For the complete list,
See section <a href="#syslog_003b-vsyslog">syslog, vsyslog</a>. Keep in mind that these are
essentially arbitrary classifications. "Mail subsystem" doesn’t have any
more meaning than the system administrator gives to it.
</p>
</dd>
<dt> priority</dt>
<dd><p>This tells how important the content of the message is. Examples of
defined priority values are: debug, informational, warning, critical.
For the complete list, see <a href="#syslog_003b-vsyslog">syslog, vsyslog</a>. Except for
the fact that the priorities have a defined order, the meaning of each
of these priorities is entirely determined by the system administrator.
</p>
</dd>
</dl>
<p>A “facility/priority” is a number that indicates both the facility
and the priority.
</p>
<p><strong>Warning:</strong> This terminology is not universal. Some people use
“level” to refer to the priority and “priority” to refer to the
combination of facility and priority. A Linux kernel has a concept of a
message “level,” which corresponds both to a Syslog priority and to a
Syslog facility/priority (It can be both because the facility code for
the kernel is zero, and that makes priority and facility/priority the
same value).
</p>
<p>The GNU C library provides functions to submit messages to Syslog. They
do it by writing to the ‘<tt>/dev/log</tt>’ socket. See section <a href="#Submitting-Syslog-Messages">Submitting Syslog Messages</a>.
</p>
<p>The GNU C library functions only work to submit messages to the Syslog
facility on the same system. To submit a message to the Syslog facility
on another system, use the socket I/O functions to write a UDP datagram
to the <code>syslog</code> UDP port on that system. See section <a href="libc_16.html#Sockets">Sockets</a>.
</p>
<hr size="6">
<a name="Submitting-Syslog-Messages"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Overview-of-Syslog" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#openlog" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#Syslog" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#Syslog" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="libc_19.html#Mathematics" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="libc.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="libc_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="libc_42.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="libc_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Submitting-Syslog-Messages-1"></a>
<h2 class="section">18.2 Submitting Syslog Messages</h2>
<p>The GNU C library provides functions to submit messages to the Syslog
facility:
</p>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top"><a href="#openlog">18.2.1 openlog</a></td><td> </td><td align="left" valign="top"> Open connection to Syslog
</td></tr>
<tr><td align="left" valign="top"><a href="#syslog_003b-vsyslog">18.2.2 syslog, vsyslog</a></td><td> </td><td align="left" valign="top"> Submit message to Syslog
</td></tr>
<tr><td align="left" valign="top"><a href="#closelog">18.2.3 closelog</a></td><td> </td><td align="left" valign="top"> Close connection to Syslog
</td></tr>
<tr><td align="left" valign="top"><a href="#setlogmask">18.2.4 setlogmask</a></td><td> </td><td align="left" valign="top"> Cause certain messages to be ignored
</td></tr>
<tr><td align="left" valign="top"><a href="#Syslog-Example">18.2.5 Syslog Example</a></td><td> </td><td align="left" valign="top"> Example of all of the above
</td></tr>
</table>
<p>These functions only work to submit messages to the Syslog facility on
the same system. To submit a message to the Syslog facility on another
system, use the socket I/O functions to write a UDP datagram to the
<code>syslog</code> UDP port on that system. See section <a href="libc_16.html#Sockets">Sockets</a>.
</p>
<hr size="6">
<a name="openlog"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Submitting-Syslog-Messages" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#syslog_003b-vsyslog" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#Syslog" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#Submitting-Syslog-Messages" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="libc_19.html#Mathematics" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="libc.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="libc_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="libc_42.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="libc_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="openlog-1"></a>
<h3 class="subsection">18.2.1 openlog</h3>
<p>The symbols referred to in this section are declared in the file
‘<tt>syslog.h</tt>’.
</p>
<dl>
<dt><a name="index-openlog"></a><u>Function:</u> void <b>openlog</b><i> (const char *<var>ident</var>, int <var>option</var>, int <var>facility</var>)</i></dt>
<dd>
<p><code>openlog</code> opens or reopens a connection to Syslog in preparation
for submitting messages.
</p>
<p><var>ident</var> is an arbitrary identification string which future
<code>syslog</code> invocations will prefix to each message. This is intended
to identify the source of the message, and people conventionally set it
to the name of the program that will submit the messages.
</p>
<p>If <var>ident</var> is NULL, or if <code>openlog</code> is not called, the default
identification string used in Syslog messages will be the program name,
taken from argv[0].
</p>
<p>Please note that the string pointer <var>ident</var> will be retained
internally by the Syslog routines. You must not free the memory that
<var>ident</var> points to. It is also dangerous to pass a reference to an
automatic variable since leaving the scope would mean ending the
lifetime of the variable. If you want to change the <var>ident</var> string,
you must call <code>openlog</code> again; overwriting the string pointed to by
<var>ident</var> is not thread-safe.
</p>
<p>You can cause the Syslog routines to drop the reference to <var>ident</var> and
go back to the default string (the program name taken from argv[0]), by
calling <code>closelog</code>: See section <a href="#closelog">closelog</a>.
</p>
<p>In particular, if you are writing code for a shared library that might get
loaded and then unloaded (e.g. a PAM module), and you use <code>openlog</code>,
you must call <code>closelog</code> before any point where your library might
get unloaded, as in this example:
</p>
<table><tr><td> </td><td><pre class="smallexample">#include <syslog.h>
void
shared_library_function (void)
{
openlog ("mylibrary", option, priority);
syslog (LOG_INFO, "shared library has been invoked");
closelog ();
}
</pre></td></tr></table>
<p>Without the call to <code>closelog</code>, future invocations of <code>syslog</code>
by the program using the shared library may crash, if the library gets
unloaded and the memory containing the string <code>"mylibrary"</code> becomes
unmapped. This is a limitation of the BSD syslog interface.
</p>
<p><code>openlog</code> may or may not open the ‘<tt>/dev/log</tt>’ socket, depending
on <var>option</var>. If it does, it tries to open it and connect it as a
stream socket. If that doesn’t work, it tries to open it and connect it
as a datagram socket. The socket has the “Close on Exec” attribute,
so the kernel will close it if the process performs an exec.
</p>
<p>You don’t have to use <code>openlog</code>. If you call <code>syslog</code> without
having called <code>openlog</code>, <code>syslog</code> just opens the connection
implicitly and uses defaults for the information in <var>ident</var> and
<var>options</var>.
</p>
<p><var>options</var> is a bit string, with the bits as defined by the following
single bit masks:
</p>
<dl compact="compact">
<dt> <code>LOG_PERROR</code></dt>
<dd><p>If on, <code>openlog</code> sets up the connection so that any <code>syslog</code>
on this connection writes its message to the calling process’ Standard
Error stream in addition to submitting it to Syslog. If off, <code>syslog</code>
does not write the message to Standard Error.
</p>
</dd>
<dt> <code>LOG_CONS</code></dt>
<dd><p>If on, <code>openlog</code> sets up the connection so that a <code>syslog</code> on
this connection that fails to submit a message to Syslog writes the
message instead to system console. If off, <code>syslog</code> does not write
to the system console (but of course Syslog may write messages it
receives to the console).
</p>
</dd>
<dt> <code>LOG_PID</code></dt>
<dd><p>When on, <code>openlog</code> sets up the connection so that a <code>syslog</code>
on this connection inserts the calling process’ Process ID (PID) into
the message. When off, <code>openlog</code> does not insert the PID.
</p>
</dd>
<dt> <code>LOG_NDELAY</code></dt>
<dd><p>When on, <code>openlog</code> opens and connects the ‘<tt>/dev/log</tt>’ socket.
When off, a future <code>syslog</code> call must open and connect the socket.
</p>
<p><strong>Portability note:</strong> In early systems, the sense of this bit was
exactly the opposite.
</p>
</dd>
<dt> <code>LOG_ODELAY</code></dt>
<dd><p>This bit does nothing. It exists for backward compatibility.
</p>
</dd>
</dl>
<p>If any other bit in <var>options</var> is on, the result is undefined.
</p>
<p><var>facility</var> is the default facility code for this connection. A
<code>syslog</code> on this connection that specifies default facility causes
this facility to be associated with the message. See <code>syslog</code> for
possible values. A value of zero means the default default, which is
<code>LOG_USER</code>.
</p>
<p>If a Syslog connection is already open when you call <code>openlog</code>,
<code>openlog</code> “reopens” the connection. Reopening is like opening
except that if you specify zero for the default facility code, the
default facility code simply remains unchanged and if you specify
LOG_NDELAY and the socket is already open and connected, <code>openlog</code>
just leaves it that way.
</p>
</dd></dl>
<hr size="6">
<a name="syslog_003b-vsyslog"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#openlog" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#closelog" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#Syslog" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#Submitting-Syslog-Messages" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="libc_19.html#Mathematics" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="libc.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="libc_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="libc_42.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="libc_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="syslog_002c-vsyslog"></a>
<h3 class="subsection">18.2.2 syslog, vsyslog</h3>
<p>The symbols referred to in this section are declared in the file
‘<tt>syslog.h</tt>’.
</p>
<dl>
<dt><a name="index-syslog"></a><u>Function:</u> void <b>syslog</b><i> (int <var>facility_priority</var>, char *<var>format</var>, ...)</i></dt>
<dd>
<p><code>syslog</code> submits a message to the Syslog facility. It does this by
writing to the Unix domain socket <code>/dev/log</code>.
</p>
<p><code>syslog</code> submits the message with the facility and priority indicated
by <var>facility_priority</var>. The macro <code>LOG_MAKEPRI</code> generates a
facility/priority from a facility and a priority, as in the following
example:
</p>
<table><tr><td> </td><td><pre class="smallexample">LOG_MAKEPRI(LOG_USER, LOG_WARNING)
</pre></td></tr></table>
<p>The possible values for the facility code are (macros):
</p>
<dl compact="compact">
<dt> <code>LOG_USER</code>
<a name="index-LOG_005fUSER"></a>
</dt>
<dd><p>A miscellaneous user process
</p></dd>
<dt> <code>LOG_MAIL</code>
<a name="index-LOG_005fMAIL"></a>
</dt>
<dd><p>Mail
</p></dd>
<dt> <code>LOG_DAEMON</code>
<a name="index-LOG_005fDAEMON"></a>
</dt>
<dd><p>A miscellaneous system daemon
</p></dd>
<dt> <code>LOG_AUTH</code>
<a name="index-LOG_005fAUTH"></a>
</dt>
<dd><p>Security (authorization)
</p></dd>
<dt> <code>LOG_SYSLOG</code>
<a name="index-LOG_005fSYSLOG"></a>
</dt>
<dd><p>Syslog
</p></dd>
<dt> <code>LOG_LPR</code>
<a name="index-LOG_005fLPR"></a>
</dt>
<dd><p>Central printer
</p></dd>
<dt> <code>LOG_NEWS</code>
<a name="index-LOG_005fNEWS"></a>
</dt>
<dd><p>Network news (e.g. Usenet)
</p></dd>
<dt> <code>LOG_UUCP</code>
<a name="index-LOG_005fUUCP"></a>
</dt>
<dd><p>UUCP
</p></dd>
<dt> <code>LOG_CRON</code>
<a name="index-LOG_005fCRON"></a>
</dt>
<dd><p>Cron and At
</p></dd>
<dt> <code>LOG_AUTHPRIV</code>
<a name="index-LOG_005fAUTHPRIV"></a>
</dt>
<dd><p>Private security (authorization)
</p></dd>
<dt> <code>LOG_FTP</code>
<a name="index-LOG_005fFTP"></a>
</dt>
<dd><p>Ftp server
</p></dd>
<dt> <code>LOG_LOCAL0</code>
<a name="index-LOG_005fLOCAL0"></a>
</dt>
<dd><p>Locally defined
</p></dd>
<dt> <code>LOG_LOCAL1</code>
<a name="index-LOG_005fLOCAL1"></a>
</dt>
<dd><p>Locally defined
</p></dd>
<dt> <code>LOG_LOCAL2</code>
<a name="index-LOG_005fLOCAL2"></a>
</dt>
<dd><p>Locally defined
</p></dd>
<dt> <code>LOG_LOCAL3</code>
<a name="index-LOG_005fLOCAL3"></a>
</dt>
<dd><p>Locally defined
</p></dd>
<dt> <code>LOG_LOCAL4</code>
<a name="index-LOG_005fLOCAL4"></a>
</dt>
<dd><p>Locally defined
</p></dd>
<dt> <code>LOG_LOCAL5</code>
<a name="index-LOG_005fLOCAL5"></a>
</dt>
<dd><p>Locally defined
</p></dd>
<dt> <code>LOG_LOCAL6</code>
<a name="index-LOG_005fLOCAL6"></a>
</dt>
<dd><p>Locally defined
</p></dd>
<dt> <code>LOG_LOCAL7</code>
<a name="index-LOG_005fLOCAL7"></a>
</dt>
<dd><p>Locally defined
</p></dd>
</dl>
<p>Results are undefined if the facility code is anything else.
</p>
<p><strong>NB:</strong> <code>syslog</code> recognizes one other facility code: that of
the kernel. But you can’t specify that facility code with these
functions. If you try, it looks the same to <code>syslog</code> as if you are
requesting the default facility. But you wouldn’t want to anyway,
because any program that uses the GNU C library is not the kernel.
</p>
<p>You can use just a priority code as <var>facility_priority</var>. In that
case, <code>syslog</code> assumes the default facility established when the
Syslog connection was opened. See section <a href="#Syslog-Example">Syslog Example</a>.
</p>
<p>The possible values for the priority code are (macros):
</p>
<dl compact="compact">
<dt> <code>LOG_EMERG</code>
<a name="index-LOG_005fEMERG"></a>
</dt>
<dd><p>The message says the system is unusable.
</p></dd>
<dt> <code>LOG_ALERT</code>
<a name="index-LOG_005fALERT"></a>
</dt>
<dd><p>Action on the message must be taken immediately.
</p></dd>
<dt> <code>LOG_CRIT</code>
<a name="index-LOG_005fCRIT"></a>
</dt>
<dd><p>The message states a critical condition.
</p></dd>
<dt> <code>LOG_ERR</code>
<a name="index-LOG_005fERR"></a>
</dt>
<dd><p>The message describes an error.
</p></dd>
<dt> <code>LOG_WARNING</code>
<a name="index-LOG_005fWARNING"></a>
</dt>
<dd><p>The message is a warning.
</p></dd>
<dt> <code>LOG_NOTICE</code>
<a name="index-LOG_005fNOTICE"></a>
</dt>
<dd><p>The message describes a normal but important event.
</p></dd>
<dt> <code>LOG_INFO</code>
<a name="index-LOG_005fINFO"></a>
</dt>
<dd><p>The message is purely informational.
</p></dd>
<dt> <code>LOG_DEBUG</code>
<a name="index-LOG_005fDEBUG"></a>
</dt>
<dd><p>The message is only for debugging purposes.
</p></dd>
</dl>
<p>Results are undefined if the priority code is anything else.
</p>
<p>If the process does not presently have a Syslog connection open (i.e.,
it did not call <code>openlog</code>), <code>syslog</code> implicitly opens the
connection the same as <code>openlog</code> would, with the following defaults
for information that would otherwise be included in an <code>openlog</code>
call: The default identification string is the program name. The
default default facility is <code>LOG_USER</code>. The default for all the
connection options in <var>options</var> is as if those bits were off.
<code>syslog</code> leaves the Syslog connection open.
</p>
<p>If the ‘<tt>dev/log</tt>’ socket is not open and connected, <code>syslog</code>
opens and connects it, the same as <code>openlog</code> with the
<code>LOG_NDELAY</code> option would.
</p>
<p><code>syslog</code> leaves ‘<tt>/dev/log</tt>’ open and connected unless its attempt
to send the message failed, in which case <code>syslog</code> closes it (with the
hope that a future implicit open will restore the Syslog connection to a
usable state).
</p>
<p>Example:
</p>
<table><tr><td> </td><td><pre class="smallexample">
#include <syslog.h>
syslog (LOG_MAKEPRI(LOG_LOCAL1, LOG_ERROR),
"Unable to make network connection to %s. Error=%m", host);
</pre></td></tr></table>
</dd></dl>
<dl>
<dt><a name="index-vsyslog"></a><u>Function:</u> void <b>vsyslog</b><i> (int <var>facility_priority</var>, char *<var>format</var>, va_list arglist)</i></dt>
<dd>
<p>This is functionally identical to <code>syslog</code>, with the BSD style variable
length argument.
</p>
</dd></dl>
<hr size="6">
<a name="closelog"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#syslog_003b-vsyslog" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#setlogmask" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#Syslog" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#Submitting-Syslog-Messages" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="libc_19.html#Mathematics" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="libc.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="libc_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="libc_42.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="libc_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="closelog-1"></a>
<h3 class="subsection">18.2.3 closelog</h3>
<p>The symbols referred to in this section are declared in the file
‘<tt>syslog.h</tt>’.
</p>
<dl>
<dt><a name="index-closelog"></a><u>Function:</u> void <b>closelog</b><i> (void)</i></dt>
<dd>
<p><code>closelog</code> closes the current Syslog connection, if there is one.
This includes closing the ‘<tt>dev/log</tt>’ socket, if it is open.
<code>closelog</code> also sets the identification string for Syslog messages
back to the default, if <code>openlog</code> was called with a non-NULL argument
to <var>ident</var>. The default identification string is the program name
taken from argv[0].
</p>
<p>If you are writing shared library code that uses <code>openlog</code> to
generate custom syslog output, you should use <code>closelog</code> to drop the
GNU C library’s internal reference to the <var>ident</var> pointer when you are
done. Please read the section on <code>openlog</code> for more information:
See section <a href="#openlog">openlog</a>.
</p>
<p><code>closelog</code> does not flush any buffers. You do not have to call
<code>closelog</code> before re-opening a Syslog connection with <code>initlog</code>.
Syslog connections are automatically closed on exec or exit.
</p>
</dd></dl>
<hr size="6">
<a name="setlogmask"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#closelog" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#Syslog-Example" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#Syslog" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#Submitting-Syslog-Messages" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="libc_19.html#Mathematics" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="libc.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="libc_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="libc_42.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="libc_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="setlogmask-1"></a>
<h3 class="subsection">18.2.4 setlogmask</h3>
<p>The symbols referred to in this section are declared in the file
‘<tt>syslog.h</tt>’.
</p>
<dl>
<dt><a name="index-setlogmask"></a><u>Function:</u> int <b>setlogmask</b><i> (int <var>mask</var>)</i></dt>
<dd>
<p><code>setlogmask</code> sets a mask (the “logmask”) that determines which
future <code>syslog</code> calls shall be ignored. If a program has not
called <code>setlogmask</code>, <code>syslog</code> doesn’t ignore any calls. You
can use <code>setlogmask</code> to specify that messages of particular
priorities shall be ignored in the future.
</p>
<p>A <code>setlogmask</code> call overrides any previous <code>setlogmask</code> call.
</p>
<p>Note that the logmask exists entirely independently of opening and
closing of Syslog connections.
</p>
<p>Setting the logmask has a similar effect to, but is not the same as,
configuring Syslog. The Syslog configuration may cause Syslog to
discard certain messages it receives, but the logmask causes certain
messages never to get submitted to Syslog in the first place.
</p>
<p><var>mask</var> is a bit string with one bit corresponding to each of the
possible message priorities. If the bit is on, <code>syslog</code> handles
messages of that priority normally. If it is off, <code>syslog</code>
discards messages of that priority. Use the message priority macros
described in <a href="#syslog_003b-vsyslog">syslog, vsyslog</a> and the <code>LOG_MASK</code> to construct
an appropriate <var>mask</var> value, as in this example:
</p>
<table><tr><td> </td><td><pre class="smallexample">LOG_MASK(LOG_EMERG) | LOG_MASK(LOG_ERROR)
</pre></td></tr></table>
<p>or
</p>
<table><tr><td> </td><td><pre class="smallexample">~(LOG_MASK(LOG_INFO))
</pre></td></tr></table>
<p>There is also a <code>LOG_UPTO</code> macro, which generates a mask with the bits
on for a certain priority and all priorities above it:
</p>
<table><tr><td> </td><td><pre class="smallexample">LOG_UPTO(LOG_ERROR)
</pre></td></tr></table>
<p>The unfortunate naming of the macro is due to the fact that internally,
higher numbers are used for lower message priorities.
</p>
</dd></dl>
<hr size="6">
<a name="Syslog-Example"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#setlogmask" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="libc_19.html#Mathematics" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#Syslog" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#Submitting-Syslog-Messages" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="libc_19.html#Mathematics" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="libc.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="libc_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="libc_42.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="libc_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Syslog-Example-1"></a>
<h3 class="subsection">18.2.5 Syslog Example</h3>
<p>Here is an example of <code>openlog</code>, <code>syslog</code>, and <code>closelog</code>:
</p>
<p>This example sets the logmask so that debug and informational messages
get discarded without ever reaching Syslog. So the second <code>syslog</code>
in the example does nothing.
</p>
<table><tr><td> </td><td><pre class="smallexample">#include <syslog.h>
setlogmask (LOG_UPTO (LOG_NOTICE));
openlog ("exampleprog", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
syslog (LOG_NOTICE, "Program started by User %d", getuid ());
syslog (LOG_INFO, "A tree falls in a forest");
closelog ();
</pre></td></tr></table>
<hr size="6">
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Syslog" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="libc_19.html#Mathematics" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="libc.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="libc_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="libc_42.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="libc_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<p>
<font size="-1">
This document was generated by <em>root</em> on <em>April 20, 2012</em> using <a href="http://www.nongnu.org/texi2html/"><em>texi2html 1.82</em></a>.
</font>
<br>
</p>
</body>
</html>
|