Commit 0e732748 authored by Daniel Salzman's avatar Daniel Salzman

log: add optional parameter to structured logging

parent ff015aa6
......@@ -208,7 +208,7 @@ void log_levels_add(log_target_t target, log_source_t src, int levels)
}
static void emit_log_msg(int level, log_source_t src, const char *zone,
size_t zone_len, const char *msg)
size_t zone_len, const char *msg, const char *param)
{
log_t *log = s_log;
......@@ -220,7 +220,7 @@ static void emit_log_msg(int level, log_source_t src, const char *zone,
sd_journal_send("PRIORITY=%d", level,
"MESSAGE=%s", msg,
zone_fmt, zone_len, zone,
NULL);
param, NULL);
} else
#endif
{
......@@ -290,7 +290,7 @@ static int log_msg_add(char **write, size_t *capacity, const char *fmt, ...)
}
static void log_msg_text(int level, log_source_t src, const char *zone,
const char *fmt, va_list args)
const char *fmt, va_list args, const char *param)
{
if (!log_isopen() || src == LOG_SOURCE_ANY) {
return;
......@@ -332,7 +332,7 @@ static void log_msg_text(int level, log_source_t src, const char *zone,
int ret = vsnprintf(write, capacity, fmt, args);
if (ret >= 0) {
// Send to logging targets.
emit_log_msg(level, src, zone, zone_len, buff);
emit_log_msg(level, src, zone, zone_len, buff, param);
}
rcu_read_unlock();
......@@ -342,12 +342,12 @@ void log_fmt(int priority, log_source_t src, const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
log_msg_text(priority, src, NULL, fmt, args);
log_msg_text(priority, src, NULL, fmt, args, NULL);
va_end(args);
}
void log_fmt_zone(int priority, log_source_t src, const knot_dname_t *zone,
const char *fmt, ...)
const char *param, const char *fmt, ...)
{
char buff[KNOT_DNAME_TXT_MAXLEN + 1];
char *zone_str = knot_dname_to_str(buff, zone, sizeof(buff));
......@@ -357,7 +357,7 @@ void log_fmt_zone(int priority, log_source_t src, const knot_dname_t *zone,
va_list args;
va_start(args, fmt);
log_msg_text(priority, src, zone_str, fmt, args);
log_msg_text(priority, src, zone_str, fmt, args, param);
va_end(args);
}
......@@ -370,7 +370,7 @@ void log_fmt_zone_str(int priority, log_source_t src, const char *zone,
va_list args;
va_start(args, fmt);
log_msg_text(priority, src, zone, fmt, args);
log_msg_text(priority, src, zone, fmt, args, NULL);
va_end(args);
}
......
......@@ -117,8 +117,9 @@ __attribute__((format(printf, 3, 4)));
* \param src Message source (LOG_SOURCE_SERVER...LOG_SOURCE_ZONE).
* \param fmt Content of the logged message.
*/
void log_fmt_zone(int priority, log_source_t src, const knot_dname_t *zone, const char *fmt, ...)
__attribute__((format(printf, 4, 5)));
void log_fmt_zone(int priority, log_source_t src, const knot_dname_t *zone,
const char *param, const char *fmt, ...)
__attribute__((format(printf, 5, 6)));
/*!
* \brief Log message into zone category.
......@@ -154,12 +155,12 @@ __attribute__((format(printf, 4, 5)));
#define log_ctl_zone_str_info(zone, msg, ...) log_fmt_zone_str(LOG_INFO, LOG_SOURCE_CONTROL, zone, msg, ##__VA_ARGS__)
#define log_ctl_zone_str_debug(zone, msg, ...) log_fmt_zone_str(LOG_DEBUG, LOG_SOURCE_CONTROL, zone, msg, ##__VA_ARGS__)
#define log_zone_fatal(zone, msg, ...) log_fmt_zone(LOG_CRIT, LOG_SOURCE_ZONE, zone, msg, ##__VA_ARGS__)
#define log_zone_error(zone, msg, ...) log_fmt_zone(LOG_ERR, LOG_SOURCE_ZONE, zone, msg, ##__VA_ARGS__)
#define log_zone_warning(zone, msg, ...) log_fmt_zone(LOG_WARNING, LOG_SOURCE_ZONE, zone, msg, ##__VA_ARGS__)
#define log_zone_notice(zone, msg, ...) log_fmt_zone(LOG_NOTICE, LOG_SOURCE_ZONE, zone, msg, ##__VA_ARGS__)
#define log_zone_info(zone, msg, ...) log_fmt_zone(LOG_INFO, LOG_SOURCE_ZONE, zone, msg, ##__VA_ARGS__)
#define log_zone_debug(zone, msg, ...) log_fmt_zone(LOG_DEBUG, LOG_SOURCE_ZONE, zone, msg, ##__VA_ARGS__)
#define log_zone_fatal(zone, msg, ...) log_fmt_zone(LOG_CRIT, LOG_SOURCE_ZONE, zone, NULL, msg, ##__VA_ARGS__)
#define log_zone_error(zone, msg, ...) log_fmt_zone(LOG_ERR, LOG_SOURCE_ZONE, zone, NULL, msg, ##__VA_ARGS__)
#define log_zone_warning(zone, msg, ...) log_fmt_zone(LOG_WARNING, LOG_SOURCE_ZONE, zone, NULL, msg, ##__VA_ARGS__)
#define log_zone_notice(zone, msg, ...) log_fmt_zone(LOG_NOTICE, LOG_SOURCE_ZONE, zone, NULL, msg, ##__VA_ARGS__)
#define log_zone_info(zone, msg, ...) log_fmt_zone(LOG_INFO, LOG_SOURCE_ZONE, zone, NULL, msg, ##__VA_ARGS__)
#define log_zone_debug(zone, msg, ...) log_fmt_zone(LOG_DEBUG, LOG_SOURCE_ZONE, zone, NULL, msg, ##__VA_ARGS__)
#define log_zone_str_fatal(zone, msg, ...) log_fmt_zone_str(LOG_CRIT, LOG_SOURCE_ZONE, zone, msg, ##__VA_ARGS__)
#define log_zone_str_error(zone, msg, ...) log_fmt_zone_str(LOG_ERR, LOG_SOURCE_ZONE, zone, msg, ##__VA_ARGS__)
......
......@@ -49,7 +49,7 @@
} while (0)
#define CONF_LOG_ZONE(severity, zone, msg, ...) do { \
log_fmt_zone(severity, LOG_SOURCE_ZONE, zone, "config, " msg, ##__VA_ARGS__); \
log_fmt_zone(severity, LOG_SOURCE_ZONE, zone, NULL, "config, " msg, ##__VA_ARGS__); \
} while (0)
/*! Configuration getter output. */
......
......@@ -84,7 +84,7 @@ static inline const char *log_direction_name(enum log_direction direction)
do { \
char address[SOCKADDR_STRLEN] = ""; \
sockaddr_tostr(address, sizeof(address), remote); \
log_fmt_zone(priority, LOG_SOURCE_ZONE, zone, "%s, %s, %s: " fmt, \
log_fmt_zone(priority, LOG_SOURCE_ZONE, zone, NULL, "%s, %s, %s: " fmt, \
log_operation_name(op), log_direction_name(dir), address, \
## __VA_ARGS__); \
} while (0)
......@@ -212,7 +212,7 @@ void knotd_mod_vlog(knotd_mod_t *mod, int priority, const char *fmt, va_list arg
if (mod->zone == NULL) {
log_fmt(priority, LOG_SOURCE_SERVER, LOG_ARGS(mod->id, msg));
} else {
log_fmt_zone(priority, LOG_SOURCE_ZONE, mod->zone,
log_fmt_zone(priority, LOG_SOURCE_ZONE, mod->zone, NULL,
LOG_ARGS(mod->id, msg));
}
......
......@@ -329,7 +329,7 @@ void err_handler_logger(sem_handler_t *handler, const zone_contents_t *zone,
}
log_fmt_zone(handler->fatal_error ? LOG_ERR : LOG_WARNING,
LOG_SOURCE_ZONE, zone->apex->owner,
LOG_SOURCE_ZONE, zone->apex->owner, NULL,
"check%s%s, %s%s%s",
(node != NULL ? ", node " : ""),
(node != NULL ? buff : ""),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment