From b161f87be81548d1b6d0210a7e138a08fbb2d3e5 Mon Sep 17 00:00:00 2001 From: David Lawrence Date: Thu, 7 Dec 2000 19:30:28 +0000 Subject: [PATCH] Updated API to support i18n message arguments to isc_log_{,v}write{,1}. Provided isc_log_i{,v}write{,1}, with appropriate macro substitutions, for files that are not yet converted to the new API. When everything is converted, the added functions will be removed. --- lib/isc/include/isc/log.h | 56 ++++++++++++++++---- lib/isc/log.c | 105 +++++++++++++++++++++++++++++++++----- 2 files changed, 139 insertions(+), 22 deletions(-) diff --git a/lib/isc/include/isc/log.h b/lib/isc/include/isc/log.h index 355d29652e..227ddcfbd4 100644 --- a/lib/isc/include/isc/log.h +++ b/lib/isc/include/isc/log.h @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: log.h,v 1.31 2000/11/27 17:49:41 gson Exp $ */ +/* $Id: log.h,v 1.32 2000/12/07 19:30:28 tale Exp $ */ #ifndef ISC_LOG_H #define ISC_LOG_H 1 @@ -28,8 +28,6 @@ #include #include -ISC_LANG_BEGINDECLS - /* * Severity levels, patterned after Unix's syslog levels. * @@ -140,6 +138,8 @@ extern isc_logmodule_t isc_modules[]; #define ISC_LOGMODULE_SOCKET (&isc_modules[0]) +ISC_LANG_BEGINDECLS + isc_result_t isc_log_create(isc_mem_t *mctx, isc_log_t **lctxp, isc_logconfig_t **lcfgp); /* @@ -499,8 +499,18 @@ isc_log_usechannel(isc_logconfig_t *lcfg, const char *name, void isc_log_write(isc_log_t *lctx, isc_logcategory_t *category, - isc_logmodule_t *module, int level, const char *format, ...) + isc_logmodule_t *module, int level, + isc_msgcat_t *msgcat, int msgset, int message, + const char *format, ...) +ISC_FORMAT_PRINTF(8, 9); +void +isc_log_iwrite(isc_log_t *lctx, isc_logcategory_t *category, + isc_logmodule_t *module, int level, + const char *format, ...) ISC_FORMAT_PRINTF(5, 6); +#ifndef ISC_LOG_MSGCATARGS +#define isc_log_write isc_log_iwrite +#endif /* * Write a message to the log channels. * @@ -536,9 +546,18 @@ ISC_FORMAT_PRINTF(5, 6); void isc_log_vwrite(isc_log_t *lctx, isc_logcategory_t *category, - isc_logmodule_t *module, int level, const char *format, - va_list args) + isc_logmodule_t *module, int level, + isc_msgcat_t *msgcat, int msgset, int message, + const char *format, va_list args) +ISC_FORMAT_PRINTF(8, 0); +void +isc_log_ivwrite(isc_log_t *lctx, isc_logcategory_t *category, + isc_logmodule_t *module, int level, + const char *format, va_list args) ISC_FORMAT_PRINTF(5, 0); +#ifndef ISC_LOG_MSGCATARGS +#define isc_log_vwrite isc_log_ivwrite +#endif /* * Write a message to the log channels. * @@ -574,8 +593,18 @@ ISC_FORMAT_PRINTF(5, 0); void isc_log_write1(isc_log_t *lctx, isc_logcategory_t *category, - isc_logmodule_t *module, int level, const char *format, ...) + isc_logmodule_t *module, int level, + isc_msgcat_t *msgcat, int msgset, int message, + const char *format, ...) +ISC_FORMAT_PRINTF(8, 9); +void +isc_log_iwrite1(isc_log_t *lctx, isc_logcategory_t *category, + isc_logmodule_t *module, int level, + const char *format, ...) ISC_FORMAT_PRINTF(5, 6); +#ifndef ISC_LOG_MSGCATARGS +#define isc_log_write1 isc_log_iwrite1 +#endif /* * Write a message to the log channels, pruning duplicates that occur within * a configurable amount of seconds (see isc_log_[sg]etduplicateinterval). @@ -584,9 +613,18 @@ ISC_FORMAT_PRINTF(5, 6); void isc_log_vwrite1(isc_log_t *lctx, isc_logcategory_t *category, - isc_logmodule_t *module, int level, const char *format, - va_list args) + isc_logmodule_t *module, int level, + isc_msgcat_t *msgcat, int msgset, int message, + const char *format, va_list args) +ISC_FORMAT_PRINTF(8, 0); +void +isc_log_ivwrite1(isc_log_t *lctx, isc_logcategory_t *category, + isc_logmodule_t *module, int level, const char *format, + va_list args) ISC_FORMAT_PRINTF(5, 0); +#ifndef ISC_LOG_MSGCATARGS +#define isc_log_vwrite1 isc_log_ivwrite1 +#endif /* * Write a message to the log channels, pruning duplicates that occur within * a configurable amount of seconds (see isc_log_[sg]etduplicateinterval). diff --git a/lib/isc/log.c b/lib/isc/log.c index 9f66c3dab1..4ae6c1dbbf 100644 --- a/lib/isc/log.c +++ b/lib/isc/log.c @@ -15,10 +15,12 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: log.c,v 1.50 2000/12/06 00:30:01 tale Exp $ */ +/* $Id: log.c,v 1.51 2000/12/07 19:30:26 tale Exp $ */ /* Principal Authors: DCL */ +#define ISC_LOG_MSGCATARGS + #include #include @@ -226,6 +228,7 @@ roll_log(isc_logchannel_t *channel); static void isc_log_doit(isc_log_t *lctx, isc_logcategory_t *category, isc_logmodule_t *module, int level, isc_boolean_t write_once, + isc_msgcat_t *msgcat, int msgset, int msg, const char *format, va_list args); /* @@ -801,8 +804,9 @@ isc_log_usechannel(isc_logconfig_t *lcfg, const char *name, void isc_log_write(isc_log_t *lctx, isc_logcategory_t *category, - isc_logmodule_t *module, int level, const char *format, ...) - + isc_logmodule_t *module, int level, + isc_msgcat_t *msgcat, int msgset, int msg, + const char *format, ...) { va_list args; @@ -811,26 +815,29 @@ isc_log_write(isc_log_t *lctx, isc_logcategory_t *category, */ va_start(args, format); - isc_log_doit(lctx, category, module, level, ISC_FALSE, format, args); + isc_log_doit(lctx, category, module, level, ISC_FALSE, + msgcat, msgset, msg, format, args); va_end(args); } void isc_log_vwrite(isc_log_t *lctx, isc_logcategory_t *category, isc_logmodule_t *module, int level, + isc_msgcat_t *msgcat, int msgset, int msg, const char *format, va_list args) - { /* * Contract checking is done in isc_log_doit(). */ - isc_log_doit(lctx, category, module, level, ISC_FALSE, format, args); + isc_log_doit(lctx, category, module, level, ISC_FALSE, + msgcat, msgset, msg, format, args); } void isc_log_write1(isc_log_t *lctx, isc_logcategory_t *category, - isc_logmodule_t *module, int level, const char *format, ...) - + isc_logmodule_t *module, int level, + isc_msgcat_t *msgcat, int msgset, int msg, + const char *format, ...) { va_list args; @@ -839,20 +846,84 @@ isc_log_write1(isc_log_t *lctx, isc_logcategory_t *category, */ va_start(args, format); - isc_log_doit(lctx, category, module, level, ISC_TRUE, format, args); + isc_log_doit(lctx, category, module, level, ISC_TRUE, + msgcat, msgset, msg, format, args); va_end(args); } void isc_log_vwrite1(isc_log_t *lctx, isc_logcategory_t *category, isc_logmodule_t *module, int level, + isc_msgcat_t *msgcat, int msgset, int msg, const char *format, va_list args) - { /* * Contract checking is done in isc_log_doit(). */ - isc_log_doit(lctx, category, module, level, ISC_TRUE, format, args); + isc_log_doit(lctx, category, module, level, ISC_TRUE, + msgcat, msgset, msg, format, args); +} + +/* + * The isc_log_i*write*() functions are transitional functions which will + * be removed once all users of the old isc_log_*write* APIs have been + * converted to the new form (which added msgcat, msgset and msg parameters). + * They are used unless the calling module has ISC_LOG_MSGCATARGS defined. + */ +void +isc_log_iwrite(isc_log_t *lctx, isc_logcategory_t *category, + isc_logmodule_t *module, int level, const char *format, ...) +{ + va_list args; + + /* + * Contract checking is done in isc_log_doit(). + */ + + va_start(args, format); + isc_log_doit(lctx, category, module, level, ISC_FALSE, + NULL, 0, 0, format, args); + va_end(args); +} + +void +isc_log_ivwrite(isc_log_t *lctx, isc_logcategory_t *category, + isc_logmodule_t *module, int level, + const char *format, va_list args) +{ + /* + * Contract checking is done in isc_log_doit(). + */ + isc_log_doit(lctx, category, module, level, ISC_FALSE, + NULL, 0, 0, format, args); +} + +void +isc_log_iwrite1(isc_log_t *lctx, isc_logcategory_t *category, + isc_logmodule_t *module, int level, const char *format, ...) +{ + va_list args; + + /* + * Contract checking is done in isc_log_doit(). + */ + + va_start(args, format); + isc_log_doit(lctx, category, module, level, ISC_TRUE, + NULL, 0, 0, format, args); + va_end(args); +} + +void +isc_log_ivwrite1(isc_log_t *lctx, isc_logcategory_t *category, + isc_logmodule_t *module, int level, + const char *format, va_list args) +{ + /* + * Contract checking is done in isc_log_doit(). + */ + isc_log_doit(lctx, category, module, level, ISC_TRUE, + NULL, 0, 0, format, args); } void @@ -969,7 +1040,8 @@ assignchannel(isc_logconfig_t *lcfg, unsigned int category_id, new_item->channel = channel; new_item->module = module; - ISC_LIST_PREPENDUNSAFE(lcfg->channellists[category_id], new_item, link); + ISC_LIST_PREPENDUNSAFE(lcfg->channellists[category_id], + new_item, link); /* * Remember the highest logging level set by any channel in the @@ -1231,11 +1303,13 @@ isc_log_wouldlog(isc_log_t *lctx, int 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, + isc_msgcat_t *msgcat, int msgset, int msg, const char *format, va_list args) { int syslog_level; char time_string[64]; char level_string[24]; + const char *iformat; struct stat statbuf; isc_boolean_t matched = ISC_FALSE; isc_boolean_t printtime, printtag; @@ -1266,6 +1340,11 @@ isc_log_doit(isc_log_t *lctx, isc_logcategory_t *category, if (! isc_log_wouldlog(lctx, level)) return; + if (msgcat != NULL) + iformat = isc_msgcat_get(msgcat, msgset, msg, format); + else + iformat = format; + time_string[0] = '\0'; level_string[0] = '\0'; @@ -1394,7 +1473,7 @@ isc_log_doit(isc_log_t *lctx, isc_logcategory_t *category, */ if (lctx->buffer[0] == '\0') { (void)vsnprintf(lctx->buffer, sizeof(lctx->buffer), - format, args); + iformat, args); /* * Check for duplicates.