Add isc_log_createandusechannel() function to simplify usage
The new
isc_log_createandusechannel() function combines following calls:
isc_log_createchannel()
isc_log_usechannel()
calls into a single call that cannot fail and therefore can be used in
places where we know this cannot fail thus simplifying the error
handling.
This commit is contained in:
@@ -153,26 +153,15 @@ init_items(isc_mem_t *mctx) {
|
||||
|
||||
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
|
||||
|
||||
@@ -67,27 +67,15 @@
|
||||
|
||||
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 {
|
||||
|
||||
@@ -38,21 +38,11 @@
|
||||
#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);
|
||||
}
|
||||
|
||||
@@ -39,20 +39,11 @@
|
||||
#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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user