1.\" Id: logging.mdoc,v 1.3 2004/03/09 06:30:08 marka Exp 2.\" 3.\" Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") 4.\" Copyright (c) 1995-1999 by Internet Software Consortium 5.\" 6.\" Permission to use, copy, modify, and distribute this software for any 7.\" purpose with or without fee is hereby granted, provided that the above 8.\" copyright notice and this permission notice appear in all copies. 9.\" 10.\" THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES 11.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR 13.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT 16.\" OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17.\" 18.\" The following six UNCOMMENTED lines are required. 19.Dd January 1, 1996 20.\"Os OPERATING_SYSTEM [version/release] 21.Os BSD 4 22.\"Dt DOCUMENT_TITLE [section number] [volume] 23.Dt LOGGING @SYSCALL_EXT@ 24.Sh NAME 25.Nm log_open_stream , 26.Nm log_close_stream , 27.Nm log_get_stream , 28.Nm log_get_filename , 29.Nm log_vwrite , 30.Nm log_write , 31.Nm log_new_context , 32.Nm log_free_context , 33.Nm log_add_channel , 34.Nm log_remove_channel , 35.Nm log_option , 36.Nm log_category_is_active , 37.Nm log_new_syslog_channel , 38.Nm log_new_file_channel , 39.Nm log_set_file_owner , 40.Nm log_new_null_channel , 41.Nm log_inc_references , 42.Nm log_dec_references , 43.Nm log_free_channel 44.Nd logging system 45.Sh SYNOPSIS 46.Fd #include <isc/logging.h> 47.Ft FILE * 48.Fn log_open_stream "log_channel chan" 49.Ft int 50.Fn log_close_stream "log_channel chan" 51.Ft FILE * 52.Fn log_get_stream "log_channel chan" 53.Ft char * 54.Fn log_get_filename "log_channel chan" 55.Ft void 56.Fn log_vwrite "log_context lc" "int category" "int level" \ 57 "const char *format" va_list args" 58.Ft void 59.Fn log_write "log_context lc" "int category" "int level" \ 60 "const char *format" "..." 61.Ft int 62.Fn log_check_channel "log_context lc" "int level" "log_channel chan" 63.Ft int 64.Fn log_check "log_context lc" "int category" "int level" 65.Ft int 66.Fn log_new_context "int num_categories" "char **category_names" \ 67 "log_context *lc" 68.Ft void 69.Fn log_free_context "log_context lc" 70.Ft int 71.Fn log_add_channel "log_context lc" "int category" "log_channel chan" 72.Ft int 73.Fn log_remove_channel "log_context lc" "int category" "log_channel chan" 74.Ft int 75.Fn log_option "log_context lc" "int option" "int value" 76.Ft int 77.Fn log_category_is_active "log_context lc" "int category" 78.Ft log_channel 79.Fn log_new_syslog_channel "unsigned int flags" "int level" "int facility" 80.Ft log_channel 81.Fn log_new_file_channel "unsigned int flags" "int level" \ 82 "char *name" "FILE *stream" "unsigned int versions" \ 83 "unsigned long max_size" 84.Ft int 85.Fn log_set_file_owner "log_channel chan" "uid_t owner" "gid_t group" 86.Ft log_channel 87.Fn log_new_null_channel "void" 88.Ft int 89.Fn log_inc_references "log_channel chan" 90.Ft int 91.Fn log_dec_references "log_channel chan" 92.Ft int 93.Fn log_free_channel "log_channel chan" 94.Sh DESCRIPTION 95The 96.Sy ISC 97.Nm logging library 98is flexible logging system which is based upon a set of concepts: 99.Nm logging channels , 100.Nm categories , 101and 102.Nm logging contexts . 103.Pp 104The basic building block is the 105.Dq Nm logging channel , 106which includes a 107.Nm priority 108(logging level), which type of logging is to occur, and other 109flags and information associated with technical aspects of the logging. 110The set of priorities which are supported is shown below, in the section 111.Sx Message Priorities . 112A priority sets a threshold for message logging; a logging channel will 113.Em only 114log those messages which are 115.Em at least as important 116as its priority indicates. (The fact that 117.Dq more important 118means 119.Dq more negative , 120under the current scheme, is an implementation detail; if a channel has 121a priority of 122.Dv log_error , 123then it will 124.Em not 125log messages with the 126.Dv log_warning 127priority, but it 128.Em will 129log messages with the 130.Dv log_error 131or 132.Dv log_critical 133priority.) 134.Pp 135The 136.Nm logging channel 137also has an indication of the type of logging performed. Currently, 138the supported 139.Nm logging types 140include (see also 141.Sx Logging Types , 142below): 143.Bl -tag -width "log_syslog" -compact -offset indent 144.It Dv log_syslog 145for 146.Xr syslog 3 Ns -style 147logging 148.It Dv log_file 149for use of a file 150.It Dv log_null 151for 152.Em no 153logging 154.El 155A new logging channel is created by calling either 156.Fn log_new_syslog_channel , 157.Fn log_new_file_channel , 158or 159.Fn log_new_null_channel , 160respectively. 161When a channel is no longer to be used, it can be freed using 162.Fn log_free_channel . 163.Pp 164Both 165.Dv log_syslog 166and 167.Dv log_file 168channel types can include more information; for instance, a 169.Dv log_syslog Ns -type 170channel allows the specification of a 171.Xr syslog 3 Ns -style 172.Dq facility , 173and a 174.Dv log_file Ns -type 175channels allows the caller to set a maximum file size and number 176of versions. (See 177.Fn log_new_syslog_channel 178or 179.Fn log_new_file_channel , 180below.) 181Additionally, once a logging channel of type 182.Dv log_file 183is defined, the functions 184.Fn log_open_stream 185and 186.Fn log_close_stream 187can open or close the stream associated with the logging channel's logging 188filename. The 189.Fn log_get_stream 190and 191.Fn log_get_filename 192functions return the stream or filename, respectively, of such a logging 193channel. Also unique to logging channels of type 194.Dv log_file 195is the 196.Fn log_set_file_owner 197function, which tells the logging system what user and group ought to own 198newly created files (which is only effective if the caller is privileged.) 199.Pp 200Callers provide 201.Dq Nm categories , 202determining both the number of such categories and any (optional) names. 203Categories are like array indexes in C; if the caller declares 204.Dq Va n 205categories, then they are considered to run from 0 to 206.Va n-1 ; 207with this scheme, a category number would be invalid if it were negative or 208greater than/equal to 209.Va n . 210Each category can have its own list of 211.Nm logging channels 212associated with it; we say that such a channel is 213.Dq in 214the particular category. 215.Sy NOTE : 216Individual logging channels can appear in more than one category. 217.Pp 218A 219.Dq Nm logging context 220is the set of all 221.Nm logging channels 222associated with the context's 223.Nm categories ; 224thus, a particular 225.Nm category 226scheme is associated with a particular 227.Nm logging context . 228.Sy NOTE : 229A logging channel may appear in more than one logging context, and in 230multiple categories within each logging context. 231.Pp 232Use 233.Fn log_add_channel 234and 235.Fn log_remove_channel 236to add or remove a logging channel to some category in a logging context. 237To see if a given category in a logging context is being used, use the 238Boolean test 239.Fn log_category_is_active . 240.Pp 241A 242.Nm logging context 243can also have a 244.Nm priority 245(logging level) 246and various flags associated with the whole context; in order to alter the 247flags or change the priority of a context, use 248.Fn log_option . 249.Ss Message Priorities 250Currently, five 251.Nm priorities 252(logging levels) are supported (they can also be found in the header file): 253.Bd -literal -offset indent 254#define log_critical (-5) 255#define log_error (-4) 256#define log_warning (-3) 257#define log_notice (-2) 258#define log_info (-1) 259.Ed 260.Pp 261In the current implementation, logging messages which have a level greater 262than 0 are considered to be debugging messages. 263.Ss Logging Types 264The three different 265.Nm logging types 266currently supported are different values of the enumerated type 267.Ft log_output_type 268(these are also listed in the header file): 269.Bd -literal -offset indent 270typedef enum { log_syslog, log_file, log_null } log_output_type; 271.Ed 272.Ss Logging Channel Flags 273There are several flags which can be set on a logging channel; the flags 274and their meanings are as follows (they are also found in the header file): 275.Bl -tag -width "LOG_USE_CONTEXT_LEVEL " -offset indent 276.It Dv LOG_CHANNEL_BROKEN 277This is set only when some portion of 278.Fn log_open_stream 279fails: 280.Xr open 2 281or 282.Xr fdopen 3 283fail; 284.Xr stat 2 285fails in a 286.Dq bad 287way; versioning or truncation is requested on a non-normal file. 288.It Dv LOG_CHANNEL_OFF 289This is set for channels opened by 290.Fn log_new_null_channel . 291.It Dv LOG_CLOSE_STREAM 292If this flag is set, then 293.Fn log_free_channel 294will free a 295.No non- Dv NULL 296stream of a logging channel which is being 297.Xr free 3 Ns -d 298(if the logging channel is of type 299.Dv log_file , 300of course). 301.It Dv LOG_PRINT_CATEGORY 302If set, 303.Fn log_vwrite 304will insert the category name, if available, into logging messages which are 305logged to channels of type 306.Dv log_syslog 307or 308.Dv log_file . 309.It Dv LOG_PRINT_LEVEL 310If set, 311.Fn log_vwrite 312will insert a string identifying the message priority level into the 313information logged to channels of type 314.Dv log_syslog 315or 316.Dv log_file . 317.It Dv LOG_REQUIRE_DEBUG 318Only log debugging messages (i.e., those with a priority greater than zero). 319.It Dv LOG_TIMESTAMP 320If set, 321.Fn log_vwrite 322will insert a timestamp into logging messages which are logged to channels of 323type 324.Dv log_syslog 325or 326.Dv log_file . 327.It Dv LOG_TRUNCATE 328Truncate logging file when re-opened 329.Fn ( log_open_stream 330will 331.Xr unlink 2 332the file and then 333.Xr open 2 334a new file of the same name with the 335.Dv O_EXCL 336bit set). 337.It Dv LOG_USE_CONTEXT_LEVEL 338Use the logging context's priority or logging level, rather than the logging 339channel's own priority. This can be useful for those channels which are 340included in multiple logging contexts. 341.El 342.Ss FUNCTION DESCRIPTIONS 343The function 344.Fn log_open_stream 345is for use with channels which log to a file; i.e., logging channels with a 346.Va type 347field set to 348.Dq Dv log_file . 349If the logging channel pointed to by 350.Dq Fa chan 351is valid, it attempts to open (and return) the stream associated with that 352channel. If the stream is already opened, then it is returned; otherwise, 353.Xr stat 2 354is used to test the filename for the stream. 355.Pp 356At this point, if the logging file is supposed to have different 357.Va versions 358(i.e., incremented version numbers; higher numbers indicate older versions 359of the logging file). If so, then any existing versions are 360.Xr rename 2 Ns -d 361to have one version-number higher than previously, and the 362.Dq current 363filename for the stream is set to the 364.Dq \&.0 365form of the name. Next, if the logging file is supposed to be truncated 366(i.e., the 367.Dv LOG_TRUNCATE 368bit of the 369.Va flags 370field of the logging channel structure is set), then any file with the 371.Dq current 372filename for the stream is 373.Xr unlink 2 Ns -d . 374.Sy NOTE : 375If the logging file is 376.Em not 377a regular file, and either of the above operations (version numbering 378or truncation) is supposed to take place, a 379.Dv NULL 380file pointer is returned. 381.Pp 382Finally, the filename associated with the logging channel is 383.Xr open 2 Ns -d 384using the appropriate flags and a mode which sets the read/write permissions 385for the user, group, and others. The file descriptor returned by 386.Xr open 2 387is then passed to 388.Xr fopen 3 , 389with the append mode set, and the stream returned by this call is stored 390in the 391.Fa chan 392structure and returned. 393.Pp 394If 395.Fn log_open_stream 396fails at any point, then the 397.Dv LOG_CHANNEL_BROKEN 398bit of the 399.Va flags 400field of the logging channel pointed to by 401.Fa chan 402is set, a 403.Dv NULL 404is returned, and 405.Va errno 406contains pertinent information. 407.Pp 408The 409.Fn log_close_stream 410function closes the stream associated with the logging channel pointed to by 411.Dq Fa chan 412(if 413.Fa chan 414is valid and the stream exists and can be closed properly by 415.Xr fclose 3 ) . 416The stream is set to 417.Dv NULL 418even if the call to 419.Xr fclose 3 420fails. 421.Pp 422The function 423.Fn log_get_stream 424returns the stream associated with the logging channel pointed to by 425.Dq Fa chan , 426if it is 427.No non- Ns Dv NULL 428and specifies a logging channel which has a 429.Dv FILE * 430or stream associated with it. 431.Pp 432The 433.Fn log_get_filename 434function returns the name of the file associated with the logging channel 435pointed to by 436.Dq Fa chan , 437if it is 438.No non- Ns Dv NULL 439and specifies a logging channel which has a file associated with it. 440.Pp 441The 442.Fn log_vwrite 443function performs the actual logging of a message to the various logging 444channels of a logging context 445.Fa lc . 446The message consists of an 447.Xr fprint 3 Ns -style 448.Fa format 449and its associated 450.Fa args 451(if any); it will be written to all logging channels in the given 452.Fa category 453which have a priority set to 454.Fa level 455or any 456.Em less important 457priority value. If the 458.Fa category 459is not valid or has no logging channels, then the category defaults to 0. 460.Pp 461There are a number of conditions under which a call to 462.Fn log_vwrite 463will not result in actually logging the message: if there is no logging channel 464at even the default category (0), or if a given channel is either 465.Dq broken 466or 467.Dq off 468(i.e., its flags have 469.Dv LOG_CHANNEL_BROKEN 470or 471.Dv LOG_CHANNEL_OFF 472set, respectively), or if the logging channel channel is of type 473.Dv log_null . 474Additionally, if the logging channel's flag has 475.Dv LOG_REQUIRE_DEBUG 476set and the message is not a debugging message (i.e., has a level greater 477than 0), then it will not be logged. 478Finally, if the message's priority is less important than the 479channel's logging level (the priority threshold), will not be logged. 480.Sy NOTE : 481If a logging channel's flag has 482.Dv LOG_USE_CONTEXT_LEVEL 483set, it will use the logging context's priority, rather than its own. 484.Pp 485If all of these hurdles are passed, then only 486.Dv log_syslog 487and 488.Dv log_file 489channels actually can have logging. For channels which use 490.Xr syslog 3 , 491the channel's 492.Xr syslog 3 493facility is used in conjunction with a potentially modified form of the 494message's priority level, since 495.Xr syslog 3 496has its own system of priorities 497.Pq Pa /usr/include/syslog.h . 498All debug messages (priority >= 0) are mapped to 499.Xr syslog 3 Ns 's 500.Dv LOG_DEBUG 501priority, all messages 502.Dq more important 503than 504.Dv log_critical 505are mapped to 506.Dv LOG_CRIT , 507and the priorities corresponding to the ones listed in the section 508.Sx Message Priorities 509are given the obvious corresponding 510.Xr syslog 3 511priority. 512.Pp 513For 514.Dv log_file 515type logging channels, if the file size is greater than the maximum file 516size, then no logging occurs. (The same thing happens if a 517.Dv NULL 518stream is encountered and 519.Fn log_open_stream 520fails to open the channel's stream.) 521.Pp 522For both logging to normal files and logging via 523.Xr syslog 3 , 524the value of the flags 525.Dv LOG_TIMESTAMP , 526.Dv LOG_PRINT_CATEGORY , 527and 528.Dv LOG_PRINT_LEVEL 529are used in determining whether or not these items are included in the logged 530information. 531.Pp 532The 533.Fn log_write 534function is merely a front-end to a call to 535.Fn log_vwrite ; 536see the description of that function, above, for more information. 537.Pp 538.Fn log_check 539and 540.Fn log_check_channel 541are used to see if a contemplated logging call will actually generate any 542output, which is useful when creating a log message involves non-trivial 543work. 544.Fn log_check 545will return non-zero if a call to 546.Fn log_vwrite 547with the given 548.Fa category 549and 550.Fa level 551would generate output on any channels, and zero otherwise. 552.Fn log_check_channel 553will return non-zero if writing to the 554.Fa chan 555at the given 556.Fa level 557would generate output. 558.Pp 559The function 560.Fn log_new_context 561creates a new 562.Nm logging context , 563and stores this in the 564.Dq Va opaque 565field of the argument 566.Dq Fa lc , 567and opaque structure used internally. This new 568.Nm context 569will include the 570.Dq Fa num_categories 571and 572.Dq Fa category_names 573which are supplied; the latter can be 574.Dv NULL . 575.Sy NOTE : 576Since 577.Dq Fa category_names 578is used directly, it 579.Em must not 580be freed by the caller, if it is 581.No non- Ns Dv NULL . 582The initial logging flags and priority are both set to zero. 583.Pp 584The 585.Fn log_free_context 586function is used to free the opaque structure 587.Dq Va lc.opaque 588and its components. 589.Sy NOTE : 590The 591.Dq Va opaque 592field of 593.Dq Fa lc 594.Em must 595be 596.No non- Ns Dv NULL . 597For each of the various 598.Dq categories 599(indicated by the 600.Dq Va num_categories 601which were in the corresponding call to 602.Fn log_new_context ) 603associated with the given 604.Nm logging context , 605.Em all 606of the 607.Nm logging channels 608are 609.Xr free 3 Ns -d . 610The opaque structure itself is then 611.Xr free 3 Ns -d , 612and 613.Dq Va lc.opaque 614is set to 615.Dv NULL . 616.Pp 617.Sy NOTE : 618The function 619.Fn log_free_context 620does 621.Em not 622free the memory associated with 623.Fa category_names , 624since the logging library did not allocate the memory for it, originally; 625it was supplied in the call to 626.Fn log_new_context . 627.Pp 628The function 629.Fn log_add_channel 630adds the 631.Nm logging channel 632.Dq Fa chan 633to the list of logging channels in the given 634.Fa category 635of the 636.Nm logging context 637.Dq Fa lc . 638No checking is performed to see whether or not 639.Fa chan 640is already present in the given 641.Fa category , 642so multiple instances in a single 643.Fa category 644can occur (but see 645.Fn log_remove_channel , 646below). 647.Pp 648The 649.Fn log_remove_channel 650function 651removes 652.Em all 653occurrences of the 654.Nm logging channel 655.Dq Fa chan 656from the list of logging channels in the given 657.Fa category 658of the 659.Nm logging context 660.Dq Fa lc . 661It also attempts to free the channel by calling 662.Fn log_free_channel 663(see its description, below). 664.Pp 665The 666.Fn log_option 667function is used to change the 668.Fa option 669of the indicated logging context 670.Fa lc 671to the given 672.Fa value . 673The 674.Fa option 675can be either 676.Dv LOG_OPTION_LEVEL 677or 678.Dv LOG_OPTION_DEBUG ; 679in the first case, the log context's debugging level is reset to the 680indicated level. If the 681.Fa option 682is 683.Dv LOG_OPTION_DEBUG , 684then a non-zero 685.Fa value 686results in setting the debug flag of the logging context, while a zero 687.Fa value 688means that the debug flag is reset. 689.Pp 690The 691.Fn log_category_is_active 692test returns a 1 if the given 693.Fa category 694of the indicated logging context 695.Fa lc 696has at least one logging channel, and 0, otherwise. 697.Pp 698The functions 699.Fn log_new_syslog_channel , 700.Fn log_new_file_channel , 701and 702.Fn log_new_null_channel 703create a new channel of the type specified (thus, the difference in arguments); 704the 705.Dq Va type 706field of the new 707.Do 708.Ft struct log_channel 709.Dc 710is always set to the appropriate value. 711.Pp 712The 713.Fn log_new_syslog_channel 714function 715.Xr malloc 3 Ns -s 716a new 717.Ft struct log_channel 718of 719.Va type 720.Dv log_syslog , 721i.e., a logging channel which will use 722.Xr syslog 3 . 723The new structure is filled out with the 724.Dq Fa flags , 725.Dq Fa level , 726and 727.Dq Fa facility 728which are given; the 729.Va references 730field is initialized to zero. 731See 732.Sx Logging Channel Flags 733and 734.Sx Message Priorities , 735above, or the header file for information about acceptable values for 736.Dq Fa flags , 737and 738.Dq Fa level . 739The 740.Dq Fa facility . 741can be any valid 742.Xr syslog 3 743facility; see the appropriate system header file or manpage for more 744information. 745.Pp 746.Ft log_channel 747.Fn log_new_file_channel "unsigned int flags" "int level" \ 748 "char *name" "FILE *stream" "unsigned int versions" \ 749 "unsigned long max_size" 750.Pp 751.Fn log_new_null_channel 752.Pp 753The functions 754.Fn log_inc_references 755and 756.Fn log_dec_references 757increment or decrements, respectively, the 758.Va references 759field of the logging channel pointed to by 760.Dq Fa chan , 761if it is a valid channel (and if the 762.Va references 763field is strictly positive, in the case of 764.Fn log_dec_references ) . 765These functions are meant to track changes in the number of different clients 766which refer to the given logging channel. 767.Pp 768The 769.Fn log_free_channel 770function frees the 771field of the logging channel pointed to by 772.Dq Fa chan 773if there are no more outstanding references to it. If the channel uses a file, 774the stream is 775.Xr fclose 3 Ns -d 776(if the 777.Dv LOG_CLOSE_STREAM 778flag is set), and the filename, if 779.No non- Ns Dv NULL , 780is 781.Xr free 3 Ns -d 782before 783.Dq Fa chan 784is 785.Xr free 3 Ns -d . 786.Pp 787.\" The following requests should be uncommented and 788.\" used where appropriate. This next request is 789.\" for sections 2 and 3 function return values only. 790.Sh RETURN VALUES 791.\" This next request is for sections 1, 6, 7 & 8 only 792.Bl -tag -width "log_category_is_active()" 793.It Fn log_open_stream 794.Dv NULL 795is returned under any of several error conditions: 796a) if 797.Dq Fa chan 798is either 799.Dv NULL 800or a 801.No non- Ns Dv log_file 802channel 803.Pq Va errno No is set to Dv EINVAL ; 804b) if either versioning or truncation is requested for a non-normal file 805.Pq Va errno No is set to Dv EINVAL ; 806c) if any of 807.Xr stat 2 , 808.Xr open 2 , 809or 810.Xr fdopen 3 811fails 812.Po 813.Va errno 814is set by the call which failed 815.Pc . 816If some value other than 817.Dv NULL 818is returned, then it is a valid logging stream (either newly-opened or 819already-open). 820.It Fn log_close_stream 821-1 if the stream associated with 822.Dq Fa chan 823is 824.No non- Ns Dv NULL 825and the call to 826.Xr fclose 3 827fails. 8280 if successful or the logging channel pointed to by 829.Dq Fa chan 830is invalid (i.e., 831.Dv NULL 832or not a logging channel which has uses a file); in the latter case, 833.Va errno 834is set to 835.Dv EINVAL . 836.It Fn log_get_stream 837.Dv NULL 838under the same conditions as those under which 839.Fn log_close_stream , 840above, returns 0 (including the setting of 841.Va errno ) . 842Otherwise, the stream associated with the logging channel is returned. 843.It Fn log_get_filename 844.Dv NULL 845under the same conditions as those under which 846.Fn log_close_stream , 847above, returns 0 (including the setting of 848.Va errno ) . 849Otherwise, the name of the file associated with the logging channel is 850returned. 851.It Fn log_new_context 852-1 if 853.Xr malloc 3 854fails 855.Pq with Va errno No set to Dv ENOMEM . 856Otherwise, 0, with 857.Dq Va lc->opaque 858containing the new structures and information. 859.It Fn log_add_channel 860-1 if 861a) either 862.Dq Va lc.opaque 863is 864.Dv NULL 865or 866.Fa category 867is invalid (negative or greater than or equal to 868.Va lcp->num_categories ) , 869with 870.Va errno 871set to 872.Dv EINVAL ; 873b) 874.Xr malloc 3 875fails 876.Pq with Va errno No set to Dv ENOMEM . 877Otherwise, 0. 878.It Fn log_remove_channel 879-1 if 880a) either 881.Dq Va lc.opaque 882is 883.Dv NULL 884or 885.Fa category 886is invalid, as under failure condition a) for 887.Fn log_add_channel , 888above, including the setting of 889.Va errno ; 890b) no channel numbered 891.Fa chan 892is found in the logging context indicated by 893.Fa lc 894.Pq with Va errno No set to Dv ENOENT . 895Otherwise, 0. 896.It Fn log_option 897-1 if 898a) 899.Dq Va lc.opaque 900is 901.Dv NULL , 902b) 903.Fa option 904specifies an unknown logging option; 905in either case, 906.Va errno 907is set to 908.Dv EINVAL . 909Otherwise, 0. 910.It Fn log_category_is_active 911-1 if 912.Dq Va lc.opaque 913is 914.Dv NULL 915.Pq with Va errno No set to Dv EINVAL ; 9161 if the 917.Fa category 918number is valid and there are logging channels in this 919.Fa category 920within the indicated logging context; 0 if the 921.Fa category 922number is invalid or there are no logging channels in this 923.Fa category 924within the indicated logging context. 925.It Fn log_new_syslog_channel 926.Dv NULL 927if 928.Xr malloc 3 929fails 930.Pq with Va errno No set to ENOMEM ; 931otherwise, a valid 932.Dv log_syslog Ns -type 933.Ft log_channel . 934.It Fn log_new_file_channel 935.Dv NULL 936if 937.Xr malloc 3 938fails 939.Pq with Va errno No set to ENOMEM ; 940otherwise, a valid 941.Dv log_file Ns -type 942.Ft log_channel . 943.It Fn log_new_null_channel 944.Dv NULL 945if 946.Xr malloc 3 947fails 948.Pq with Va errno No set to ENOMEM ; 949otherwise, a valid 950.Dv log_null Ns -type 951.Ft log_channel . 952.It Fn log_inc_references 953-1 if 954.Dq Fa chan 955is 956.Dv NULL 957.Pq with Va errno set to Dv EINVAL . 958Otherwise, 0. 959.It Fn log_dec_references 960-1 if 961.Dq Fa chan 962is 963.Dv NULL 964or its 965.Va references 966field is already <= 0 967.Pq with Va errno set to Dv EINVAL . 968Otherwise, 0. 969.It Fn log_free_channel 970-1 under the same conditions as 971.Fn log_dec_references , 972above, including the setting of 973.Va errno ; 9740 otherwise. 975.El 976.\" .Sh ENVIRONMENT 977.Sh FILES 978.Bl -tag -width "isc/logging.h" 979.It Pa isc/logging.h 980include file for logging library 981.It Pa syslog.h 982.Xr syslog 3 Ns -style 983priorities 984.El 985.\" .Sh EXAMPLES 986.\" This next request is for sections 1, 6, 7 & 8 only 987.\" (command return values (to shell) and 988.\" fprintf/stderr type diagnostics) 989.\" .Sh DIAGNOSTICS 990.\" The next request is for sections 2 and 3 error 991.\" and signal handling only. 992.Sh ERRORS 993This table shows which functions can return the indicated error in the 994.Va errno 995variable; see the 996.Sx RETURN VALUES 997section, above, for more information. 998.Bl -tag -width "(any0other0value)0" 999.It Dv EINVAL 1000.Fn log_open_stream , 1001.Fn log_close_stream , 1002.Fn log_get_stream , 1003.Fn log_get_filename , 1004.Fn log_add_channel , 1005.Fn log_remove_channel , 1006.Fn log_option , 1007.Fn log_category_is_active , 1008.Fn log_inc_references , 1009.Fn log_dec_references , 1010.Fn log_free_channel . 1011.It Dv ENOENT 1012.Fn log_remove_channel . 1013.It Dv ENOMEM 1014.Fn log_new_context , 1015.Fn log_add_channel , 1016.Fn log_new_syslog_channel , 1017.Fn log_new_file_channel , 1018.Fn log_new_null_channel . 1019.It (any other value) 1020returned via a pass-through of an error code from 1021.Xr stat 2 , 1022.Xr open 2 , 1023or 1024.Xr fdopen 3 , 1025which can occur in 1026.Fn log_open_stream 1027and functions which call it 1028.Pq currently, only Fn log_vwrite . 1029.El 1030.Pp 1031Additionally, 1032.Fn log_vwrite 1033and 1034.Fn log_free_context 1035will fail via 1036.Fn assert 1037if 1038.Dq Va lc.opaque 1039is 1040.Dv NULL . 1041The function 1042.Fn log_vwrite 1043can also exit with a critical error logged via 1044.Xr syslog 3 1045indicating a memory overrun 1046.Sh SEE ALSO 1047.Xr @INDOT@named @SYS_OPS_EXT@ , 1048.Xr syslog 3 . 1049The HTML documentation includes a file, 1050.Pa logging.html , 1051which has more information about this logging system. 1052.\" .Sh STANDARDS 1053.\" .Sh HISTORY 1054.Sh AUTHORS 1055Bob Halley...TODO 1056.\" .Sh BUGS 1057