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

Can specify loglevel in config file

parent 3aaacce0
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!96Log levels
...@@ -55,7 +55,7 @@ enum log_level { ...@@ -55,7 +55,7 @@ enum log_level {
#define LOG(format, level, section, ...) \ #define LOG(format, level, section, ...) \
{ \ { \
if (level >= log_level) \ if (level <= log_level) \
fprintf(stderr, " %c %s%s: " format "\n", \ fprintf(stderr, " %c %s%s: " format "\n", \
level == ERROR ? '!' : level == WARN ? '*' : level == INFO ? '.' : ' ', \ level == ERROR ? '!' : level == WARN ? '*' : level == INFO ? '.' : ' ', \
sizeof(section) > sizeof("") ? ("[" section "] ") : "", \ sizeof(section) > sizeof("") ? ("[" section "] ") : "", \
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include <stdarg.h> #include <stdarg.h>
#include <sys/stat.h> #include <sys/stat.h>
int log_level = INFO; int log_level = 0; /* None by default */
void void
__not_implemented(const char *func, char *file, int line) __not_implemented(const char *func, char *file, int line)
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <lektor/net.h> #include <lektor/net.h>
#include <lektor/reg.h> #include <lektor/reg.h>
#include <strings.h>
#include <stdlib.h> #include <stdlib.h>
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
...@@ -46,6 +47,34 @@ handler(volatile sqlite3 *user, const char *section, const char *name, ...@@ -46,6 +47,34 @@ handler(volatile sqlite3 *user, const char *section, const char *name,
return 0; return 0;
} }
static inline void
__set_log_level(const char *name, 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", "%s", "Invalid empty 'log' option");
return;
}
if (STR_MATCH(level, "error"))
log_level = ERROR;
else if (STR_MATCH(level, "warn") || STR_MATCH(level, "warning"))
log_level = WARN;
else if (STR_MATCH(level, "info"))
log_level = INFO;
else if (STR_MATCH(level, "debug"))
log_level = DEBUG;
else
log_level = strtol(level, NULL, 0);
LOG_INFO("CONFIG", "Log level set to %d", log_level);
}
static inline int static inline int
ini_parse(const char *path, volatile sqlite3 *db) ini_parse(const char *path, volatile sqlite3 *db)
{ {
...@@ -58,6 +87,9 @@ ini_parse(const char *path, volatile sqlite3 *db) ...@@ -58,6 +87,9 @@ ini_parse(const char *path, volatile sqlite3 *db)
return 1; return 1;
} }
memset(section, 0, INI_MAX_SECTION_LEN);
memset(line, 0, INI_MAX_LINE_LEN);
/* Parse the file */ /* Parse the file */
while (NULL != fgets(line, INI_MAX_LINE_LEN, file)) { while (NULL != fgets(line, INI_MAX_LINE_LEN, file)) {
++linenum; ++linenum;
...@@ -102,13 +134,18 @@ ini_parse(const char *path, volatile sqlite3 *db) ...@@ -102,13 +134,18 @@ ini_parse(const char *path, volatile sqlite3 *db)
value = skip(value); value = skip(value);
strip(value); strip(value);
/* Handle the SECTION, NAME[:=]VALUE */ /* Handle the SECTION, NAME[:=]VALUE
if (handler(db, section, name, value)) { The only option that has no SECTION is the log level:
error = 1; log[:=]ERROR|WARN|INFO|DEBUG|\d+ */
LOG_ERROR("PARSER", "Failed to '[handle] %s, " if (section[0]) {
"%s{:,=}%s' at line '%d'", if (handler(db, section, name, value)) {
section, name, value, linenum); error = 1;
} LOG_ERROR("PARSER", "Failed to '[handle] %s, "
"%s{:,=}%s' at line '%d'",
section, name, value, linenum);
}
} else
__set_log_level(name, value);
} }
else { else {
......
...@@ -941,6 +941,7 @@ parse_args(args_t *args, int argc, const char **argv) ...@@ -941,6 +941,7 @@ parse_args(args_t *args, int argc, const char **argv)
int int
main(int argc, const char **argv) main(int argc, const char **argv)
{ {
log_level = ERROR;
executable_name = "lkt"; executable_name = "lkt";
assert(NULL != setlocale(LC_ALL, "en_US.UTF-8")); /* BECAUSE! */ assert(NULL != setlocale(LC_ALL, "en_US.UTF-8")); /* BECAUSE! */
assert(!signal(SIGPIPE, sigpipe__)); assert(!signal(SIGPIPE, sigpipe__));
......
...@@ -66,10 +66,6 @@ main(int argc, char *argv[]) ...@@ -66,10 +66,6 @@ main(int argc, char *argv[])
} }
normal_launch: normal_launch:
LOG_INFO("GENERAL", "Lektor launched by user %s (shell: %s, home: %s)",
pw->pw_name, pw->pw_shell, pw->pw_dir);
if (env_get(LKT_ENV_RESTART))
LOG_INFO("GENERAL", "%s", "Lektord has been restarted");
reg_set(server_reg); reg_set(server_reg);
mthread_init(); mthread_init();
pthread_create(&th, NULL, mthread_main, NULL); pthread_create(&th, NULL, mthread_main, NULL);
...@@ -136,6 +132,10 @@ normal_launch: ...@@ -136,6 +132,10 @@ normal_launch:
lkt_queue_send(&srv.queue, lkt_event_play_pos, (void *) (size_t) strtol(env_current, NULL, 0)); lkt_queue_send(&srv.queue, lkt_event_play_pos, (void *) (size_t) strtol(env_current, NULL, 0));
} }
LOG_INFO("GENERAL", "Lektor was %s, user: %s, shell: %s, home: %s",
env_get(LKT_ENV_RESTART) ? "restarted" : "started",
pw->pw_name, pw->pw_shell, pw->pw_dir);
lkt_listen(&srv); lkt_listen(&srv);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter