#define cf_log_debug(_cf, _fmt, ...) _cf_log_debug(CF_TO_ITEM(_cf), _fmt, ## __VA_ARGS__)
void _cf_log_debug(CONF_ITEM const *ci, char const *fmt, ...) CC_HINT(format (printf, 2, 3));
+#define cf_log_debug_prefix(_cf, _fmt, ...) _cf_log_debug_prefix(CF_TO_ITEM(_cf), _fmt, ## __VA_ARGS__)
+void _cf_log_debug_prefix(CONF_ITEM const *ci, char const *fmt, ...) CC_HINT(format (printf, 2, 3));
+
void cf_log_err_by_name(CONF_SECTION const *parent,
char const *name, char const *fmt, ...) CC_HINT(format (printf, 3, 4));
talloc_free(msg);
}
+/** Log a debug message relating to a #CONF_ITEM
+ *
+ * Always emits a filename/lineno prefix is available
+ *
+ * @param[in] ci #CONF_ITEM to print file/lineno for.
+ * @param[in] fmt of the message.
+ * @param[in] ... Message args.
+ */
+void _cf_log_debug_prefix(CONF_ITEM const *ci, char const *fmt, ...)
+{
+ va_list ap;
+ char *msg;
+
+ if (rad_debug_lvl < 1) return;
+
+ va_start(ap, fmt);
+ msg = talloc_vasprintf(NULL, fmt, ap);
+ va_end(ap);
+
+ if (!ci || !ci->filename) {
+ DEBUG("%s", msg);
+ } else {
+ char const *e, *p;
+ int len;
+ truncate_filename(&e, &p, &len, ci->filename);
+ DEBUG("%s%.*s[%d]: %s", e, len, p, ci->lineno, msg);
+ }
+
+ talloc_free(msg);
+}
+
/** Log an error message in the context of a child pair of the specified parent
*
* @param[in] parent containing the pair.
*/
if (DEBUG_ENABLED3) {
if ((map->lhs->type == TMPL_TYPE_ATTR) && (map->lhs->name[0] != '&')) {
- WARN("%s[%d]: Please change attribute reference to '&%s %s ...'",
- cf_filename(cp), cf_lineno(cp),
- map->lhs->name, fr_int2str(fr_tokens_table, map->op, "<INVALID>"));
+ cf_log_warn(cp, "Please change attribute reference to '&%s %s ...'",
+ map->lhs->name, fr_int2str(fr_tokens_table, map->op, "<INVALID>"));
}
if ((map->rhs->type == TMPL_TYPE_ATTR) && (map->rhs->name[0] != '&')) {
- WARN("%s[%d]: Please change attribute reference to '... %s &%s'",
- cf_filename(cp), cf_lineno(cp),
- fr_int2str(fr_tokens_table, map->op, "<INVALID>"), map->rhs->name);
+ cf_log_warn(cp, "Please change attribute reference to '... %s &%s'",
+ fr_int2str(fr_tokens_table, map->op, "<INVALID>"), map->rhs->name);
}
}
*/
if (DEBUG_ENABLED3) {
if ((map->lhs->type == TMPL_TYPE_ATTR) && (map->lhs->name[0] != '&')) {
- WARN("%s[%d]: Please change attribute reference to '&%s %s ...'",
- cf_filename(cp), cf_lineno(cp),
- map->lhs->name, fr_int2str(fr_tokens_table, map->op, "<INVALID>"));
+ cf_log_warn(cp, "Please change attribute reference to '&%s %s ...'",
+ map->lhs->name, fr_int2str(fr_tokens_table, map->op, "<INVALID>"));
}
if ((map->rhs->type == TMPL_TYPE_ATTR) && (map->rhs->name[0] != '&')) {
- WARN("%s[%d]: Please change attribute reference to '... %s &%s'",
- cf_filename(cp), cf_lineno(cp),
- fr_int2str(fr_tokens_table, map->op, "<INVALID>"), map->rhs->name);
+ cf_log_warn(cp, "Please change attribute reference to '... %s &%s'",
+ fr_int2str(fr_tokens_table, map->op, "<INVALID>"), map->rhs->name);
}
}
*/
name = cf_pair_attr(cp);
if (name[0] == '-') {
- WARN("%s[%d]: Ignoring \"%s\" (see raddb/mods-available/README.rst)",
- cf_filename(cp), cf_lineno(cp), name + 1);
+ cf_log_warn(cp, "Ignoring \"%s\" "
+ "(see raddb/mods-available/README.rst)", name + 1);
continue;
}
rad_assert(cond != NULL);
if (cond->type == COND_TYPE_FALSE) {
- INFO(" # Skipping contents of '%s' as it is always 'false' -- %s:%d",
- unlang_ops[mod_type].name,
- cf_filename(cs), cf_lineno(cs));
+ cf_log_debug_prefix(cs, "Skipping contents of '%s' as it is always 'false'",
+ unlang_ops[mod_type].name);
return compile_empty(parent, unlang_ctx, cs, group_type, parentgroup_type, mod_type, COND_TYPE_FALSE);
}
}
if (f->cond->type == COND_TYPE_TRUE) {
- INFO(" # Skipping contents of '%s' as previous '%s' is always 'true' -- %s:%d",
- unlang_ops[mod_type].name,
- unlang_ops[f->self.type].name,
- cf_filename(cs), cf_lineno(cs));
+ cf_log_debug_prefix(cs, "Skipping contents of '%s' as previous '%s' is always 'true'",
+ unlang_ops[mod_type].name,
+ unlang_ops[f->self.type].name);
return 0;
}