]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Tidy up log output on server startup
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 15 Jun 2017 16:43:48 +0000 (12:43 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 15 Jun 2017 16:43:48 +0000 (12:43 -0400)
Mostly just use the correct macros in the correct places...

src/include/cf_util.h
src/main/cf_util.c
src/main/dl.c
src/main/files.c
src/main/modules.c
src/main/unlang_compile.c
src/main/virtual_servers.c

index 52b24c7341e6642011d52c1f40b30b33a90a8aa4..694c1be221a92a6d8c310e65b86e09eff8c2efc0 100644 (file)
@@ -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));
 
index 1307c96162122696547b1ae39d70603e690f5fc6..4a5fad2e478a405e6c51c4a14c195f7b2d2a0b31 100644 (file)
@@ -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.
index b99f2ceac177d163adce09687424b55916696b85..240eec8bd0c898add4c5b3ea7f474bd0fc1ed064 100644 (file)
@@ -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
index 63f7849e12cde65314a03ac0e2a0aba7de95f276..c75a9a1b8247941176e23287cc16e498fd9bf5a5 100644 (file)
@@ -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
index d88137d1799815f9a3667db8215828e51a09d640..3cd4da7987318008662c4a665cfdd230867888b4 100644 (file)
@@ -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.
         */
index 7944de240fc28d115c24cd9341d166c5012df942..c7c77398405ad3d2a1d031e8d123e58208e9f33d 100644 (file)
@@ -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, "<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);
                }
        }
 
@@ -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, "<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);
                }
        }
 
@@ -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;
        }
 
index 1ab814a4fe88cb68225c0f0cb5ee4179f46099ba..0ad00f62e57cbc30b6bb788062c79ed8dcb8a892 100644 (file)
@@ -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) {