Skip to content
Extraits de code Groupes Projets
Vérifiée Valider f45dfb1e rédigé par Kubat's avatar Kubat
Parcourir les fichiers

LOG: Apply the 'log/level' (new value) instead of '/log' with the config

parent 91ecd8b7
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!170Ensure that option config values are present in the db
......@@ -26,24 +26,17 @@ skip(char *s)
return s;
}
static int
PRIVATE_FUNCTION int
handler(lkt_db *user, const char *section, const char *name, const char *value)
{
RETURN_UNLESS(section && name && value, "I can't complete the database with incomplete lines",
1);
RETURN_UNLESS(database_config_set(user, section, name, value), "Failed to update the database",
1);
RETURN_UNLESS(section && name && value, "Skip incomplete line", 1);
RETURN_UNLESS(database_config_set(user, section, name, value), "Failed to update config", 1);
return 0;
}
static inline void
__set_log_level(const char *name, const char *level)
PRIVATE_FUNCTION void
___set_log_level_internal(const char *level)
{
if (!STR_MATCH(name, "log")) {
LOG_WARN("CONFIG", "Invalid option '%s[:=]%s' with no section", name, level);
return;
}
if (!level[0]) {
LOG_WARN("CONFIG", "Invalid empty 'log' option");
return;
......@@ -63,7 +56,33 @@ __set_log_level(const char *name, const char *level)
LOG_INFO("CONFIG", "Log level set to %d", lkt_get_log_level());
}
static inline int
PRIVATE_FUNCTION void
___set_log_level(const char *name, const char *level)
{
/* Just check the key name here */
if (!STR_MATCH(name, "log")) {
LOG_WARN("CONFIG", "Invalid option '%s[:=]%s' with no section", name, level);
return;
}
___set_log_level_internal(level);
}
PRIVATE_FUNCTION void
___apply_log_level(lkt_db *db)
{
char loglevel[LKT_LINE_MAX];
if (!database_config_get_text_nospace(db, "log", "level", loglevel, LKT_LINE_MAX)) {
/* 'log/level' is not present, use the '/log' */
LOG_DEBUG("CONFIG", "No entry in config for 'log/level', set it to the '/log' entry");
safe_snprintf(loglevel, LKT_LINE_MAX, "%d", lkt_get_log_level());
database_config_set(db, "log", "level", loglevel);
} else {
/* 'log/level' is present, use that one */
___set_log_level_internal(loglevel);
}
}
PRIVATE_FUNCTION int
ini_parse(const char *path, lkt_db *db)
{
char *start, *end, *name, *value;
......@@ -132,8 +151,10 @@ ini_parse(const char *path, lkt_db *db)
LOG_ERROR("PARSER", "Failed to '[handle] %s, %s{:,=}%s' at line '%d'",
section, name, value, linenum);
}
} else
__set_log_level(name, value);
} else {
/* Keep for legacy reasons */
___set_log_level(name, value);
}
}
else {
......@@ -143,6 +164,8 @@ ini_parse(const char *path, lkt_db *db)
}
}
___apply_log_level(db);
/* End of the function */
fclose(file);
if (error)
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter