Merge from vendor branch WPA_SUPPLICANT:
[dragonfly.git] / contrib / bind-9.2.4rc7 / lib / isc / include / isc / log.h
1 /*
2  * Copyright (C) 2004  Internet Systems Consortium, Inc. ("ISC")
3  * Copyright (C) 1999-2003  Internet Software Consortium.
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15  * PERFORMANCE OF THIS SOFTWARE.
16  */
17
18 /* $Id: log.h,v 1.39.2.6 2004/04/10 04:30:06 marka Exp $ */
19
20 #ifndef ISC_LOG_H
21 #define ISC_LOG_H 1
22
23 #include <stdio.h>
24 #include <stdarg.h>
25 #include <syslog.h> /* XXXDCL NT */
26
27 #include <isc/formatcheck.h>
28 #include <isc/lang.h>
29 #include <isc/platform.h>
30 #include <isc/types.h>
31
32 /*
33  * Severity levels, patterned after Unix's syslog levels.
34  *
35  * ISC_LOG_DYNAMIC can only be used for defining channels with
36  * isc_log_createchannel(), not to specify a level in isc_log_write().
37  */
38 #define ISC_LOG_DEBUG(level)    (level)
39 #define ISC_LOG_DYNAMIC           0
40 #define ISC_LOG_INFO            (-1)
41 #define ISC_LOG_NOTICE          (-2)
42 #define ISC_LOG_WARNING         (-3)
43 #define ISC_LOG_ERROR           (-4)
44 #define ISC_LOG_CRITICAL        (-5)
45
46 /*
47  * Destinations.
48  */
49 #define ISC_LOG_TONULL          1
50 #define ISC_LOG_TOSYSLOG        2
51 #define ISC_LOG_TOFILE          3
52 #define ISC_LOG_TOFILEDESC      4
53
54 /*
55  * Channel flags.
56  */
57 #define ISC_LOG_PRINTTIME       0x0001
58 #define ISC_LOG_PRINTLEVEL      0x0002
59 #define ISC_LOG_PRINTCATEGORY   0x0004
60 #define ISC_LOG_PRINTMODULE     0x0008
61 #define ISC_LOG_PRINTTAG        0x0010
62 #define ISC_LOG_PRINTALL        0x001F
63 #define ISC_LOG_DEBUGONLY       0x1000
64 #define ISC_LOG_OPENERR         0x8000          /* internal */
65
66 /*
67  * Other options.
68  * XXXDCL INFINITE doesn't yet work.  Arguably it isn't needed, but
69  *   since I am intend to make large number of versions work efficiently,
70  *   INFINITE is going to be trivial to add to that.
71  */
72 #define ISC_LOG_ROLLINFINITE    (-1)
73 #define ISC_LOG_ROLLNEVER       (-2)
74
75 /*
76  * Used to name the categories used by a library.  An array of isc_logcategory
77  * structures names each category, and the id value is initialized by calling
78  * isc_log_registercategories.
79  */
80 struct isc_logcategory {
81         const char *name;
82         unsigned int id;
83 };
84
85 /*
86  * Similar to isc_logcategory above, but for all the modules a library defines.
87  */
88 struct isc_logmodule {
89         const char *name;
90         unsigned int id;
91 };
92
93 /*
94  * The isc_logfile structure is initialized as part of an isc_logdestination
95  * before calling isc_log_createchannel().  When defining an ISC_LOG_TOFILE
96  * channel the name, versions and maximum_size should be set before calling
97  * isc_log_createchannel().  To define an ISC_LOG_TOFILEDESC channel set only
98  * the stream before the call.
99  * 
100  * Setting maximum_size to zero implies no maximum.
101  */
102 typedef struct isc_logfile {
103         FILE *stream;           /* Initialized to NULL for ISC_LOG_TOFILE. */
104         const char *name;       /* NULL for ISC_LOG_TOFILEDESC. */
105         int versions;   /* >= 0, ISC_LOG_ROLLNEVER, ISC_LOG_ROLLINFINITE. */
106         /*
107          * stdio's ftell is standardized to return a long, which may well not
108          * be big enough for the largest file supportable by the operating
109          * system (though it is _probably_ big enough for the largest log
110          * anyone would want).  st_size returned by fstat should be typedef'd
111          * to a size large enough for the largest possible file on a system.
112          */
113         isc_offset_t maximum_size;
114         isc_boolean_t maximum_reached; /* Private. */
115 } isc_logfile_t;
116
117 /*
118  * Passed to isc_log_createchannel to define the attributes of either
119  * a stdio or a syslog log.
120  */
121 typedef union isc_logdestination {
122         isc_logfile_t file;
123         int facility;           /* XXXDCL NT */
124 } isc_logdestination_t;
125
126 /*
127  * The built-in categories of libisc.
128  *
129  * Each library registering categories should provide library_LOGCATEGORY_name
130  * definitions with indexes into its isc_logcategory structure corresponding to
131  * the order of the names.
132  */
133 LIBISC_EXTERNAL_DATA extern isc_logcategory_t isc_categories[];
134 LIBISC_EXTERNAL_DATA extern isc_log_t *isc_lctx;
135 LIBISC_EXTERNAL_DATA extern isc_logmodule_t isc_modules[];
136
137 /*
138  * Do not log directly to DEFAULT.  Use another category.  When in doubt,
139  * use GENERAL.
140  */
141 #define ISC_LOGCATEGORY_DEFAULT (&isc_categories[0])
142 #define ISC_LOGCATEGORY_GENERAL (&isc_categories[1])
143
144 #define ISC_LOGMODULE_SOCKET (&isc_modules[0])
145 #define ISC_LOGMODULE_TIME (&isc_modules[1])
146
147 ISC_LANG_BEGINDECLS
148
149 isc_result_t
150 isc_log_create(isc_mem_t *mctx, isc_log_t **lctxp, isc_logconfig_t **lcfgp);
151 /*
152  * Establish a new logging context, with default channels.
153  *
154  * Notes:
155  *      isc_log_create calls isc_logconfig_create, so see its comment
156  *      below for more information.
157  *
158  * Requires:
159  *      mctx is a valid memory context.
160  *      lctxp is not null and *lctxp is null.
161  *      lcfgp is null or lcfgp is not null and *lcfgp is null.
162  *
163  * Ensures:
164  *      *lctxp will point to a valid logging context if all of the necessary
165  *      memory was allocated, or NULL otherwise.
166  *      *lcfgp will point to a valid logging configuration if all of the
167  *      necessary memory was allocated, or NULL otherwise.
168  *      On failure, no additional memory is allocated.
169  *
170  * Returns:
171  *      ISC_R_SUCCESS           Success
172  *      ISC_R_NOMEMORY          Resource limit: Out of memory
173  */
174
175 isc_result_t
176 isc_logconfig_create(isc_log_t *lctx, isc_logconfig_t **lcfgp);
177 /*
178  * Create the data structure that holds all of the configurable information
179  * about where messages are actually supposed to be sent -- the information
180  * that could changed based on some configuration file, as opposed to the
181  * the category/module specification of isc_log_[v]write[1] that is compiled
182  * into a program, or the debug_level which is dynamic state information.
183  *
184  * Notes:
185  *      It is necessary to specify the logging context the configuration
186  *      will be used with because the number of categories and modules
187  *      needs to be known in order to set the configuration.  However,
188  *      the configuration is not used by the logging context until the
189  *      isc_logconfig_use function is called.
190  *
191  *      The memory context used for operations that allocate memory for
192  *      the configuration is that of the logging context, as specified
193  *      in the isc_log_create call.
194  *
195  *      Four default channels are established:
196  *              default_syslog
197  *               - log to syslog's daemon facility ISC_LOG_INFO or higher
198  *              default_stderr
199  *               - log to stderr ISC_LOG_INFO or higher
200  *              default_debug
201  *               - log to stderr ISC_LOG_DEBUG dynamically
202  *              null
203  *               - log nothing
204  *
205  * Requires:
206  *      lctx is a valid logging context.
207  *      lcftp is not null and *lcfgp is null.
208  *
209  * Ensures:
210  *      *lcfgp will point to a valid logging context if all of the necessary
211  *      memory was allocated, or NULL otherwise.
212  *      On failure, no additional memory is allocated.
213  *
214  * Returns:
215  *      ISC_R_SUCCESS           Success
216  *      ISC_R_NOMEMORY          Resource limit: Out of memory
217  */
218
219 isc_logconfig_t *
220 isc_logconfig_get(isc_log_t *lctx);
221 /*
222  * Returns a pointer to the configuration currently in use by the log context.
223  *
224  * Requires:
225  *      lctx is a valid context.
226  *
227  * Ensures:
228  *      The configuration pointer is non-null.
229  *
230  * Returns:
231  *      The configuration pointer.
232  */
233
234 isc_result_t
235 isc_logconfig_use(isc_log_t *lctx, isc_logconfig_t *lcfg);
236 /*
237  * Associate a new configuration with a logging context.
238  *
239  * Notes:
240  *      This is thread safe.  The logging context will lock a mutex
241  *      before attempting to swap in the new configuration, and isc_log_doit
242  *      (the internal function used by all of isc_log_[v]write[1]) locks
243  *      the same lock for the duration of its use of the configuration.
244  *
245  * Requires:
246  *      lctx is a valid logging context.
247  *      lcfg is a valid logging configuration.
248  *      lctx is the same configuration given to isc_logconfig_create
249  *              when the configuration was created.
250  *
251  * Ensures:
252  *      Future calls to isc_log_write will use the new configuration.
253  *
254  * Returns:
255  *      ISC_R_SUCCESS           Success
256  *      ISC_R_NOMEMORY          Resource limit: Out of memory
257  */
258
259 void
260 isc_log_destroy(isc_log_t **lctxp);
261 /*
262  * Deallocate the memory associated with a logging context.
263  *
264  * Requires:
265  *      *lctx is a valid logging context.
266  *
267  * Ensures:
268  *      All of the memory associated with the logging context is returned
269  *      to the free memory pool.
270  *
271  *      Any open files are closed.
272  *
273  *      The logging context is marked as invalid.
274  */
275
276 void
277 isc_logconfig_destroy(isc_logconfig_t **lcfgp);
278 /*
279  * Destroy a logging configuration.
280  *
281  * Notes:
282  *      This function cannot be used directly with the return value of
283  *      isc_logconfig_get, because a logging context must always have
284  *      a valid configuration associated with it.
285  *
286  * Requires:
287  *      lcfgp is not null and *lcfgp is a valid logging configuration.
288  *      The logging configuration is not in use by an existing logging context.
289  *
290  * Ensures:
291  *      All memory allocated for the configuration is freed.
292  *
293  *      The configuration is marked as invalid.
294  */
295
296 void
297 isc_log_registercategories(isc_log_t *lctx, isc_logcategory_t categories[]);
298 /*
299  * Identify logging categories a library will use.
300  *
301  * Notes:
302  *      A category should only be registered once, but no mechanism enforces
303  *      this rule.
304  *
305  *      The end of the categories array is identified by a NULL name.
306  *
307  *      Because the name is used by ISC_LOG_PRINTCATEGORY, it should not
308  *      be altered or destroyed after isc_log_registercategories().
309  *
310  *      Because each element of the categories array is used by
311  *      isc_log_categorybyname, it should not be altered or destroyed
312  *      after registration.
313  *
314  *      The value of the id integer in each structure is overwritten
315  *      by this function, and so id need not be initialized to any particular
316  *      value prior to the function call.
317  *
318  *      A subsequent call to isc_log_registercategories with the same
319  *      logging context (but new categories) will cause the last
320  *      element of the categories array from the prior call to have
321  *      its "name" member changed from NULL to point to the new
322  *      categories array, and its "id" member set to UINT_MAX.
323  *
324  * Requires:
325  *      lctx is a valid logging context.
326  *      categories != NULL.
327  *      categories[0].name != NULL.
328  *
329  * Ensures:
330  *      There are references to each category in the logging context,
331  *      so they can be used with isc_log_usechannel() and isc_log_write().
332  */
333
334 void
335 isc_log_registermodules(isc_log_t *lctx, isc_logmodule_t modules[]);
336 /*
337  * Identify logging categories a library will use.
338  *
339  * Notes:
340  *      A module should only be registered once, but no mechanism enforces
341  *      this rule.
342  *
343  *      The end of the modules array is identified by a NULL name.
344  *
345  *      Because the name is used by ISC_LOG_PRINTMODULE, it should not
346  *      be altered or destroyed after isc_log_registermodules().
347  *
348  *      Because each element of the modules array is used by
349  *      isc_log_modulebyname, it should not be altered or destroyed
350  *      after registration.
351  *
352  *      The value of the id integer in each structure is overwritten
353  *      by this function, and so id need not be initialized to any particular
354  *      value prior to the function call.
355  *
356  *      A subsequent call to isc_log_registermodules with the same
357  *      logging context (but new modules) will cause the last
358  *      element of the modules array from the prior call to have
359  *      its "name" member changed from NULL to point to the new
360  *      modules array, and its "id" member set to UINT_MAX.
361  *
362  * Requires:
363  *      lctx is a valid logging context.
364  *      modules != NULL.
365  *      modules[0].name != NULL;
366  *
367  * Ensures:
368  *      Each module has a reference in the logging context, so they can be
369  *      used with isc_log_usechannel() and isc_log_write().
370  */
371
372 isc_result_t
373 isc_log_createchannel(isc_logconfig_t *lcfg, const char *name,
374                       unsigned int type, int level,
375                       const isc_logdestination_t *destination,
376                       unsigned int flags);
377 /*
378  * Specify the parameters of a logging channel.
379  *
380  * Notes:
381  *      The name argument is copied to memory in the logging context, so
382  *      it can be altered or destroyed after isc_log_createchannel().
383  *
384  *      Defining a very large number of channels will have a performance
385  *      impact on isc_log_usechannel(), since the names are searched
386  *      linearly until a match is made.  This same issue does not affect
387  *      isc_log_write, however.
388  *
389  *      Channel names can be redefined; this is primarily useful for programs
390  *      that want their own definition of default_syslog, default_debug
391  *      and default_stderr.
392  *
393  *      Any channel that is redefined will not affect logging that was
394  *      already directed to its original definition, _except_ for the
395  *      default_stderr channel.  This case is handled specially so that
396  *      the default logging category can be changed by redefining
397  *      default_stderr.  (XXXDCL Though now that I think of it, the default
398  *      logging category can be changed with only one additional function
399  *      call by defining a new channel and then calling isc_log_usechannel()
400  *      for ISC_LOGCATEGORY_DEFAULT.)
401  *
402  *      Specifying ISC_LOG_PRINTTIME or ISC_LOG_PRINTTAG for syslog is allowed,
403  *      but probably not what you wanted to do.
404  *
405  *      ISC_LOG_DEBUGONLY will mark the channel as usable only when the
406  *      debug level of the logging context (see isc_log_setdebuglevel)
407  *      is non-zero.
408  *
409  * Requires:
410  *      lcfg is a valid logging configuration.
411  *
412  *      name is not NULL.
413  *
414  *      type is ISC_LOG_TOSYSLOG, ISC_LOG_TOFILE, ISC_LOG_TOFILEDESC or
415  *              ISC_LOG_TONULL.
416  *
417  *      destination is not NULL unless type is ISC_LOG_TONULL.
418  *
419  *      level is >= ISC_LOG_CRITICAL (the most negative logging level).
420  *
421  *      flags does not include any bits aside from the ISC_LOG_PRINT* bits
422  *      or ISC_LOG_DEBUGONLY.
423  *
424  * Ensures:
425  *      ISC_R_SUCCESS
426  *              A channel with the given name is usable with
427  *              isc_log_usechannel().
428  *
429  *      ISC_R_NOMEMORY or ISC_R_UNEXPECTED
430  *              No additional memory is being used by the logging context.
431  *
432  *              Any channel that previously existed with the given name
433  *              is not redefined.
434  *
435  * Returns:
436  *      ISC_R_SUCCESS           Success
437  *      ISC_R_NOMEMORY          Resource limit: Out of memory
438  *      ISC_R_UNEXPECTED        type was out of range and REQUIRE()
439  *                                      was disabled.
440  */
441
442 isc_result_t
443 isc_log_usechannel(isc_logconfig_t *lcfg, const char *name,
444                    const isc_logcategory_t *category,
445                    const isc_logmodule_t *module);
446 /*
447  * Associate a named logging channel with a category and module that
448  * will use it.
449  *
450  * Notes:
451  *      The name is searched for linearly in the set of known channel names
452  *      until a match is found.  (Note the performance impact of a very large
453  *      number of named channels.)  When multiple channels of the same
454  *      name are defined, the most recent definition is found.
455  *
456  *      Specifing a very large number of channels for a category will have
457  *      a moderate impact on performance in isc_log_write(), as each
458  *      call looks up the category for the start of a linked list, which
459  *      it follows all the way to the end to find matching modules.  The
460  *      test for matching modules is  integral, though.
461  *
462  *      If category is NULL, then the channel is associated with the indicated
463  *      module for all known categories (including the "default" category).
464  *
465  *      If module is NULL, then the channel is associated with every module
466  *      that uses that category.
467  *
468  *      Passing both category and module as NULL would make every log message
469  *      use the indicated channel.
470  *
471  *      Specifying a channel that is ISC_LOG_TONULL for a category/module pair
472  *      has no effect on any other channels associated with that pair,
473  *      regardless of ordering.  Thus you cannot use it to "mask out" one
474  *      category/module pair when you have specified some other channel that
475  *      is also used by that category/module pair.
476  *
477  * Requires:
478  *      lcfg is a valid logging configuration.
479  *
480  *      category is NULL or has an id that is in the range of known ids.
481  *
482  *      module is NULL or has an id that is in the range of known ids.
483  *
484  * Ensures:
485  *      ISC_R_SUCCESS
486  *              The channel will be used by the indicated category/module
487  *              arguments.
488  *
489  *      ISC_R_NOMEMORY
490  *              If assignment for a specific category has been requested,
491  *              the channel has not been associated with the indicated
492  *              category/module arguments and no additional memory is
493  *              used by the logging context.
494  *
495  *              If assignment for all categories has been requested
496  *              then _some_ may have succeeded (starting with category
497  *              "default" and progressing through the order of categories
498  *              passed to isc_log_registercategories) and additional memory
499  *              is being used by whatever assignments succeeded.
500  *
501  * Returns:
502  *      ISC_R_SUCCESS   Success
503  *      ISC_R_NOMEMORY  Resource limit: Out of memory
504  */
505
506 void
507 isc_log_write(isc_log_t *lctx, isc_logcategory_t *category,
508               isc_logmodule_t *module, int level,
509               const char *format, ...)
510 ISC_FORMAT_PRINTF(5, 6);
511 /*
512  * Write a message to the log channels.
513  *
514  * Notes:
515  *      Log messages containing natural language text should be logged with
516  *      isc_log_iwrite() to allow for localization.
517  *
518  *      lctx can be NULL; this is allowed so that programs which use
519  *      libraries that use the ISC logging system are not required to
520  *      also use it.
521  *
522  *      The format argument is a printf(3) string, with additional arguments
523  *      as necessary.
524  *
525  * Requires:
526  *      lctx is a valid logging context.
527  *
528  *      The category and module arguments must have ids that are in the
529  *      range of known ids, as estabished by isc_log_registercategories()
530  *      and isc_log_registermodules().
531  *
532  *      level != ISC_LOG_DYNAMIC.  ISC_LOG_DYNAMIC is used only to define
533  *      channels, and explicit debugging level must be identified for
534  *      isc_log_write() via ISC_LOG_DEBUG(level).
535  *
536  *      format != NULL.
537  *
538  * Ensures:
539  *      The log message is written to every channel associated with the
540  *      indicated category/module pair.
541  *
542  * Returns:
543  *      Nothing.  Failure to log a message is not construed as a
544  *      meaningful error.
545  */
546
547 void
548 isc_log_vwrite(isc_log_t *lctx, isc_logcategory_t *category,
549                isc_logmodule_t *module, int level,
550                const char *format, va_list args)
551 ISC_FORMAT_PRINTF(5, 0);
552 /*
553  * Write a message to the log channels.
554  *
555  * Notes:
556  *      lctx can be NULL; this is allowed so that programs which use
557  *      libraries that use the ISC logging system are not required to
558  *      also use it.
559  *
560  *      The format argument is a printf(3) string, with additional arguments
561  *      as necessary.
562  *
563  * Requires:
564  *      lctx is a valid logging context.
565  *
566  *      The category and module arguments must have ids that are in the
567  *      range of known ids, as estabished by isc_log_registercategories()
568  *      and isc_log_registermodules().
569  *
570  *      level != ISC_LOG_DYNAMIC.  ISC_LOG_DYNAMIC is used only to define
571  *      channels, and explicit debugging level must be identified for
572  *      isc_log_write() via ISC_LOG_DEBUG(level).
573  *
574  *      format != NULL.
575  *
576  * Ensures:
577  *      The log message is written to every channel associated with the
578  *      indicated category/module pair.
579  *
580  * Returns:
581  *      Nothing.  Failure to log a message is not construed as a
582  *      meaningful error.
583  */
584
585 void
586 isc_log_write1(isc_log_t *lctx, isc_logcategory_t *category,
587                isc_logmodule_t *module, int level, const char *format, ...)
588 ISC_FORMAT_PRINTF(5, 6);
589 /*
590  * Write a message to the log channels, pruning duplicates that occur within
591  * a configurable amount of seconds (see isc_log_[sg]etduplicateinterval).
592  * This function is otherwise identical to isc_log_write().
593  */
594
595 void
596 isc_log_vwrite1(isc_log_t *lctx, isc_logcategory_t *category,
597                 isc_logmodule_t *module, int level, const char *format,
598                 va_list args)
599 ISC_FORMAT_PRINTF(5, 0);
600 /*
601  * Write a message to the log channels, pruning duplicates that occur within
602  * a configurable amount of seconds (see isc_log_[sg]etduplicateinterval).
603  * This function is otherwise identical to isc_log_vwrite().
604  */
605
606 void
607 isc_log_iwrite(isc_log_t *lctx, isc_logcategory_t *category,
608               isc_logmodule_t *module, int level,
609               isc_msgcat_t *msgcat, int msgset, int message,
610               const char *format, ...)
611 ISC_FORMAT_PRINTF(8, 9);
612
613 void
614 isc_log_ivwrite(isc_log_t *lctx, isc_logcategory_t *category,
615                 isc_logmodule_t *module, int level,
616                 isc_msgcat_t *msgcat, int msgset, int message,
617                 const char *format, va_list args)
618 ISC_FORMAT_PRINTF(8, 0);
619
620 void
621 isc_log_iwrite1(isc_log_t *lctx, isc_logcategory_t *category,
622                 isc_logmodule_t *module, int level,
623                 isc_msgcat_t *msgcat, int msgset, int message,
624                 const char *format, ...)
625 ISC_FORMAT_PRINTF(8, 9);
626
627 void
628 isc_log_ivwrite1(isc_log_t *lctx, isc_logcategory_t *category,
629                  isc_logmodule_t *module, int level,
630                  isc_msgcat_t *msgcat, int msgset, int message,
631                  const char *format, va_list args)
632 ISC_FORMAT_PRINTF(8, 0);
633 /*
634  * These are four internationalized versions of the the isc_log_[v]write[1]
635  * functions.  The only difference is that they take arguments for a message
636  * catalog, message set, and message number, all immediately preceding the
637  * format argument.  The format argument becomes the default text, a la
638  * isc_msgcat_get.  If the message catalog is NULL, no lookup is attempted
639  * for a message -- which makes the message set and message number irrelevant,
640  * and the non-internationalized call should have probably been used instead.
641  *
642  * Yes, that means there are now *eight* interfaces to logging a message.
643  * Sheesh.   Make the madness stop!
644  */
645
646 void
647 isc_log_setdebuglevel(isc_log_t *lctx, unsigned int level);
648 /*
649  * Set the debugging level used for logging.
650  *
651  * Notes:
652  *      Setting the debugging level to 0 disables debugging log messages.
653  *
654  * Requires:
655  *      lctx is a valid logging context.
656  *
657  * Ensures:
658  *      The debugging level is set to the requested value.
659  */
660
661 unsigned int
662 isc_log_getdebuglevel(isc_log_t *lctx);
663 /*
664  * Get the current debugging level.
665  *
666  * Notes:
667  *      This is provided so that a program can have a notion of
668  *      "increment debugging level" or "decrement debugging level"
669  *      without needing to keep track of what the current level is.
670  *
671  *      A return value of 0 indicates that debugging messages are disabled.
672  *
673  * Requires:
674  *      lctx is a valid logging context.
675  *
676  * Ensures:
677  *      The current logging debugging level is returned.
678  */
679
680 isc_boolean_t
681 isc_log_wouldlog(isc_log_t *lctx, int level);
682 /*
683  * Determine whether logging something to 'lctx' at 'level' would
684  * actually cause something to be logged somewhere.
685  *
686  * If ISC_FALSE is returned, it is guaranteed that nothing would
687  * be logged, allowing the caller to omit unnecessary
688  * isc_log_write() calls and possible message preformatting.
689  */
690
691 void
692 isc_log_setduplicateinterval(isc_logconfig_t *lcfg, unsigned int interval);
693 /*
694  * Set the interval over which duplicate log messages will be ignored
695  * by isc_log_[v]write1(), in seconds.
696  *
697  * Notes:
698  *      Increasing the duplicate interval from X to Y will not necessarily
699  *      filter out duplicates of messages logged in Y - X seconds since the
700  *      increase.  (Example: Message1 is logged at midnight.  Message2
701  *      is logged at 00:01:00, when the interval is only 30 seconds, causing
702  *      Message1 to be expired from the log message history.  Then the interval
703  *      is increased to 3000 (five minutes) and at 00:04:00 Message1 is logged
704  *      again.  It will appear the second time even though less than five
705  *      passed since the first occurrence.
706  *
707  * Requires:
708  *      lctx is a valid logging context.
709  */
710
711 unsigned int
712 isc_log_getduplicateinterval(isc_logconfig_t *lcfg);
713 /*
714  * Get the current duplicate filtering interval.
715  *
716  * Requires:
717  *      lctx is a valid logging context.
718  *
719  * Returns:
720  *      The current duplicate filtering interval.
721  */
722
723 isc_result_t
724 isc_log_settag(isc_logconfig_t *lcfg, const char *tag);
725 /*
726  * Set the program name or other identifier for ISC_LOG_PRINTTAG.
727  *
728  * Requires:
729  *      lcfg is a valid logging configuration.
730  *
731  * Notes:
732  *      If this function has not set the tag to a non-NULL, non-empty value,
733  *      then the ISC_LOG_PRINTTAG channel flag will not print anything.
734  *      Unlike some implementations of syslog on Unix systems, you *must* set
735  *      the tag in order to get it logged.  It is not implicitly derived from
736  *      the program name (which is pretty impossible to infer portably).
737  *
738  *      Setting the tag to NULL or the empty string will also cause the
739  *      ISC_LOG_PRINTTAG channel flag to not print anything.  If tag equals the
740  *      empty string, calls to isc_log_gettag will return NULL.
741  *
742  *      Because the name is used by ISC_LOG_PRINTTAG, it should not be
743  *      altered or destroyed after isc_log_settag().
744  *
745  * Returns:
746  *      ISC_R_SUCCESS   Success
747  *      ISC_R_NOMEMORY  Resource Limit: Out of memory
748  *
749  * XXXDCL when creating a new isc_logconfig_t, it might be nice if the tag
750  * of the currently active isc_logconfig_t was inherited.  this does not
751  * currently happen.
752  */
753
754 char *
755 isc_log_gettag(isc_logconfig_t *lcfg);
756 /*
757  * Get the current identifier printed with ISC_LOG_PRINTTAG.
758  *
759  * Requires:
760  *      lcfg is a valid logging configuration.
761  *
762  * Notes:
763  *      Since isc_log_settag() will not associate a zero-length string
764  *      with the logging configuration, attempts to do so will cause
765  *      this function to return NULL.  However, a determined programmer
766  *      will observe that (currently) a tag of length greater than zero
767  *      could be set, and then modified to be zero length.
768  *
769  * Returns:
770  *      A pointer to the current identifier, or NULL if none has been set.
771  */
772
773 void
774 isc_log_opensyslog(const char *tag, int options, int facility);
775 /*
776  * Initialize syslog logging.
777  *
778  * Notes:
779  *      XXXDCL NT
780  *      This is currently equivalent to openlog(), but is not going to remain
781  *      that way.  In the meantime, the arguments are all identical to
782  *      those used by openlog(3), as follows:
783  *              tag: The string to use in the position of the program
784  *                      name in syslog messages.  Most (all?) syslogs
785  *                      will use basename(argv[0]) if tag is NULL.
786  *
787  *              options: LOG_CONS, LOG_PID, LOG_NDELAY ... whatever your
788  *                      syslog supports.
789  *
790  *              facility: The default syslog facility.  This is irrelevant
791  *                      since isc_log_write will ALWAYS use the channel's
792  *                      declared facility.
793  *
794  *      Zero effort has been made (yet) to accomodate systems with openlog()
795  *      that only takes two arguments, or to identify valid syslog
796  *      facilities or options for any given architecture.
797  *
798  *      It is necessary to call isc_log_opensyslog() to initialize
799  *      syslogging on machines which do not support network connections to
800  *      syslogd because they require a Unix domain socket to be used.  Since
801  *      this is a chore to determine at run-time, it is suggested that it
802  *      always be called by programs using the ISC logging system.
803  *
804  * Requires:
805  *      Nothing.
806  *
807  * Ensures:
808  *      openlog() is called to initialize the syslog system.
809  */
810
811 void
812 isc_log_closefilelogs(isc_log_t *lctx);
813 /*
814  * Close all open files used by ISC_LOG_TOFILE channels.
815  *
816  * Notes:
817  *      This function is provided for programs that want to use their own
818  *      log rolling mechanism rather than the one provided internally.
819  *      For example, a program that wanted to keep daily logs would define
820  *      a channel which used ISC_LOG_ROLLNEVER, then once a day would
821  *      rename the log file and call isc_log_closefilelogs().
822  *
823  *      ISC_LOG_TOFILEDESC channels are unaffected.
824  *
825  * Requires:
826  *      lctx is a valid context.
827  *
828  * Ensures:
829  *      The open files are closed and will be reopened when they are
830  *      next needed.
831  */
832
833 isc_logcategory_t *
834 isc_log_categorybyname(isc_log_t *lctx, const char *name);
835 /*
836  * Find a category by its name.
837  *
838  * Notes:
839  *      The string name of a category is not required to be unique.
840  *
841  * Requires:
842  *      lctx is a valid context.
843  *      name is not NULL.
844  *
845  * Returns:
846  *      A pointer to the _first_ isc_logcategory_t structure used by "name".
847  *
848  *      NULL if no category exists by that name.
849  */
850
851 isc_logmodule_t *
852 isc_log_modulebyname(isc_log_t *lctx, const char *name);
853 /*
854  * Find a module by its name.
855  *
856  * Notes:
857  *      The string name of a module is not required to be unique.
858  *
859  * Requires:
860  *      lctx is a valid context.
861  *      name is not NULL.
862  *
863  * Returns:
864  *      A pointer to the _first_ isc_logmodule_t structure used by "name".
865  *
866  *      NULL if no module exists by that name.
867  */
868
869 void
870 isc_log_setcontext(isc_log_t *lctx);
871 /*
872  * Sets the context used by the libisc for logging.
873  *
874  * Requires:
875  *      lctx be a valid context.
876  */
877
878 ISC_LANG_ENDDECLS
879
880 #endif /* ISC_LOG_H */