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