From: Arran Cudbard-Bell Date: Thu, 15 Jun 2017 16:43:48 +0000 (-0400) Subject: Tidy up log output on server startup X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f2c1915d3b1c4c686ef7dd39d1992c5d9e400cf5;p=thirdparty%2Ffreeradius-server.git Tidy up log output on server startup Mostly just use the correct macros in the correct places... --- diff --git a/src/include/cf_util.h b/src/include/cf_util.h index 52b24c7341e..694c1be221a 100644 --- a/src/include/cf_util.h +++ b/src/include/cf_util.h @@ -193,6 +193,9 @@ void _cf_log_info(CONF_ITEM const *ci, char const *fmt, ...) CC_HINT(format (pr #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)); diff --git a/src/main/cf_util.c b/src/main/cf_util.c index 1307c961621..4a5fad2e478 100644 --- a/src/main/cf_util.c +++ b/src/main/cf_util.c @@ -1680,6 +1680,37 @@ void _cf_log_debug(CONF_ITEM const *ci, char const *fmt, ...) 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. diff --git a/src/main/dl.c b/src/main/dl.c index b99f2ceac17..240eec8bd0c 100644 --- a/src/main/dl.c +++ b/src/main/dl.c @@ -752,7 +752,7 @@ dl_t const *dl_module(CONF_SECTION *conf, dl_t const *parent, char const *name, goto error; } - cf_log_debug(conf, "Loaded module \"%s\"", module_name); + cf_log_info(conf, "Loaded module \"%s\"", module_name); /* * Add the module to the dlhandle cache diff --git a/src/main/files.c b/src/main/files.c index 63f7849e12c..c75a9a1b824 100644 --- a/src/main/files.c +++ b/src/main/files.c @@ -97,7 +97,7 @@ int pairlist_read(TALLOC_CTX *ctx, char const *file, PAIR_LIST **list, int compl #endif char newfile[8192]; - DEBUG2(" reading file %s", file); + DEBUG2("Reading file %s", file); /* * Open the file. The error message should be a little diff --git a/src/main/modules.c b/src/main/modules.c index d88137d1799..3cd4da79873 100644 --- a/src/main/modules.c +++ b/src/main/modules.c @@ -659,8 +659,7 @@ static int _module_instantiate(void *instance, UNUSED void *ctx) * Call the instantiate method, if any. */ if (inst->module->instantiate) { - cf_log_debug(inst->cs, "Instantiating module \"%s\" from file %s", inst->name, - cf_filename(inst->cs)); + cf_log_debug(inst->cs, "Instantiating module \"%s\"", inst->name); /* * Call the module's instantiation routine. @@ -885,9 +884,6 @@ static module_instance_t *module_bootstrap(CONF_SECTION *modules, CONF_SECTION * return NULL; } - cf_log_debug(cs, "Loading module \"%s\" from file %s", instance->name, - cf_filename(cs)); - /* * Parse the modules configuration. */ diff --git a/src/main/unlang_compile.c b/src/main/unlang_compile.c index 7944de240fc..c7c77398405 100644 --- a/src/main/unlang_compile.c +++ b/src/main/unlang_compile.c @@ -1067,15 +1067,13 @@ static int modcall_fixup_map(vp_map_t *map, UNUSED void *ctx) */ 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, "")); + cf_log_warn(cp, "Please change attribute reference to '&%s %s ...'", + map->lhs->name, fr_int2str(fr_tokens_table, map->op, "")); } 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, ""), map->rhs->name); + cf_log_warn(cp, "Please change attribute reference to '... %s &%s'", + fr_int2str(fr_tokens_table, map->op, ""), map->rhs->name); } } @@ -1133,15 +1131,13 @@ int unlang_fixup_update(vp_map_t *map, UNUSED void *ctx) */ 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, "")); + cf_log_warn(cp, "Please change attribute reference to '&%s %s ...'", + map->lhs->name, fr_int2str(fr_tokens_table, map->op, "")); } 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, ""), map->rhs->name); + cf_log_warn(cp, "Please change attribute reference to '... %s &%s'", + fr_int2str(fr_tokens_table, map->op, ""), map->rhs->name); } } @@ -1807,8 +1803,8 @@ static unlang_t *compile_children(unlang_group_t *g, UNUSED unlang_t *parent, un */ 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; } @@ -2235,9 +2231,8 @@ static unlang_t *compile_if(unlang_t *parent, unlang_compile_t *unlang_ctx, CONF 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); } @@ -2279,10 +2274,9 @@ static int previous_if(CONF_SECTION *cs, unlang_t *parent, unlang_type_t mod_typ } 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; } diff --git a/src/main/virtual_servers.c b/src/main/virtual_servers.c index 1ab814a4fe8..0ad00f62e57 100644 --- a/src/main/virtual_servers.c +++ b/src/main/virtual_servers.c @@ -406,7 +406,7 @@ static int virtual_servers_compile(CONF_SECTION *cs) char const *name = cf_section_name2(cs); CONF_PAIR *cp; - cf_log_debug(cs, "server %s { # from file %s", name, cf_filename(cs)); + cf_log_debug(cs, "server %s {", name); cp = cf_pair_find(cs, "namespace"); if (cp) {