home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / isc / log.h < prev    next >
Encoding:
C/C++ Source or Header  |  2008-09-17  |  28.2 KB  |  914 lines

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