From 30576c592b538cab293cf6e1f6265d376cd5a12c Mon Sep 17 00:00:00 2001 From: Andreas Gustafsson Date: Thu, 13 Jul 2000 00:19:02 +0000 Subject: [PATCH] 330. [func] New function isc_log_wouldlog(). --- CHANGES | 2 ++ lib/isc/include/isc/log.h | 13 ++++++++++- lib/isc/log.c | 45 ++++++++++++++++++++++----------------- 3 files changed, 40 insertions(+), 20 deletions(-) diff --git a/CHANGES b/CHANGES index 0772b30444..c2421bde6c 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,5 @@ + 330. [func] New function isc_log_wouldlog(). + 329. [func] omapi_auth_register() now takes a size_t argument for the length of a key's secret data. Previously OMAPI only stored secrets up to the first NUL byte. diff --git a/lib/isc/include/isc/log.h b/lib/isc/include/isc/log.h index 091c763371..f80f735d59 100644 --- a/lib/isc/include/isc/log.h +++ b/lib/isc/include/isc/log.h @@ -15,7 +15,7 @@ * SOFTWARE. */ -/* $Id: log.h,v 1.25 2000/06/19 21:45:03 explorer Exp $ */ +/* $Id: log.h,v 1.26 2000/07/13 00:18:53 gson Exp $ */ #ifndef ISC_LOG_H #define ISC_LOG_H 1 @@ -627,6 +627,17 @@ isc_log_getdebuglevel(isc_log_t *lctx); * The current logging debugging level is returned. */ +isc_boolean_t +isc_log_wouldlog(isc_log_t *lctx, int level); +/* + * Determine whether logging something to 'lctx' at 'level' would + * actually cause something to be logged somewhere. + * + * If ISC_FALSE is returned, it is guaranteed that nothing would + * be logged, allowing the caller to omit unnecessary + * isc_log_write() calls and possible message preformatting. + */ + void isc_log_setduplicateinterval(isc_logconfig_t *lcfg, unsigned int interval); /* diff --git a/lib/isc/log.c b/lib/isc/log.c index 93df1fe816..e3c5d308bc 100644 --- a/lib/isc/log.c +++ b/lib/isc/log.c @@ -15,7 +15,7 @@ * SOFTWARE. */ -/* $Id: log.c,v 1.38 2000/06/23 17:52:20 tale Exp $ */ +/* $Id: log.c,v 1.39 2000/07/13 00:18:51 gson Exp $ */ /* Principal Authors: DCL */ @@ -1197,6 +1197,30 @@ isc_log_open(isc_logchannel_t *channel) { return (ISC_R_SUCCESS); } +isc_boolean_t +isc_log_wouldlog(isc_log_t *lctx, int level) { + /* + * Try to avoid locking the mutex for messages which can't + * possibly be logged to any channels -- primarily debugging + * messages that the debug level is not high enough to print. + * + * If the level is (mathematically) less than or equal to the + * highest_level, or if there is a dynamic channel and the level is + * less than or equal to the debug level, the main loop must be + * entered to see if the message should really be output. + * + * NOTE: this is UNLOCKED access to the logconfig. However, + * the worst thing that can happen is that a bad decision is made + * about returning without logging, and that's not a big concern, + * because that's a risk anyway if the logconfig is being + * dynamically changed. + */ + + return (ISC_TF(level <= lctx->logconfig->highest_level || + (lctx->logconfig->dynamic && + level <= lctx->debug_level))); +} + static void isc_log_doit(isc_log_t *lctx, isc_logcategory_t *category, isc_logmodule_t *module, int level, isc_boolean_t write_once, @@ -1232,24 +1256,7 @@ isc_log_doit(isc_log_t *lctx, isc_logcategory_t *category, REQUIRE(category->id < lctx->category_count); REQUIRE(module->id < lctx->module_count); - /* - * Try to avoid locking the mutex for messages which can't - * possibly be logged to any channels -- primarily debugging - * messages that the debug level is not high enough to print. - * - * If the level is (mathematically) less than or equal to the - * highest_level, or if there is a dynamic channel and the level is - * less than or equal to the debug level, the main loop must be - * entered to see if the message should really be output. - * - * NOTE: this is UNLOCKED access to the logconfig. However, - * the worst thing that can happen is that a bad decision is made - * about returning without logging, and that's not a big concern, - * because that's a risk anyway if the logconfig is being - * dynamically changed. - */ - if (! (level <= lctx->logconfig->highest_level || - (lctx->logconfig->dynamic && level <= lctx->debug_level))) + if (! isc_log_wouldlog(lctx, level)) return; time_string[0] = '\0';