ISC_FORMAT_PRINTF(5, 0);
-/*%
- * Write a message to the log channels, pruning duplicates that occur within
- * a configurable amount of seconds (see isc_log_[sg]etduplicateinterval).
- * This function is otherwise identical to isc_log_write().
- */
-void
-isc_log_write1(isc_log_t *lctx, isc_logcategory_t *category,
- isc_logmodule_t *module, int level, const char *format, ...)
-
- ISC_FORMAT_PRINTF(5, 6);
-
-/*%
- * Write a message to the log channels, pruning duplicates that occur within
- * a configurable amount of seconds (see isc_log_[sg]etduplicateinterval).
- * This function is otherwise identical to isc_log_vwrite().
- */
-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_FORMAT_PRINTF(5, 0);
-
void
isc_log_setdebuglevel(isc_log_t *lctx, unsigned int level);
/*%<
* isc_log_write() calls and possible message preformatting.
*/
-void
-isc_log_setduplicateinterval(isc_logconfig_t *lcfg, unsigned int interval);
-/*%<
- * Set the interval over which duplicate log messages will be ignored
- * by isc_log_[v]write1(), in seconds.
- *
- * Notes:
- *\li Increasing the duplicate interval from X to Y will not necessarily
- * filter out duplicates of messages logged in Y - X seconds since the
- * increase. (Example: Message1 is logged at midnight. Message2
- * is logged at 00:01:00, when the interval is only 30 seconds, causing
- * Message1 to be expired from the log message history. Then the interval
- * is increased to 3000 (five minutes) and at 00:04:00 Message1 is logged
- * again. It will appear the second time even though less than five
- * passed since the first occurrence.
- *
- * Requires:
- *\li lctx is a valid logging context.
- */
-
-unsigned int
-isc_log_getduplicateinterval(isc_logconfig_t *lcfg);
-/*%<
- * Get the current duplicate filtering interval.
- *
- * Requires:
- *\li lctx is a valid logging context.
- *
- * Returns:
- *\li The current duplicate filtering interval.
- */
-
void
isc_log_settag(isc_logconfig_t *lcfg, const char *tag);
/*%<
ISC_LIST(isc_logchannel_t) channels;
ISC_LIST(isc_logchannellist_t) * channellists;
unsigned int channellist_count;
- unsigned int duplicate_interval;
int_fast32_t highest_level;
char *tag;
bool dynamic;
* to the buffer into which the message is formatted and to guard against
* competing threads trying to write to the same syslog resource.
*
- * FIXME: We can remove the locking by using per-thread .buffer and .messages.
+ * FIXME: We can remove the locking by using per-thread .buffer.
*/
struct isc_log {
/* Not locked. */
isc_mutex_t lock;
/* Locked by isc_log lock. */
char buffer[LOG_BUFFER_SIZE];
- ISC_LIST(isc_logmessage_t) messages;
atomic_bool dynamic;
atomic_int_fast32_t highest_level;
};
static void
isc_log_doit(isc_log_t *__lctx ISC_ATTR_UNUSED, isc_logcategory_t *category,
- isc_logmodule_t *module, int level, bool write_once,
- const char *format, va_list args) ISC_FORMAT_PRINTF(6, 0);
+ isc_logmodule_t *module, int level, const char *format,
+ va_list args) ISC_FORMAT_PRINTF(5, 0);
/*@{*/
/*!
}
lcfg->tag = NULL;
lcfg->highest_level = 0;
- lcfg->duplicate_interval = 0;
lcfg->magic = 0;
isc_mem_put(mctx, lcfg, sizeof(*lcfg));
*/
va_start(args, format);
- isc_log_doit(NULL, category, module, level, false, format, args);
+ isc_log_doit(NULL, category, module, level, format, args);
va_end(args);
}
/*
* Contract checking is done in isc_log_doit().
*/
- isc_log_doit(NULL, category, module, level, false, format, args);
-}
-
-void
-isc_log_write1(isc_log_t *__lctx ISC_ATTR_UNUSED, 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(NULL, category, module, level, true, format, args);
- va_end(args);
-}
-
-void
-isc_log_vwrite1(isc_log_t *__lctx ISC_ATTR_UNUSED, 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(NULL, category, module, level, true, format, args);
+ isc_log_doit(NULL, category, module, level, format, args);
}
void
return (atomic_load_acquire(&isc__lctx->debug_level));
}
-void
-isc_log_setduplicateinterval(isc_logconfig_t *lcfg, unsigned int interval) {
- REQUIRE(VALID_CONFIG(lcfg));
-
- lcfg->duplicate_interval = interval;
-}
-
-unsigned int
-isc_log_getduplicateinterval(isc_logconfig_t *lcfg) {
- REQUIRE(VALID_CONTEXT(lcfg));
-
- return (lcfg->duplicate_interval);
-}
-
void
isc_log_settag(isc_logconfig_t *lcfg, const char *tag) {
REQUIRE(VALID_CONFIG(lcfg));
static void
isc_log_doit(isc_log_t *__lctx ISC_ATTR_UNUSED, isc_logcategory_t *category,
- isc_logmodule_t *module, int level, bool write_once,
- const char *format, va_list args) {
+ isc_logmodule_t *module, int level, const char *format,
+ va_list args) {
int syslog_level;
const char *time_string;
char local_time[64];
(void)vsnprintf(isc__lctx->buffer,
sizeof(isc__lctx->buffer), format,
args);
-
- /*
- * Check for duplicates.
- */
- if (write_once) {
- isc_logmessage_t *message, *next;
- isc_time_t oldest;
- isc_interval_t interval;
- size_t size;
-
- isc_interval_set(&interval,
- lcfg->duplicate_interval, 0);
-
- /*
- * 'oldest' is the age of the oldest
- * messages which fall within the
- * duplicate_interval range.
- */
- oldest = isc_time_now();
- if (isc_time_subtract(&oldest, &interval,
- &oldest) != ISC_R_SUCCESS)
- {
- /*
- * Can't effectively do the
- * checking without having a
- * valid time.
- */
- message = NULL;
- } else {
- message = ISC_LIST_HEAD(
- isc__lctx->messages);
- }
-
- while (message != NULL) {
- if (isc_time_compare(&message->time,
- &oldest) < 0)
- {
- /*
- * This message is older
- * than the
- * duplicate_interval,
- * so it should be
- * dropped from the
- * history.
- *
- * Setting the interval
- * to be to be longer
- * will obviously not
- * cause the expired
- * message to spring
- * back into existence.
- */
- next = ISC_LIST_NEXT(message,
- link);
-
- ISC_LIST_UNLINK(
- isc__lctx->messages,
- message, link);
-
- isc_mem_put(
- isc__lctx->mctx,
- message,
- sizeof(*message) + 1 +
- strlen(message->text));
-
- message = next;
- continue;
- }
-
- /*
- * This message is in the
- * duplicate filtering interval
- * ...
- */
- if (strcmp(isc__lctx->buffer,
- message->text) == 0)
- {
- /*
- * ... and it is a
- * duplicate. Unlock the
- * mutex and get the
- * hell out of Dodge.
- */
- goto unlock;
- }
-
- message = ISC_LIST_NEXT(message, link);
- }
-
- /*
- * It wasn't in the duplicate interval,
- * so add it to the message list.
- */
- size = sizeof(isc_logmessage_t) +
- strlen(isc__lctx->buffer) + 1;
- message = isc_mem_get(isc__lctx->mctx, size);
- message->text = (char *)(message + 1);
- size -= sizeof(isc_logmessage_t);
- strlcpy(message->text, isc__lctx->buffer, size);
- message->time = isc_time_now();
- ISC_LINK_INIT(message, link);
- ISC_LIST_APPEND(isc__lctx->messages, message,
- link);
- }
}
utc = ((channel->flags & ISC_LOG_UTC) != 0);
forcelog = v;
}
-static void
-isc__log_free_messages(isc_mem_t *mctx, isc_log_t *lctx ISC_ATTR_UNUSED) {
- isc_logmessage_t *message = NULL, *next = NULL;
- ISC_LIST_FOREACH_SAFE (lctx->messages, message, link, next) {
- ISC_LIST_UNLINK(lctx->messages, message, link);
-
- isc_mem_put(mctx, message,
- sizeof(*message) + strlen(message->text) + 1);
- }
-}
-
void
isc__log_initialize(void) {
REQUIRE(isc__lctx == NULL);
isc__lctx = isc_mem_get(mctx, sizeof(*isc__lctx));
*isc__lctx = (isc_log_t){
- .magic = LCTX_MAGIC,
- .messages = ISC_LIST_INITIALIZER,
- .mctx = mctx, /* implicit attach */
+ .magic = LCTX_MAGIC, .mctx = mctx, /* implicit attach */
};
isc_mutex_init(&isc__lctx->lock);
isc_logconfig_destroy(&isc__lctx->logconfig);
}
- isc__log_free_messages(mctx, isc__lctx);
-
isc_mutex_destroy(&isc__lctx->lock);
isc_mem_putanddetach(&mctx, isc__lctx, sizeof(*isc__lctx));