isc_result_t
setup_logging(FILE *errout) {
isc_logconfig_t *logconfig = isc_logconfig_get();
- isc_logdestination_t destination = {
- .file.stream = errout,
- .file.versions = ISC_LOG_ROLLNEVER,
- };
- isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC,
- ISC_LOG_DYNAMIC, &destination, 0);
-
- RUNTIME_CHECK(isc_log_usechannel(logconfig, "stderr",
- ISC_LOGCATEGORY_ALL,
- ISC_LOGMODULE_ALL) == ISC_R_SUCCESS);
+ isc_log_createandusechannel(
+ logconfig, "default_stderr", ISC_LOG_TOFILEDESC,
+ ISC_LOG_DYNAMIC, ISC_LOGDESTINATION_FILE(errout), 0,
+ ISC_LOGCATEGORY_DEFAULT, ISC_LOGMODULE_DEFAULT);
return (ISC_R_SUCCESS);
}
static void
setup_logging(FILE *errout) {
- isc_result_t result;
int packetlevel = 10;
+ isc_log_setdebuglevel(loglevel);
+
isc_logconfig_t *logconfig = isc_logconfig_get();
- isc_logdestination_t destination = {
- .file.stream = errout,
- .file.versions = ISC_LOG_ROLLNEVER,
- };
- isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC,
- ISC_LOG_DYNAMIC, &destination,
- ISC_LOG_PRINTPREFIX);
- isc_log_setdebuglevel(loglevel);
isc_log_settag(logconfig, ";; ");
- result = isc_log_usechannel(logconfig, "stderr",
- ISC_LOGCATEGORY_DEFAULT, ISC_LOGMODULE_ALL);
- if (result != ISC_R_SUCCESS) {
- fatal("Couldn't attach to log channel 'stderr'");
- }
+ isc_log_createandusechannel(
+ logconfig, "default_stderr", ISC_LOG_TOFILEDESC,
+ ISC_LOG_DYNAMIC, ISC_LOGDESTINATION_FILE(errout),
+ ISC_LOG_PRINTPREFIX, ISC_LOGCATEGORY_DEFAULT,
+ ISC_LOGMODULE_DEFAULT);
if (resolve_trace && loglevel < 1) {
- isc_log_createchannel(logconfig, "resolver", ISC_LOG_TOFILEDESC,
- ISC_LOG_DEBUG(1), &destination,
- ISC_LOG_PRINTPREFIX);
-
- result = isc_log_usechannel(logconfig, "resolver",
- DNS_LOGCATEGORY_RESOLVER,
- DNS_LOGMODULE_RESOLVER);
- if (result != ISC_R_SUCCESS) {
- fatal("Couldn't attach to log channel 'resolver'");
- }
+ isc_log_createandusechannel(
+ logconfig, "resolver", ISC_LOG_TOFILEDESC,
+ ISC_LOG_DEBUG(1), ISC_LOGDESTINATION_FILE(errout),
+ ISC_LOG_PRINTPREFIX, DNS_LOGCATEGORY_RESOLVER,
+ DNS_LOGMODULE_RESOLVER);
}
if (validator_trace && loglevel < 3) {
- isc_log_createchannel(logconfig, "validator",
- ISC_LOG_TOFILEDESC, ISC_LOG_DEBUG(3),
- &destination, ISC_LOG_PRINTPREFIX);
-
- result = isc_log_usechannel(logconfig, "validator",
- DNS_LOGCATEGORY_DNSSEC,
- DNS_LOGMODULE_VALIDATOR);
- if (result != ISC_R_SUCCESS) {
- fatal("Couldn't attach to log channel 'validator'");
- }
+ isc_log_createandusechannel(
+ logconfig, "validator", ISC_LOG_TOFILEDESC,
+ ISC_LOG_DEBUG(3), ISC_LOGDESTINATION_FILE(errout),
+ ISC_LOG_PRINTPREFIX, DNS_LOGCATEGORY_DNSSEC,
+ DNS_LOGMODULE_VALIDATOR);
}
if (send_trace) {
packetlevel = 11;
}
if ((message_trace || send_trace) && loglevel < packetlevel) {
- isc_log_createchannel(logconfig, "messages", ISC_LOG_TOFILEDESC,
- ISC_LOG_DEBUG(packetlevel), &destination,
- ISC_LOG_PRINTPREFIX);
-
- result = isc_log_usechannel(logconfig, "messages",
- DNS_LOGCATEGORY_RESOLVER,
- DNS_LOGMODULE_PACKETS);
- if (result != ISC_R_SUCCESS) {
- fatal("Couldn't attach to log channel 'messagse'");
- }
+ isc_log_createandusechannel(
+ logconfig, "messages", ISC_LOG_TOFILEDESC,
+ ISC_LOG_DEBUG(packetlevel),
+ ISC_LOGDESTINATION_FILE(errout), ISC_LOG_PRINTPREFIX,
+ DNS_LOGCATEGORY_RESOLVER, DNS_LOGMODULE_PACKETS);
}
}
isc_managers_create(&mctx, 1, &loopmgr, &netmgr);
logconfig = isc_logconfig_get();
- result = isc_log_usechannel(logconfig, "default_debug",
- ISC_LOGCATEGORY_ALL, ISC_LOGMODULE_ALL);
-
- check_result(result, "isc_log_usechannel");
-
+ isc_log_createandusechannel(logconfig, "debug", ISC_LOG_TOFILEDESC,
+ ISC_LOG_DYNAMIC, ISC_LOGDESTINATION_STDERR,
+ ISC_LOG_PRINTTIME, ISC_LOGCATEGORY_DEFAULT,
+ ISC_LOGMODULE_DEFAULT);
isc_log_setdebuglevel(0);
isc_mem_setname(mctx, "dig");
void
setup_logging(void) {
- isc_logdestination_t destination;
isc_logconfig_t *logconfig = NULL;
int level;
* - the program name and logging level are printed
* - no time stamp is printed
*/
- destination.file.stream = stderr;
- destination.file.name = NULL;
- destination.file.versions = ISC_LOG_ROLLNEVER;
- destination.file.maximum_size = 0;
- isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC, level,
- &destination,
- ISC_LOG_PRINTTAG | ISC_LOG_PRINTLEVEL);
-
- RUNTIME_CHECK(isc_log_usechannel(logconfig, "stderr",
- ISC_LOGCATEGORY_ALL,
- ISC_LOGMODULE_ALL) == ISC_R_SUCCESS);
+ isc_log_createandusechannel(
+ logconfig, "default_stderr", ISC_LOG_TOFILEDESC, level,
+ ISC_LOGDESTINATION_STDERR,
+ ISC_LOG_PRINTTAG | ISC_LOG_PRINTLEVEL, ISC_LOGCATEGORY_DEFAULT,
+ ISC_LOGMODULE_DEFAULT);
}
static isc_stdtime_t
.maximum_size = 100 * 1024 * 1024,
},
};
- isc_result_t result;
if (sslkeylogfile_path == NULL ||
strcmp(sslkeylogfile_path, "config") == 0)
return;
}
- isc_log_createchannel(lcfg, "default_sslkeylogfile", ISC_LOG_TOFILE,
- ISC_LOG_INFO, &destination, 0);
- result = isc_log_usechannel(lcfg, "default_sslkeylogfile",
- ISC_LOGCATEGORY_SSLKEYLOG,
- ISC_LOGMODULE_ALL);
- RUNTIME_CHECK(result == ISC_R_SUCCESS);
+ isc_log_createandusechannel(lcfg, "default_sslkeylogfile",
+ ISC_LOG_TOFILE, ISC_LOG_INFO, &destination,
+ 0, ISC_LOGCATEGORY_SSLKEYLOG,
+ ISC_LOGMODULE_DEFAULT);
}
isc_result_t
isc_result_t result = ISC_R_SUCCESS;
result = isc_log_usechannel(lcfg, "default_debug",
- ISC_LOGCATEGORY_DEFAULT, ISC_LOGMODULE_ALL);
+ ISC_LOGCATEGORY_DEFAULT,
+ ISC_LOGMODULE_DEFAULT);
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
if (named_g_logfile != NULL) {
result = isc_log_usechannel(lcfg, "default_logfile",
ISC_LOGCATEGORY_DEFAULT,
- ISC_LOGMODULE_ALL);
+ ISC_LOGMODULE_DEFAULT);
} else if (!named_g_nosyslog) {
result = isc_log_usechannel(lcfg, "default_syslog",
ISC_LOGCATEGORY_DEFAULT,
- ISC_LOGMODULE_ALL);
+ ISC_LOGMODULE_DEFAULT);
}
}
isc_result_t result;
result = isc_log_usechannel(lcfg, "null", NAMED_LOGCATEGORY_UNMATCHED,
- ISC_LOGMODULE_ALL);
+ ISC_LOGMODULE_DEFAULT);
return (result);
}
isc_result_t result;
const char *catname;
isc_logcategory_t category;
- isc_logmodule_t module;
const cfg_obj_t *destinations = NULL;
const cfg_listelt_t *element = NULL;
return (ISC_R_SUCCESS);
}
- module = ISC_LOGMODULE_ALL;
-
destinations = cfg_tuple_get(ccat, "destinations");
for (element = cfg_list_first(destinations); element != NULL;
element = cfg_list_next(element))
const char *channelname = cfg_obj_asstring(channel);
result = isc_log_usechannel(logconfig, channelname, category,
- module);
+ ISC_LOGMODULE_DEFAULT);
if (result != ISC_R_SUCCESS) {
isc_log_write(CFG_LOGCATEGORY_CONFIG,
NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR,
ddebug("setup_system()");
logconfig = isc_logconfig_get();
- result = isc_log_usechannel(logconfig, "default_debug",
- ISC_LOGCATEGORY_ALL, ISC_LOGMODULE_ALL);
- check_result(result, "isc_log_usechannel");
-
+ isc_log_createandusechannel(logconfig, "debug", ISC_LOG_TOFILEDESC,
+ ISC_LOG_DYNAMIC, ISC_LOGDESTINATION_STDERR,
+ ISC_LOG_PRINTTIME, ISC_LOGCATEGORY_DEFAULT,
+ ISC_LOGMODULE_DEFAULT);
isc_log_setdebuglevel(logdebuglevel);
result = irs_resconf_load(gmctx, resolvconf, &resconf);
isc_result_t result = ISC_R_SUCCESS;
bool show_final_mem = false;
isc_logconfig_t *logconfig = NULL;
- isc_logdestination_t logdest;
cfg_parser_t *pctx = NULL;
cfg_obj_t *config = NULL;
const char *keyname = NULL;
logconfig = isc_logconfig_get();
isc_log_settag(logconfig, progname);
- logdest.file.stream = stderr;
- logdest.file.name = NULL;
- logdest.file.versions = ISC_LOG_ROLLNEVER;
- logdest.file.maximum_size = 0;
- isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC,
- ISC_LOG_INFO, &logdest,
- ISC_LOG_PRINTTAG | ISC_LOG_PRINTLEVEL);
- DO("enabling log channel",
- isc_log_usechannel(logconfig, "stderr", ISC_LOGCATEGORY_ALL,
- ISC_LOGMODULE_ALL));
+ isc_log_createandusechannel(
+ logconfig, "default_stderr", ISC_LOG_TOFILEDESC, ISC_LOG_INFO,
+ ISC_LOGDESTINATION_STDERR,
+ ISC_LOG_PRINTTAG | ISC_LOG_PRINTLEVEL, ISC_LOGCATEGORY_DEFAULT,
+ ISC_LOGMODULE_DEFAULT);
parse_config(rndc_mctx, keyname, &pctx, &config);
isc_result_t result;
char *origin, *file1, *file2, *journal;
dns_db_t *olddb = NULL, *newdb = NULL;
- isc_logdestination_t destination;
isc_logconfig_t *logconfig = NULL;
if (argc != 5) {
isc_mem_create(&mctx);
logconfig = isc_logconfig_get();
- destination.file.stream = stderr;
- destination.file.name = NULL;
- destination.file.versions = ISC_LOG_ROLLNEVER;
- destination.file.maximum_size = 0;
- isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC,
- ISC_LOG_DYNAMIC, &destination, 0);
-
- result = isc_log_usechannel(logconfig, "stderr", ISC_LOGCATEGORY_ALL,
- ISC_LOGMODULE_ALL);
- if (result != ISC_R_SUCCESS) {
- goto cleanup;
- }
+ isc_log_createandusechannel(
+ logconfig, "default_stderr", ISC_LOG_TOFILEDESC,
+ ISC_LOG_DYNAMIC, ISC_LOGDESTINATION_STDERR, 0,
+ ISC_LOGCATEGORY_DEFAULT, ISC_LOGMODULE_DEFAULT);
result = loadzone(&olddb, origin, file1);
if (result != ISC_R_SUCCESS) {
isc_mem_t *mctx;
isc_logconfig_t *logconfig;
int level = ISC_LOG_WARNING;
-isc_logdestination_t destination;
char filename[255];
isc_result_t result;
isc_buffer_t buf;
logconfig = isc_logconfig_get();
isc_log_settag(logconfig, "bigkey");
- destination.file.stream = stderr;
- destination.file.name = NULL;
- destination.file.versions = ISC_LOG_ROLLNEVER;
- destination.file.maximum_size = 0;
- isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC, level,
- &destination,
- ISC_LOG_PRINTTAG | ISC_LOG_PRINTLEVEL);
-
- CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL), "isc_log_"
- "usechannel("
- ")");
+ isc_log_createandusechannel(
+ logconfig, "default_stderr", ISC_LOG_TOFILEDESC, level,
+ ISC_LOGDESTINATION_STDERR,
+ ISC_LOG_PRINTTAG | ISC_LOG_PRINTLEVEL, ISC_LOGCATEGORY_DEFAULT,
+ ISC_LOGMODULE_DEFAULT);
+
name = dns_fixedname_initname(&fname);
isc_buffer_constinit(&buf, "example.", strlen("example."));
isc_buffer_add(&buf, strlen("example."));
*/
static void
setup_logging(FILE *errout) {
- isc_logdestination_t destination;
- isc_logconfig_t *logconfig = NULL;
-
- logconfig = isc_logconfig_get();
- destination.file.stream = errout;
- destination.file.name = NULL;
- destination.file.versions = ISC_LOG_ROLLNEVER;
- destination.file.maximum_size = 0;
- isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC,
- ISC_LOG_DYNAMIC, &destination, 0);
-
- RUNTIME_CHECK(isc_log_usechannel(logconfig, "stderr",
- ISC_LOGCATEGORY_ALL,
- ISC_LOGMODULE_ALL) == ISC_R_SUCCESS);
+ isc_logconfig_t *logconfig = isc_logconfig_get();
+ isc_log_createandusechannel(
+ logconfig, "default_stderr", ISC_LOG_TOFILEDESC,
+ ISC_LOG_DYNAMIC, ISC_LOGDESTINATION_FILE(errout), 0,
+ ISC_LOGCATEGORY_DEFAULT, ISC_LOGMODULE_DEFAULT);
}
int
null, and all other messages to syslog.
result = isc_log_usechannel(lcfg, "default_stderr",
- DNS_LOGCATEGORY_SECURITY, NULL);
+ DNS_LOGCATEGORY_SECURITY, ISC_LOGMODULE_DEFAULT);
if (result != ISC_R_SUCCESS)
oops_it_didnt_work();
result = isc_log_usechannel(lcfg, "null",
- DNS_LOGCATEGORY_DATABASE, NULL);
+ DNS_LOGCATEGORY_DATABASE, ISC_LOGMODULE_DEFAULT);
if (result != ISC_R_SUCCESS)
oops_it_didnt_work();
result = isc_log_usechannel(lcfg, "default_syslog",
- ISC_LOGCATEGORY_DEFAULT, NULL);
+ ISC_LOGCATEGORY_DEFAULT, ISC_LOGMODULE_DEFAULT);
if (result != ISC_R_SUCCESS)
oops_it_didnt_work();
#include <isccfg/namedconf.h>
static void
-check_result(isc_result_t result, const char *format, ...) {
- va_list args;
-
- if (result == ISC_R_SUCCESS) {
- return;
- }
-
- va_start(args, format);
- vfprintf(stderr, format, args);
- va_end(args);
- fprintf(stderr, ": %s\n", isc_result_totext(result));
- exit(EXIT_FAILURE);
-}
-
-static void
-output(void *closure, const char *text, int textlen) {
- UNUSED(closure);
+output(void *closure ISC_ATTR_UNUSED, const char *text, int textlen) {
(void)fwrite(text, 1, textlen, stdout);
}
exit(EXIT_FAILURE);
}
+static void
+setup_logging(void) {
+ isc_logconfig_t *logconfig = isc_logconfig_get();
+ isc_log_createandusechannel(
+ logconfig, "default_stderr", ISC_LOG_TOFILEDESC,
+ ISC_LOG_DYNAMIC, ISC_LOGDESTINATION_STDERR, ISC_LOG_PRINTTIME,
+ ISC_LOGCATEGORY_DEFAULT, ISC_LOGMODULE_DEFAULT);
+}
+
int
main(int argc, char **argv) {
isc_result_t result;
isc_mem_t *mctx = NULL;
- isc_logconfig_t *lcfg = NULL;
- isc_logdestination_t destination;
cfg_parser_t *pctx = NULL;
cfg_obj_t *cfg = NULL;
cfg_type_t *type = NULL;
isc_mem_create(&mctx);
- /*
- * Create and install the default channel.
- */
- lcfg = isc_logconfig_get();
- destination.file.stream = stderr;
- destination.file.name = NULL;
- destination.file.versions = ISC_LOG_ROLLNEVER;
- destination.file.maximum_size = 0;
- isc_log_createchannel(lcfg, "_default", ISC_LOG_TOFILEDESC,
- ISC_LOG_DYNAMIC, &destination, ISC_LOG_PRINTTIME);
-
- result = isc_log_usechannel(lcfg, "_default", ISC_LOGCATEGORY_ALL,
- ISC_LOGMODULE_ALL);
- check_result(result, "isc_log_usechannel()");
+ setup_logging();
/*
* Set the initial debug level.
#include <isc/formatcheck.h>
#include <isc/lang.h>
#include <isc/types.h>
+#include <isc/util.h>
typedef struct isc_logconfig isc_logconfig_t; /*%< Log Configuration */
typedef enum isc_logcategory isc_logcategory_t; /*%< Log Category */
enum isc_logcategory {
/*%
- * Do not log directly to DEFAULT. Use another category.
- * When in doubt, use GENERAL.
+ * Logging to DEFAULT will end with assertion failure. Use another
+ * category. When in doubt, use GENERAL.
*/
- ISC_LOGCATEGORY_ALL = -2,
ISC_LOGCATEGORY_INVALID = -1,
/* isc categories */
ISC_LOGCATEGORY_DEFAULT = 0,
*/
typedef enum isc_logmodule isc_logmodule_t; /*%< Log Module */
enum isc_logmodule {
- ISC_LOGMODULE_ALL = -2,
ISC_LOGMODULE_INVALID = -1,
/* isc modules */
- ISC_LOGMODULE_NONE = 0,
+ ISC_LOGMODULE_DEFAULT = 0,
ISC_LOGMODULE_SOCKET,
ISC_LOGMODULE_TIME,
ISC_LOGMODULE_INTERFACE,
* The isc_logfile structure is initialized as part of an isc_logdestination
* before calling isc_log_createchannel().
*
- * When defining an #ISC_LOG_TOFILE
- * channel the name, versions and maximum_size should be set before calling
- * isc_log_createchannel(). To define an #ISC_LOG_TOFILEDESC channel set only
- * the stream before the call.
+ * When defining an #ISC_LOG_TOFILE channel, the name, versions and
+ * maximum_size should be set before calling isc_log_createchannel(). To
+ * define an #ISC_LOG_TOFILEDESC channel set only the stream before the
+ * call.
*
* Setting maximum_size to zero implies no maximum.
*/
int facility;
} isc_logdestination_t;
-#define ISC_LOGDESTINATION_STDERR \
+#define ISC_LOGDESTINATION_FILE(errout) \
(&(isc_logdestination_t){ \
.file = { \
- .stream = stderr, \
+ .stream = errout, \
.versions = ISC_LOG_ROLLNEVER, \
.suffix = isc_log_rollsuffix_increment, \
} })
+#define ISC_LOGDESTINATION_STDERR ISC_LOGDESTINATION_FILE(stderr)
+
#define ISC_LOGDESTINATION_SYSLOG(f) \
(&(isc_logdestination_t){ .facility = (f) })
* Requires:
*\li lcfg is a valid logging configuration.
*
- *\li category is NULL or has an id that is in the range of known ids.
+ *\li category is ISC_LOGCATEGORY_DEFAULT or has an id that is in the range of
+ * known ids.
*
- * module is NULL or has an id that is in the range of known ids.
+ * module is ISC_LOGMODULE_DEFAULT or has an id that is in the range of
+ * known ids.
*
* Ensures:
- *\li #ISC_R_SUCCESS
- * The channel will be used by the indicated category/module
- * arguments.
- *
- *\li #ISC_R_NOMEMORY
- * If assignment for a specific category has been requested,
- * the channel has not been associated with the indicated
- * category/module arguments and no additional memory is
- * used by the logging context.
- * If assignment for all categories has been requested
- * then _some_ may have succeeded (starting with category
- * "default" and progressing through the order of categories
- * passed to isc_log_registercategories()) and additional memory
- * is being used by whatever assignments succeeded.
- *
- * Returns:
- *\li #ISC_R_SUCCESS Success
- *\li #ISC_R_NOMEMORY Resource limit: Out of memory
+ * The channel will be used by the indicated category/module
+ * arguments.
*/
-/* Attention: next four comments PRECEDE code */
-/*!
+void
+isc_log_createandusechannel(isc_logconfig_t *lcfg, const char *name,
+ unsigned int type, int level,
+ const isc_logdestination_t *destination,
+ unsigned int flags,
+ const isc_logcategory_t category,
+ const isc_logmodule_t module);
+
+/*%<
+ * The isc_log_createchannel() and isc_log_usechannel() functions, combined
+ * into one. (This is for use by utilities that have simpler logging
+ * requirements than named, and don't have to define and assign channels
+ * dynamically.)
+ */
+
+void
+isc_log_write(isc_logcategory_t category, isc_logmodule_t module, int level,
+ const char *format, ...) ISC_FORMAT_PRINTF(4, 5);
+/*%<
* \brief
* Write a message to the log channels.
*
* Notes:
- *\li lctx can be NULL; this is allowed so that programs which use
- * libraries that use the ISC logging system are not required to
- * also use it.
- *
*\li The format argument is a printf(3) string, with additional arguments
* as necessary.
*
* Requires:
- *\li lctx is a valid logging context.
- *
*\li The category and module arguments must have ids that are in the
- * range of known ids, as established by isc_log_registercategories()
- * and isc_log_registermodules().
+ * range of known ids.
+ *
+ *\li category != ISC_LOGCATEGORY_DEFAULT. ISC_LOGCATEGORY_DEFAULT is used
+ * only to define channels.
+ *
+ *\li module != ISC_LOGMODULE_DEFAULT. ISC_LOGMODULE_DEFAULT is used
+ * only to define channels.
*
*\li level != #ISC_LOG_DYNAMIC. ISC_LOG_DYNAMIC is used only to define
* channels, and explicit debugging level must be identified for
*\li Nothing. Failure to log a message is not construed as a
* meaningful error.
*/
-void
-isc_log_write(isc_logcategory_t category, isc_logmodule_t module, int level,
- const char *format, ...)
- ISC_FORMAT_PRINTF(4, 5);
-
-/*%
+void
+isc_log_vwrite(isc_logcategory_t category, isc_logmodule_t module, int level,
+ const char *format, va_list args) ISC_FORMAT_PRINTF(4, 0);
+/*%<
* Write a message to the log channels.
*
- * Notes:
- *\li lctx can be NULL; this is allowed so that programs which use
- * libraries that use the ISC logging system are not required to
- * also use it.
- *
*\li The format argument is a printf(3) string, with additional arguments
* as necessary.
*
* Requires:
- *\li lctx is a valid logging context.
- *
*\li The category and module arguments must have ids that are in the
- * range of known ids, as established by isc_log_registercategories()
- * and isc_log_registermodules().
+ * range of known ids.
+ *
+ *\li category != ISC_LOGCATEGORY_DEFAULT. ISC_LOGCATEGORY_DEFAULT is used
+ * only to define channels.
+ *
+ *\li module != ISC_LOGMODULE_DEFAULT. ISC_LOGMODULE_DEFAULT is used
+ * only to define channels.
*
*\li level != #ISC_LOG_DYNAMIC. ISC_LOG_DYNAMIC is used only to define
* channels, and explicit debugging level must be identified for
*\li Nothing. Failure to log a message is not construed as a
* meaningful error.
*/
-void
-isc_log_vwrite(isc_logcategory_t category, isc_logmodule_t module, int level,
- const char *format, va_list args)
-
- ISC_FORMAT_PRINTF(4, 0);
void
isc_log_setdebuglevel(unsigned int level);
*/
static const char *modules_description[] = {
/* isc modules */
- [ISC_LOGMODULE_NONE] = "no_module",
+ [ISC_LOGMODULE_DEFAULT] = "no_module",
[ISC_LOGMODULE_SOCKET] = "socket",
[ISC_LOGMODULE_TIME] = "time",
[ISC_LOGMODULE_INTERFACE] = "interface",
REQUIRE(level >= ISC_LOG_CRITICAL);
REQUIRE((flags & ~permitted) == 0);
- /* XXXDCL find duplicate names? */
+ /* FIXME: find duplicate names? */
mctx = lcfg->lctx->mctx;
const isc_logmodule_t module) {
REQUIRE(VALID_CONFIG(lcfg));
REQUIRE(name != NULL);
- REQUIRE(category == ISC_LOGCATEGORY_ALL ||
- (category >= 0 && category < ISC_LOGCATEGORY_MAX));
- REQUIRE(module == ISC_LOGMODULE_ALL ||
- (module >= 0 && module < ISC_LOGMODULE_MAX));
+ REQUIRE(category >= ISC_LOGCATEGORY_DEFAULT &&
+ category < ISC_LOGCATEGORY_MAX);
+ REQUIRE(module >= ISC_LOGMODULE_DEFAULT && module < ISC_LOGMODULE_MAX);
isc_logchannel_t *channel;
for (channel = ISC_LIST_HEAD(lcfg->channels); channel != NULL;
return (ISC_R_NOTFOUND);
}
- if (category != ISC_LOGCATEGORY_ALL) {
+ if (category != ISC_LOGCATEGORY_DEFAULT) {
assignchannel(lcfg, category, module, channel);
} else {
/*
* Assign to all categories. Note that this includes
* the default channel.
*/
- for (size_t i = 0; i < ISC_LOGCATEGORY_MAX; i++) {
+ for (size_t i = ISC_LOGCATEGORY_DEFAULT;
+ i < ISC_LOGCATEGORY_MAX; i++)
+ {
assignchannel(lcfg, i, module, channel);
}
}
return (ISC_R_SUCCESS);
}
+void
+isc_log_createandusechannel(isc_logconfig_t *lcfg, const char *name,
+ unsigned int type, int level,
+ const isc_logdestination_t *destination,
+ unsigned int flags,
+ const isc_logcategory_t category,
+ const isc_logmodule_t module) {
+ isc_log_createchannel(lcfg, name, type, level, destination, flags);
+ RUNTIME_CHECK(isc_log_usechannel(lcfg, name, category, module) ==
+ ISC_R_SUCCESS);
+}
+
void
isc_log_write(isc_logcategory_t category, isc_logmodule_t module, int level,
const char *format, ...) {
isc_log_t *lctx = lcfg->lctx;
- REQUIRE(category > ISC_LOGCATEGORY_INVALID &&
+ REQUIRE(category >= ISC_LOGCATEGORY_DEFAULT &&
category < ISC_LOGCATEGORY_MAX);
- REQUIRE(module == ISC_LOGMODULE_ALL ||
- (module > ISC_LOGMODULE_INVALID && module < ISC_LOGMODULE_MAX));
+ REQUIRE(module >= ISC_LOGMODULE_DEFAULT && module < ISC_LOGMODULE_MAX);
isc_logchannellist_t *new_item = isc_mem_get(lctx->mctx,
sizeof(*new_item));
isc_result_t result;
REQUIRE(isc__lctx == NULL || VALID_CONTEXT(isc__lctx));
- REQUIRE(category >= 0 && category < ISC_LOGCATEGORY_MAX);
- REQUIRE(module >= 0 && module < ISC_LOGMODULE_MAX);
+ REQUIRE(category > ISC_LOGCATEGORY_DEFAULT &&
+ category < ISC_LOGCATEGORY_MAX);
+ REQUIRE(module > ISC_LOGMODULE_DEFAULT && module < ISC_LOGMODULE_MAX);
REQUIRE(level != ISC_LOG_DYNAMIC);
REQUIRE(format != NULL);
category_channels = &default_channel;
}
- if (category_channels->module != ISC_LOGMODULE_ALL &&
+ if (category_channels->module != ISC_LOGMODULE_DEFAULT &&
category_channels->module != module)
{
category_channels = ISC_LIST_NEXT(category_channels,
vsnprintf(msgbuf, sizeof(msgbuf), fmt, ap);
va_end(ap);
- isc_log_write(ISC_LOGCATEGORY_DEFAULT, ISC_LOGMODULE_NETMGR, level,
+ isc_log_write(ISC_LOGCATEGORY_GENERAL, ISC_LOGMODULE_NETMGR, level,
"netmgr %p: %s", netmgr, msgbuf);
}
vsnprintf(msgbuf, sizeof(msgbuf), fmt, ap);
va_end(ap);
- isc_log_write(ISC_LOGCATEGORY_DEFAULT, ISC_LOGMODULE_NETMGR, level,
+ isc_log_write(ISC_LOGCATEGORY_GENERAL, ISC_LOGMODULE_NETMGR, level,
"socket %p: %s", sock, msgbuf);
}
real_peer_fmt, real_local_fmt, proto);
if (cmd == ISC_PROXY2_CMD_LOCAL) {
- isc_log_write(ISC_LOGCATEGORY_DEFAULT, ISC_LOGMODULE_NETMGR,
+ isc_log_write(ISC_LOGCATEGORY_GENERAL, ISC_LOGMODULE_NETMGR,
log_level, "%s: command: LOCAL (%s)", common_msg,
real_addresses_msg);
return;
switch (socktype) {
case 0:
- isc_log_write(ISC_LOGCATEGORY_DEFAULT,
+ isc_log_write(ISC_LOGCATEGORY_GENERAL,
ISC_LOGMODULE_NETMGR, log_level,
"%s: command: PROXY (unspecified address "
"and socket type, %s)",
dst_addr_msg = dst_addr_fmt;
}
- isc_log_write(ISC_LOGCATEGORY_DEFAULT, ISC_LOGMODULE_NETMGR,
+ isc_log_write(ISC_LOGCATEGORY_GENERAL, ISC_LOGMODULE_NETMGR,
log_level,
"%s: command: PROXY, socket type: %s, source: "
"%s, destination: %s, TLVs: %s",
static void
init_logging(void) {
- isc_result_t result;
- isc_logdestination_t destination;
- isc_logconfig_t *logconfig = NULL;
-
- logconfig = isc_logconfig_get();
- destination.file.stream = stderr;
- destination.file.name = NULL;
- destination.file.versions = ISC_LOG_ROLLNEVER;
- destination.file.maximum_size = 0;
- isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC,
- ISC_LOG_DYNAMIC, &destination,
- ISC_LOG_PRINTPREFIX | ISC_LOG_PRINTTIME |
- ISC_LOG_ISO8601);
#if VERBOSE
isc_log_setdebuglevel(7);
#endif
-
- result = isc_log_usechannel(logconfig, "stderr",
- ISC_LOGCATEGORY_DEFAULT, ISC_LOGMODULE_ALL);
- INSIST(result == ISC_R_SUCCESS);
+ isc_logconfig_t *logconfig = isc_logconfig_get();
+ isc_log_createandusechannel(
+ logconfig, "default_stderr", ISC_LOG_TOFILEDESC,
+ ISC_LOG_DYNAMIC, ISC_LOGDESTINATION_STDERR,
+ ISC_LOG_PRINTPREFIX | ISC_LOG_PRINTTIME | ISC_LOG_ISO8601,
+ ISC_LOGCATEGORY_DEFAULT, ISC_LOGMODULE_DEFAULT);
}
static void
static void
setup_logging(void) {
- isc_result_t result;
- isc_logdestination_t destination;
- isc_logconfig_t *logconfig = NULL;
-
- logconfig = isc_logconfig_get();
- destination.file.stream = stderr;
- destination.file.name = NULL;
- destination.file.versions = ISC_LOG_ROLLNEVER;
- destination.file.maximum_size = 0;
- isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC,
- ISC_LOG_DYNAMIC, &destination,
- ISC_LOG_PRINTPREFIX | ISC_LOG_PRINTTIME |
- ISC_LOG_ISO8601);
-
#if VERBOSE
isc_log_setdebuglevel(7);
#endif
-
- result = isc_log_usechannel(logconfig, "stderr",
- ISC_LOGCATEGORY_DEFAULT, ISC_LOGMODULE_ALL);
- assert_int_equal(result, ISC_R_SUCCESS);
+ isc_logconfig_t *logconfig = isc_logconfig_get();
+ isc_log_createandusechannel(
+ logconfig, "default_stderr", ISC_LOG_TOFILEDESC,
+ ISC_LOG_DYNAMIC, ISC_LOGDESTINATION_STDERR,
+ ISC_LOG_PRINTPREFIX | ISC_LOG_PRINTTIME | ISC_LOG_ISO8601,
+ ISC_LOGCATEGORY_DEFAULT, ISC_LOGMODULE_DEFAULT);
}
static struct {
#include <tests/isc.h>
ISC_SETUP_TEST_IMPL(group) {
- isc_result_t result;
-
isc_logconfig_t *logconfig = isc_logconfig_get();
- isc_logdestination_t destination = {
- .file.stream = stderr,
- .file.versions = ISC_LOG_ROLLNEVER,
- };
- isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC,
- ISC_LOG_DYNAMIC, &destination, 0);
-
- result = isc_log_usechannel(logconfig, "stderr", ISC_LOGCATEGORY_ALL,
- ISC_LOGMODULE_ALL);
- if (result != ISC_R_SUCCESS) {
- return (-1);
- }
+ isc_log_createandusechannel(
+ logconfig, "default_stderr", ISC_LOG_TOFILEDESC,
+ ISC_LOG_DYNAMIC, ISC_LOGDESTINATION_STDERR, 0,
+ ISC_LOGCATEGORY_DEFAULT, ISC_LOGMODULE_DEFAULT);
return (0);
}
#include <tests/isc.h>
ISC_SETUP_TEST_IMPL(group) {
- isc_result_t result;
isc_logconfig_t *logconfig = isc_logconfig_get();
- isc_logdestination_t destination = {
- .file.stream = stderr,
- .file.versions = ISC_LOG_ROLLNEVER,
- };
- isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC,
- ISC_LOG_DYNAMIC, &destination, 0);
- result = isc_log_usechannel(logconfig, "stderr", ISC_LOGCATEGORY_ALL,
- ISC_LOGMODULE_ALL);
-
- if (result != ISC_R_SUCCESS) {
- return (-1);
- }
+ isc_log_createandusechannel(
+ logconfig, "default_stderr", ISC_LOG_TOFILEDESC,
+ ISC_LOG_DYNAMIC, ISC_LOGDESTINATION_STDERR, 0,
+ ISC_LOGCATEGORY_DEFAULT, ISC_LOGMODULE_DEFAULT);
return (0);
}