log.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004-2007, 2009, 2014  Internet Systems Consortium, Inc. ("ISC")
00003  * Copyright (C) 1999-2002  Internet Software Consortium.
00004  *
00005  * Permission to use, copy, modify, and/or distribute this software for any
00006  * purpose with or without fee is hereby granted, provided that the above
00007  * copyright notice and this permission notice appear in all copies.
00008  *
00009  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
00010  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
00011  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
00012  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00013  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00014  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00015  * PERFORMANCE OF THIS SOFTWARE.
00016  */
00017 
00018 /* $Id: log.h,v 1.59 2009/02/16 02:01:16 marka Exp $ */
00019 
00020 #ifndef ISC_LOG_H
00021 #define ISC_LOG_H 1
00022 
00023 /*! \file isc/log.h */
00024 
00025 #include <stdio.h>
00026 #include <stdarg.h>
00027 #include <syslog.h> /* XXXDCL NT */
00028 
00029 #include <isc/formatcheck.h>
00030 #include <isc/lang.h>
00031 #include <isc/platform.h>
00032 #include <isc/types.h>
00033 
00034 /*@{*/
00035 /*!
00036  * \brief Severity levels, patterned after Unix's syslog levels.
00037  *
00038  */
00039 #define ISC_LOG_DEBUG(level)    (level)
00040 /*!
00041  * #ISC_LOG_DYNAMIC can only be used for defining channels with
00042  * isc_log_createchannel(), not to specify a level in isc_log_write().
00043  */
00044 #define ISC_LOG_DYNAMIC           0
00045 #define ISC_LOG_INFO            (-1)
00046 #define ISC_LOG_NOTICE          (-2)
00047 #define ISC_LOG_WARNING         (-3)
00048 #define ISC_LOG_ERROR           (-4)
00049 #define ISC_LOG_CRITICAL        (-5)
00050 /*@}*/
00051 
00052 /*@{*/
00053 /*!
00054  * \brief Destinations.
00055  */
00056 #define ISC_LOG_TONULL          1
00057 #define ISC_LOG_TOSYSLOG        2
00058 #define ISC_LOG_TOFILE          3
00059 #define ISC_LOG_TOFILEDESC      4
00060 /*@}*/
00061 
00062 /*@{*/
00063 /*%
00064  * Channel flags.
00065  */
00066 #define ISC_LOG_PRINTTIME       0x0001
00067 #define ISC_LOG_PRINTLEVEL      0x0002
00068 #define ISC_LOG_PRINTCATEGORY   0x0004
00069 #define ISC_LOG_PRINTMODULE     0x0008
00070 #define ISC_LOG_PRINTTAG        0x0010          /* tag and ":" */
00071 #define ISC_LOG_PRINTPREFIX     0x0020          /* tag only, no colon */
00072 #define ISC_LOG_PRINTALL        0x003F
00073 #define ISC_LOG_BUFFERED        0x0040
00074 #define ISC_LOG_DEBUGONLY       0x1000
00075 #define ISC_LOG_OPENERR         0x8000          /* internal */
00076 /*@}*/
00077 
00078 /*@{*/
00079 /*!
00080  * \brief Other options.
00081  *
00082  * XXXDCL INFINITE doesn't yet work.  Arguably it isn't needed, but
00083  *   since I am intend to make large number of versions work efficiently,
00084  *   INFINITE is going to be trivial to add to that.
00085  */
00086 #define ISC_LOG_ROLLINFINITE    (-1)
00087 #define ISC_LOG_ROLLNEVER       (-2)
00088 /*@}*/
00089 
00090 /*!
00091  * \brief Used to name the categories used by a library.
00092  *
00093  * An array of isc_logcategory
00094  * structures names each category, and the id value is initialized by calling
00095  * isc_log_registercategories.
00096  */
00097 struct isc_logcategory {
00098         const char *name;
00099         unsigned int id;
00100 };
00101 
00102 /*%
00103  * Similar to isc_logcategory, but for all the modules a library defines.
00104  */
00105 struct isc_logmodule {
00106         const char *name;
00107         unsigned int id;
00108 };
00109 
00110 /*%
00111  * The isc_logfile structure is initialized as part of an isc_logdestination
00112  * before calling isc_log_createchannel().
00113  *
00114  * When defining an #ISC_LOG_TOFILE
00115  * channel the name, versions and maximum_size should be set before calling
00116  * isc_log_createchannel().  To define an #ISC_LOG_TOFILEDESC channel set only
00117  * the stream before the call.
00118  *
00119  * Setting maximum_size to zero implies no maximum.
00120  */
00121 typedef struct isc_logfile {
00122         FILE *stream;           /*%< Initialized to NULL for #ISC_LOG_TOFILE. */
00123         const char *name;       /*%< NULL for #ISC_LOG_TOFILEDESC. */
00124         int versions;   /* >= 0, #ISC_LOG_ROLLNEVER, #ISC_LOG_ROLLINFINITE. */
00125         /*%
00126          * stdio's ftell is standardized to return a long, which may well not
00127          * be big enough for the largest file supportable by the operating
00128          * system (though it is _probably_ big enough for the largest log
00129          * anyone would want).  st_size returned by fstat should be typedef'd
00130          * to a size large enough for the largest possible file on a system.
00131          */
00132         isc_offset_t maximum_size;
00133         isc_boolean_t maximum_reached; /*%< Private. */
00134 } isc_logfile_t;
00135 
00136 /*%
00137  * Passed to isc_log_createchannel to define the attributes of either
00138  * a stdio or a syslog log.
00139  */
00140 typedef union isc_logdestination {
00141         isc_logfile_t file;
00142         int facility;           /* XXXDCL NT */
00143 } isc_logdestination_t;
00144 
00145 /*@{*/
00146 /*%
00147  * The built-in categories of libisc.
00148  *
00149  * Each library registering categories should provide library_LOGCATEGORY_name
00150  * definitions with indexes into its isc_logcategory structure corresponding to
00151  * the order of the names.
00152  */
00153 LIBISC_EXTERNAL_DATA extern isc_logcategory_t isc_categories[];
00154 LIBISC_EXTERNAL_DATA extern isc_log_t *isc_lctx;
00155 LIBISC_EXTERNAL_DATA extern isc_logmodule_t isc_modules[];
00156 /*@}*/
00157 
00158 /*@{*/
00159 /*%
00160  * Do not log directly to DEFAULT.  Use another category.  When in doubt,
00161  * use GENERAL.
00162  */
00163 #define ISC_LOGCATEGORY_DEFAULT (&isc_categories[0])
00164 #define ISC_LOGCATEGORY_GENERAL (&isc_categories[1])
00165 /*@}*/
00166 
00167 #define ISC_LOGMODULE_SOCKET (&isc_modules[0])
00168 #define ISC_LOGMODULE_TIME (&isc_modules[1])
00169 #define ISC_LOGMODULE_INTERFACE (&isc_modules[2])
00170 #define ISC_LOGMODULE_TIMER (&isc_modules[3])
00171 #define ISC_LOGMODULE_FILE (&isc_modules[4])
00172 #define ISC_LOGMODULE_OTHER (&isc_modules[5])
00173 
00174 ISC_LANG_BEGINDECLS
00175 
00176 isc_result_t
00177 isc_log_create(isc_mem_t *mctx, isc_log_t **lctxp, isc_logconfig_t **lcfgp);
00178 /*%<
00179  * Establish a new logging context, with default channels.
00180  *
00181  * Notes:
00182  *\li   isc_log_create() calls isc_logconfig_create(), so see its comment
00183  *      below for more information.
00184  *
00185  * Requires:
00186  *\li   mctx is a valid memory context.
00187  *\li   lctxp is not null and *lctxp is null.
00188  *\li   lcfgp is null or lcfgp is not null and *lcfgp is null.
00189  *
00190  * Ensures:
00191  *\li   *lctxp will point to a valid logging context if all of the necessary
00192  *      memory was allocated, or NULL otherwise.
00193  *\li   *lcfgp will point to a valid logging configuration if all of the
00194  *      necessary memory was allocated, or NULL otherwise.
00195  *\li   On failure, no additional memory is allocated.
00196  *
00197  * Returns:
00198  *\li   #ISC_R_SUCCESS          Success
00199  *\li   #ISC_R_NOMEMORY         Resource limit: Out of memory
00200  */
00201 
00202 isc_result_t
00203 isc_logconfig_create(isc_log_t *lctx, isc_logconfig_t **lcfgp);
00204 /*%<
00205  * Create the data structure that holds all of the configurable information
00206  * about where messages are actually supposed to be sent -- the information
00207  * that could changed based on some configuration file, as opposed to the
00208  * the category/module specification of isc_log_[v]write[1] that is compiled
00209  * into a program, or the debug_level which is dynamic state information.
00210  *
00211  * Notes:
00212  *\li   It is necessary to specify the logging context the configuration
00213  *      will be used with because the number of categories and modules
00214  *      needs to be known in order to set the configuration.  However,
00215  *      the configuration is not used by the logging context until the
00216  *      isc_logconfig_use function is called.
00217  *
00218  *\li   The memory context used for operations that allocate memory for
00219  *      the configuration is that of the logging context, as specified
00220  *      in the isc_log_create call.
00221  *
00222  *\li   Four default channels are established:
00223  *\verbatim
00224  *              default_syslog
00225  *               - log to syslog's daemon facility #ISC_LOG_INFO or higher
00226  *              default_stderr
00227  *               - log to stderr #ISC_LOG_INFO or higher
00228  *              default_debug
00229  *               - log to stderr #ISC_LOG_DEBUG dynamically
00230  *              null
00231  *               - log nothing
00232  *\endverbatim
00233  *
00234  * Requires:
00235  *\li   lctx is a valid logging context.
00236  *\li   lcftp is not null and *lcfgp is null.
00237  *
00238  * Ensures:
00239  *\li   *lcfgp will point to a valid logging context if all of the necessary
00240  *      memory was allocated, or NULL otherwise.
00241  *\li   On failure, no additional memory is allocated.
00242  *
00243  * Returns:
00244  *\li   #ISC_R_SUCCESS          Success
00245  *\li   #ISC_R_NOMEMORY         Resource limit: Out of memory
00246  */
00247 
00248 isc_logconfig_t *
00249 isc_logconfig_get(isc_log_t *lctx);
00250 /*%<
00251  * Returns a pointer to the configuration currently in use by the log context.
00252  *
00253  * Requires:
00254  *\li   lctx is a valid context.
00255  *
00256  * Ensures:
00257  *\li   The configuration pointer is non-null.
00258  *
00259  * Returns:
00260  *\li   The configuration pointer.
00261  */
00262 
00263 isc_result_t
00264 isc_logconfig_use(isc_log_t *lctx, isc_logconfig_t *lcfg);
00265 /*%<
00266  * Associate a new configuration with a logging context.
00267  *
00268  * Notes:
00269  *\li   This is thread safe.  The logging context will lock a mutex
00270  *      before attempting to swap in the new configuration, and isc_log_doit
00271  *      (the internal function used by all of isc_log_[v]write[1]) locks
00272  *      the same lock for the duration of its use of the configuration.
00273  *
00274  * Requires:
00275  *\li   lctx is a valid logging context.
00276  *\li   lcfg is a valid logging configuration.
00277  *\li   lctx is the same configuration given to isc_logconfig_create
00278  *              when the configuration was created.
00279  *
00280  * Ensures:
00281  *\li   Future calls to isc_log_write will use the new configuration.
00282  *
00283  * Returns:
00284  *\li   #ISC_R_SUCCESS          Success
00285  *\li   #ISC_R_NOMEMORY         Resource limit: Out of memory
00286  */
00287 
00288 void
00289 isc_log_destroy(isc_log_t **lctxp);
00290 /*%<
00291  * Deallocate the memory associated with a logging context.
00292  *
00293  * Requires:
00294  *\li   *lctx is a valid logging context.
00295  *
00296  * Ensures:
00297  *\li   All of the memory associated with the logging context is returned
00298  *      to the free memory pool.
00299  *
00300  *\li   Any open files are closed.
00301  *
00302  *\li   The logging context is marked as invalid.
00303  */
00304 
00305 void
00306 isc_logconfig_destroy(isc_logconfig_t **lcfgp);
00307 /*%<
00308  * Destroy a logging configuration.
00309  *
00310  * Notes:
00311  *\li   This function cannot be used directly with the return value of
00312  *      isc_logconfig_get, because a logging context must always have
00313  *      a valid configuration associated with it.
00314  *
00315  * Requires:
00316  *\li   lcfgp is not null and *lcfgp is a valid logging configuration.
00317  *\li   The logging configuration is not in use by an existing logging context.
00318  *
00319  * Ensures:
00320  *\li   All memory allocated for the configuration is freed.
00321  *
00322  *\li   The configuration is marked as invalid.
00323  */
00324 
00325 void
00326 isc_log_registercategories(isc_log_t *lctx, isc_logcategory_t categories[]);
00327 /*%<
00328  * Identify logging categories a library will use.
00329  *
00330  * Notes:
00331  *\li   A category should only be registered once, but no mechanism enforces
00332  *      this rule.
00333  *
00334  *\li   The end of the categories array is identified by a NULL name.
00335  *
00336  *\li   Because the name is used by #ISC_LOG_PRINTCATEGORY, it should not
00337  *      be altered or destroyed after isc_log_registercategories().
00338  *
00339  *\li   Because each element of the categories array is used by
00340  *      isc_log_categorybyname, it should not be altered or destroyed
00341  *      after registration.
00342  *
00343  *\li   The value of the id integer in each structure is overwritten
00344  *      by this function, and so id need not be initialized to any particular
00345  *      value prior to the function call.
00346  *
00347  *\li   A subsequent call to isc_log_registercategories with the same
00348  *      logging context (but new categories) will cause the last
00349  *      element of the categories array from the prior call to have
00350  *      its "name" member changed from NULL to point to the new
00351  *      categories array, and its "id" member set to UINT_MAX.
00352  *
00353  * Requires:
00354  *\li   lctx is a valid logging context.
00355  *\li   categories != NULL.
00356  *\li   categories[0].name != NULL.
00357  *
00358  * Ensures:
00359  * \li  There are references to each category in the logging context,
00360  *      so they can be used with isc_log_usechannel() and isc_log_write().
00361  */
00362 
00363 void
00364 isc_log_registermodules(isc_log_t *lctx, isc_logmodule_t modules[]);
00365 /*%<
00366  * Identify logging categories a library will use.
00367  *
00368  * Notes:
00369  *\li   A module should only be registered once, but no mechanism enforces
00370  *      this rule.
00371  *
00372  *\li   The end of the modules array is identified by a NULL name.
00373  *
00374  *\li   Because the name is used by #ISC_LOG_PRINTMODULE, it should not
00375  *      be altered or destroyed after isc_log_registermodules().
00376  *
00377  *\li   Because each element of the modules array is used by
00378  *      isc_log_modulebyname, it should not be altered or destroyed
00379  *      after registration.
00380  *
00381  *\li   The value of the id integer in each structure is overwritten
00382  *      by this function, and so id need not be initialized to any particular
00383  *      value prior to the function call.
00384  *
00385  *\li   A subsequent call to isc_log_registermodules with the same
00386  *      logging context (but new modules) will cause the last
00387  *      element of the modules array from the prior call to have
00388  *      its "name" member changed from NULL to point to the new
00389  *      modules array, and its "id" member set to UINT_MAX.
00390  *
00391  * Requires:
00392  *\li   lctx is a valid logging context.
00393  *\li   modules != NULL.
00394  *\li   modules[0].name != NULL;
00395  *
00396  * Ensures:
00397  *\li   Each module has a reference in the logging context, so they can be
00398  *      used with isc_log_usechannel() and isc_log_write().
00399  */
00400 
00401 isc_result_t
00402 isc_log_createchannel(isc_logconfig_t *lcfg, const char *name,
00403                       unsigned int type, int level,
00404                       const isc_logdestination_t *destination,
00405                       unsigned int flags);
00406 /*%<
00407  * Specify the parameters of a logging channel.
00408  *
00409  * Notes:
00410  *\li   The name argument is copied to memory in the logging context, so
00411  *      it can be altered or destroyed after isc_log_createchannel().
00412  *
00413  *\li   Defining a very large number of channels will have a performance
00414  *      impact on isc_log_usechannel(), since the names are searched
00415  *      linearly until a match is made.  This same issue does not affect
00416  *      isc_log_write, however.
00417  *
00418  *\li   Channel names can be redefined; this is primarily useful for programs
00419  *      that want their own definition of default_syslog, default_debug
00420  *      and default_stderr.
00421  *
00422  *\li   Any channel that is redefined will not affect logging that was
00423  *      already directed to its original definition, _except_ for the
00424  *      default_stderr channel.  This case is handled specially so that
00425  *      the default logging category can be changed by redefining
00426  *      default_stderr.  (XXXDCL Though now that I think of it, the default
00427  *      logging category can be changed with only one additional function
00428  *      call by defining a new channel and then calling isc_log_usechannel()
00429  *      for #ISC_LOGCATEGORY_DEFAULT.)
00430  *
00431  *\li   Specifying #ISC_LOG_PRINTTIME or #ISC_LOG_PRINTTAG for syslog is
00432  *      allowed, but probably not what you wanted to do.
00433  *
00434  *      #ISC_LOG_DEBUGONLY will mark the channel as usable only when the
00435  *      debug level of the logging context (see isc_log_setdebuglevel)
00436  *      is non-zero.
00437  *
00438  * Requires:
00439  *\li   lcfg is a valid logging configuration.
00440  *
00441  *\li   name is not NULL.
00442  *
00443  *\li   type is #ISC_LOG_TOSYSLOG, #ISC_LOG_TOFILE, #ISC_LOG_TOFILEDESC or
00444  *              #ISC_LOG_TONULL.
00445  *
00446  *\li   destination is not NULL unless type is #ISC_LOG_TONULL.
00447  *
00448  *\li   level is >= #ISC_LOG_CRITICAL (the most negative logging level).
00449  *
00450  *\li   flags does not include any bits aside from the ISC_LOG_PRINT* bits,
00451  *      #ISC_LOG_DEBUGONLY or #ISC_LOG_BUFFERED.
00452  *
00453  * Ensures:
00454  *\li   #ISC_R_SUCCESS
00455  *              A channel with the given name is usable with
00456  *              isc_log_usechannel().
00457  *
00458  *\li   #ISC_R_NOMEMORY or #ISC_R_UNEXPECTED
00459  *              No additional memory is being used by the logging context.
00460  *              Any channel that previously existed with the given name
00461  *              is not redefined.
00462  *
00463  * Returns:
00464  *\li   #ISC_R_SUCCESS          Success
00465  *\li   #ISC_R_NOMEMORY         Resource limit: Out of memory
00466  *\li   #ISC_R_UNEXPECTED       type was out of range and REQUIRE()
00467  *                                      was disabled.
00468  */
00469 
00470 isc_result_t
00471 isc_log_usechannel(isc_logconfig_t *lcfg, const char *name,
00472                    const isc_logcategory_t *category,
00473                    const isc_logmodule_t *module);
00474 /*%<
00475  * Associate a named logging channel with a category and module that
00476  * will use it.
00477  *
00478  * Notes:
00479  *\li   The name is searched for linearly in the set of known channel names
00480  *      until a match is found.  (Note the performance impact of a very large
00481  *      number of named channels.)  When multiple channels of the same
00482  *      name are defined, the most recent definition is found.
00483  *
00484  *\li   Specifying a very large number of channels for a category will have
00485  *      a moderate impact on performance in isc_log_write(), as each
00486  *      call looks up the category for the start of a linked list, which
00487  *      it follows all the way to the end to find matching modules.  The
00488  *      test for matching modules is  integral, though.
00489  *
00490  *\li   If category is NULL, then the channel is associated with the indicated
00491  *      module for all known categories (including the "default" category).
00492  *
00493  *\li   If module is NULL, then the channel is associated with every module
00494  *      that uses that category.
00495  *
00496  *\li   Passing both category and module as NULL would make every log message
00497  *      use the indicated channel.
00498  *
00499  * \li  Specifying a channel that is #ISC_LOG_TONULL for a category/module pair
00500  *      has no effect on any other channels associated with that pair,
00501  *      regardless of ordering.  Thus you cannot use it to "mask out" one
00502  *      category/module pair when you have specified some other channel that
00503  *      is also used by that category/module pair.
00504  *
00505  * Requires:
00506  *\li   lcfg is a valid logging configuration.
00507  *
00508  *\li   category is NULL or has an id that is in the range of known ids.
00509  *
00510  *      module is NULL or has an id that is in the range of known ids.
00511  *
00512  * Ensures:
00513  *\li   #ISC_R_SUCCESS
00514  *              The channel will be used by the indicated category/module
00515  *              arguments.
00516  *
00517  *\li   #ISC_R_NOMEMORY
00518  *              If assignment for a specific category has been requested,
00519  *              the channel has not been associated with the indicated
00520  *              category/module arguments and no additional memory is
00521  *              used by the logging context.
00522  *              If assignment for all categories has been requested
00523  *              then _some_ may have succeeded (starting with category
00524  *              "default" and progressing through the order of categories
00525  *              passed to isc_log_registercategories()) and additional memory
00526  *              is being used by whatever assignments succeeded.
00527  *
00528  * Returns:
00529  *\li   #ISC_R_SUCCESS  Success
00530  *\li   #ISC_R_NOMEMORY Resource limit: Out of memory
00531  */
00532 
00533 /* Attention: next four comments PRECEED code */
00534 /*!
00535  *   \brief
00536  * Write a message to the log channels.
00537  *
00538  * Notes:
00539  *\li   Log messages containing natural language text should be logged with
00540  *      isc_log_iwrite() to allow for localization.
00541  *
00542  *\li   lctx can be NULL; this is allowed so that programs which use
00543  *      libraries that use the ISC logging system are not required to
00544  *      also use it.
00545  *
00546  *\li   The format argument is a printf(3) string, with additional arguments
00547  *      as necessary.
00548  *
00549  * Requires:
00550  *\li   lctx is a valid logging context.
00551  *
00552  *\li   The category and module arguments must have ids that are in the
00553  *      range of known ids, as established by isc_log_registercategories()
00554  *      and isc_log_registermodules().
00555  *
00556  *\li   level != #ISC_LOG_DYNAMIC.  ISC_LOG_DYNAMIC is used only to define
00557  *      channels, and explicit debugging level must be identified for
00558  *      isc_log_write() via ISC_LOG_DEBUG(level).
00559  *
00560  *\li   format != NULL.
00561  *
00562  * Ensures:
00563  *\li   The log message is written to every channel associated with the
00564  *      indicated category/module pair.
00565  *
00566  * Returns:
00567  *\li   Nothing.  Failure to log a message is not construed as a
00568  *      meaningful error.
00569  */
00570 void
00571 isc_log_write(isc_log_t *lctx, isc_logcategory_t *category,
00572                isc_logmodule_t *module, int level,
00573               const char *format, ...)
00574 
00575 ISC_FORMAT_PRINTF(5, 6);
00576 
00577 /*%
00578  * Write a message to the log channels.
00579  *
00580  * Notes:
00581  *\li   lctx can be NULL; this is allowed so that programs which use
00582  *      libraries that use the ISC logging system are not required to
00583  *      also use it.
00584  *
00585  *\li   The format argument is a printf(3) string, with additional arguments
00586  *      as necessary.
00587  *
00588  * Requires:
00589  *\li   lctx is a valid logging context.
00590  *
00591  *\li   The category and module arguments must have ids that are in the
00592  *      range of known ids, as established by isc_log_registercategories()
00593  *      and isc_log_registermodules().
00594  *
00595  *\li   level != #ISC_LOG_DYNAMIC.  ISC_LOG_DYNAMIC is used only to define
00596  *      channels, and explicit debugging level must be identified for
00597  *      isc_log_write() via ISC_LOG_DEBUG(level).
00598  *
00599  *\li   format != NULL.
00600  *
00601  * Ensures:
00602  *\li   The log message is written to every channel associated with the
00603  *      indicated category/module pair.
00604  *
00605  * Returns:
00606  *\li   Nothing.  Failure to log a message is not construed as a
00607  *      meaningful error.
00608  */
00609 void
00610 isc_log_vwrite(isc_log_t *lctx, isc_logcategory_t *category,
00611                isc_logmodule_t *module, int level,
00612                const char *format, va_list args)
00613 
00614 ISC_FORMAT_PRINTF(5, 0);
00615 
00616 /*%
00617  * Write a message to the log channels, pruning duplicates that occur within
00618  * a configurable amount of seconds (see isc_log_[sg]etduplicateinterval).
00619  * This function is otherwise identical to isc_log_write().
00620  */
00621 void
00622 isc_log_write1(isc_log_t *lctx, isc_logcategory_t *category,
00623                isc_logmodule_t *module, int level, const char *format, ...)
00624 
00625 ISC_FORMAT_PRINTF(5, 6);
00626 
00627 /*%
00628  * Write a message to the log channels, pruning duplicates that occur within
00629  * a configurable amount of seconds (see isc_log_[sg]etduplicateinterval).
00630  * This function is otherwise identical to isc_log_vwrite().
00631  */
00632 void
00633 isc_log_vwrite1(isc_log_t *lctx, isc_logcategory_t *category,
00634                 isc_logmodule_t *module, int level, const char *format,
00635                 va_list args)
00636 
00637 ISC_FORMAT_PRINTF(5, 0);
00638 
00639 /*%
00640  * These are four internationalized versions of the isc_log_[v]write[1]
00641  * functions.
00642  *
00643  * The only difference is that they take arguments for a message
00644  * catalog, message set, and message number, all immediately preceding the
00645  * format argument.  The format argument becomes the default text, a la
00646  * isc_msgcat_get.  If the message catalog is NULL, no lookup is attempted
00647  * for a message -- which makes the message set and message number irrelevant,
00648  * and the non-internationalized call should have probably been used instead.
00649  *
00650  * Yes, that means there are now *eight* interfaces to logging a message.
00651  * Sheesh.   Make the madness stop!
00652  */
00653 /*@{*/
00654 void
00655 isc_log_iwrite(isc_log_t *lctx, isc_logcategory_t *category,
00656               isc_logmodule_t *module, int level,
00657               isc_msgcat_t *msgcat, int msgset, int message,
00658               const char *format, ...)
00659 ISC_FORMAT_PRINTF(8, 9);
00660 
00661 void
00662 isc_log_ivwrite(isc_log_t *lctx, isc_logcategory_t *category,
00663                 isc_logmodule_t *module, int level,
00664                 isc_msgcat_t *msgcat, int msgset, int message,
00665                 const char *format, va_list args)
00666 ISC_FORMAT_PRINTF(8, 0);
00667 
00668 void
00669 isc_log_iwrite1(isc_log_t *lctx, isc_logcategory_t *category,
00670                 isc_logmodule_t *module, int level,
00671                 isc_msgcat_t *msgcat, int msgset, int message,
00672                 const char *format, ...)
00673 ISC_FORMAT_PRINTF(8, 9);
00674 
00675 void
00676 isc_log_ivwrite1(isc_log_t *lctx, isc_logcategory_t *category,
00677                  isc_logmodule_t *module, int level,
00678                  isc_msgcat_t *msgcat, int msgset, int message,
00679                  const char *format, va_list args)
00680 ISC_FORMAT_PRINTF(8, 0);
00681 /*@}*/
00682 
00683 void
00684 isc_log_setdebuglevel(isc_log_t *lctx, unsigned int level);
00685 /*%<
00686  * Set the debugging level used for logging.
00687  *
00688  * Notes:
00689  *\li   Setting the debugging level to 0 disables debugging log messages.
00690  *
00691  * Requires:
00692  *\li   lctx is a valid logging context.
00693  *
00694  * Ensures:
00695  *\li   The debugging level is set to the requested value.
00696  */
00697 
00698 unsigned int
00699 isc_log_getdebuglevel(isc_log_t *lctx);
00700 /*%<
00701  * Get the current debugging level.
00702  *
00703  * Notes:
00704  *\li   This is provided so that a program can have a notion of
00705  *      "increment debugging level" or "decrement debugging level"
00706  *      without needing to keep track of what the current level is.
00707  *
00708  *\li   A return value of 0 indicates that debugging messages are disabled.
00709  *
00710  * Requires:
00711  *\li   lctx is a valid logging context.
00712  *
00713  * Ensures:
00714  *\li   The current logging debugging level is returned.
00715  */
00716 
00717 isc_boolean_t
00718 isc_log_wouldlog(isc_log_t *lctx, int level);
00719 /*%<
00720  * Determine whether logging something to 'lctx' at 'level' would
00721  * actually cause something to be logged somewhere.
00722  *
00723  * If #ISC_FALSE is returned, it is guaranteed that nothing would
00724  * be logged, allowing the caller to omit unnecessary
00725  * isc_log_write() calls and possible message preformatting.
00726  */
00727 
00728 void
00729 isc_log_setduplicateinterval(isc_logconfig_t *lcfg, unsigned int interval);
00730 /*%<
00731  * Set the interval over which duplicate log messages will be ignored
00732  * by isc_log_[v]write1(), in seconds.
00733  *
00734  * Notes:
00735  *\li   Increasing the duplicate interval from X to Y will not necessarily
00736  *      filter out duplicates of messages logged in Y - X seconds since the
00737  *      increase.  (Example: Message1 is logged at midnight.  Message2
00738  *      is logged at 00:01:00, when the interval is only 30 seconds, causing
00739  *      Message1 to be expired from the log message history.  Then the interval
00740  *      is increased to 3000 (five minutes) and at 00:04:00 Message1 is logged
00741  *      again.  It will appear the second time even though less than five
00742  *      passed since the first occurrence.
00743  *
00744  * Requires:
00745  *\li   lctx is a valid logging context.
00746  */
00747 
00748 unsigned int
00749 isc_log_getduplicateinterval(isc_logconfig_t *lcfg);
00750 /*%<
00751  * Get the current duplicate filtering interval.
00752  *
00753  * Requires:
00754  *\li   lctx is a valid logging context.
00755  *
00756  * Returns:
00757  *\li   The current duplicate filtering interval.
00758  */
00759 
00760 isc_result_t
00761 isc_log_settag(isc_logconfig_t *lcfg, const char *tag);
00762 /*%<
00763  * Set the program name or other identifier for #ISC_LOG_PRINTTAG.
00764  *
00765  * Requires:
00766  *\li   lcfg is a valid logging configuration.
00767  *
00768  * Notes:
00769  *\li   If this function has not set the tag to a non-NULL, non-empty value,
00770  *      then the #ISC_LOG_PRINTTAG channel flag will not print anything.
00771  *      Unlike some implementations of syslog on Unix systems, you *must* set
00772  *      the tag in order to get it logged.  It is not implicitly derived from
00773  *      the program name (which is pretty impossible to infer portably).
00774  *
00775  *\li   Setting the tag to NULL or the empty string will also cause the
00776  *      #ISC_LOG_PRINTTAG channel flag to not print anything.  If tag equals the
00777  *      empty string, calls to isc_log_gettag will return NULL.
00778  *
00779  * Returns:
00780  *\li   #ISC_R_SUCCESS  Success
00781  *\li   #ISC_R_NOMEMORY  Resource Limit: Out of memory
00782  *
00783  * XXXDCL when creating a new isc_logconfig_t, it might be nice if the tag
00784  * of the currently active isc_logconfig_t was inherited.  this does not
00785  * currently happen.
00786  */
00787 
00788 char *
00789 isc_log_gettag(isc_logconfig_t *lcfg);
00790 /*%<
00791  * Get the current identifier printed with #ISC_LOG_PRINTTAG.
00792  *
00793  * Requires:
00794  *\li   lcfg is a valid logging configuration.
00795  *
00796  * Notes:
00797  *\li   Since isc_log_settag() will not associate a zero-length string
00798  *      with the logging configuration, attempts to do so will cause
00799  *      this function to return NULL.  However, a determined programmer
00800  *      will observe that (currently) a tag of length greater than zero
00801  *      could be set, and then modified to be zero length.
00802  *
00803  * Returns:
00804  *\li   A pointer to the current identifier, or NULL if none has been set.
00805  */
00806 
00807 void
00808 isc_log_opensyslog(const char *tag, int options, int facility);
00809 /*%<
00810  * Initialize syslog logging.
00811  *
00812  * Notes:
00813  *\li   XXXDCL NT
00814  *      This is currently equivalent to openlog(), but is not going to remain
00815  *      that way.  In the meantime, the arguments are all identical to
00816  *      those used by openlog(3), as follows:
00817  *
00818  * \code
00819  *              tag: The string to use in the position of the program
00820  *                      name in syslog messages.  Most (all?) syslogs
00821  *                      will use basename(argv[0]) if tag is NULL.
00822  *
00823  *              options: LOG_CONS, LOG_PID, LOG_NDELAY ... whatever your
00824  *                      syslog supports.
00825  *
00826  *              facility: The default syslog facility.  This is irrelevant
00827  *                      since isc_log_write will ALWAYS use the channel's
00828  *                      declared facility.
00829  * \endcode
00830  *
00831  *\li   Zero effort has been made (yet) to accommodate systems with openlog()
00832  *      that only takes two arguments, or to identify valid syslog
00833  *      facilities or options for any given architecture.
00834  *
00835  *\li   It is necessary to call isc_log_opensyslog() to initialize
00836  *      syslogging on machines which do not support network connections to
00837  *      syslogd because they require a Unix domain socket to be used.  Since
00838  *      this is a chore to determine at run-time, it is suggested that it
00839  *      always be called by programs using the ISC logging system.
00840  *
00841  * Requires:
00842  *\li   Nothing.
00843  *
00844  * Ensures:
00845  *\li   openlog() is called to initialize the syslog system.
00846  */
00847 
00848 void
00849 isc_log_closefilelogs(isc_log_t *lctx);
00850 /*%<
00851  * Close all open files used by #ISC_LOG_TOFILE channels.
00852  *
00853  * Notes:
00854  *\li   This function is provided for programs that want to use their own
00855  *      log rolling mechanism rather than the one provided internally.
00856  *      For example, a program that wanted to keep daily logs would define
00857  *      a channel which used #ISC_LOG_ROLLNEVER, then once a day would
00858  *      rename the log file and call isc_log_closefilelogs().
00859  *
00860  *\li   #ISC_LOG_TOFILEDESC channels are unaffected.
00861  *
00862  * Requires:
00863  *\li   lctx is a valid context.
00864  *
00865  * Ensures:
00866  *\li   The open files are closed and will be reopened when they are
00867  *      next needed.
00868  */
00869 
00870 isc_logcategory_t *
00871 isc_log_categorybyname(isc_log_t *lctx, const char *name);
00872 /*%<
00873  * Find a category by its name.
00874  *
00875  * Notes:
00876  *\li   The string name of a category is not required to be unique.
00877  *
00878  * Requires:
00879  *\li   lctx is a valid context.
00880  *\li   name is not NULL.
00881  *
00882  * Returns:
00883  *\li   A pointer to the _first_ isc_logcategory_t structure used by "name".
00884  *
00885  *\li   NULL if no category exists by that name.
00886  */
00887 
00888 isc_logmodule_t *
00889 isc_log_modulebyname(isc_log_t *lctx, const char *name);
00890 /*%<
00891  * Find a module by its name.
00892  *
00893  * Notes:
00894  *\li   The string name of a module is not required to be unique.
00895  *
00896  * Requires:
00897  *\li   lctx is a valid context.
00898  *\li   name is not NULL.
00899  *
00900  * Returns:
00901  *\li   A pointer to the _first_ isc_logmodule_t structure used by "name".
00902  *
00903  *\li   NULL if no module exists by that name.
00904  */
00905 
00906 void
00907 isc_log_setcontext(isc_log_t *lctx);
00908 /*%<
00909  * Sets the context used by the libisc for logging.
00910  *
00911  * Requires:
00912  *\li   lctx be a valid context.
00913  */
00914 
00915 ISC_LANG_ENDDECLS
00916 
00917 #endif /* ISC_LOG_H */

Generated on Tue Apr 28 17:41:04 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha