diff --git a/CHANGELOG.md b/CHANGELOG.md index fda1ef9c7143e0ca8c81e6d5009af50ff171859c..cb242c002e31876ba30402a9d8ee874df6b95091 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ - Add: the regex used to populate the database from disk is now modifiable from the config file, the keys are `database/{types,categories,languages}`. Those fields must only contain alpha characters and commas - Add: re-use more informations from databases when upgrading the database because minimal version where added to the different fields in the table descriptions - Add: new field `repo_timestamp` which is the timestamp of the kara from the repo. This field is defaulted to the `cached_mtime` at upgrade time if needed +- Add: config flag to set verbose log level indications or not (less confusing messages...) - Fix: Correctly reading the `XDG_CONFIG_HOME` variable if present in the env... - Fix: fix incorrect parsing of lists of commands with multiple arguments: the parser could overrun the correct command buffer and insert a '\0' between the next command and its furst argument - Fix: fix issue #100 -> the `database_queue_add_id` won't add ids that doesn't exist diff --git a/inc/lektor/common.h b/inc/lektor/common.h index 5fa57233ad054de85ab00e64f41194877b89b401..57a21ea1d794cd2d9b7b1fdb7b8dee1a84375080 100644 --- a/inc/lektor/common.h +++ b/inc/lektor/common.h @@ -137,6 +137,7 @@ typedef enum { } LOG_LEVEL; struct lkt_logfile; +void lkt_set_log_level_verbose(bool); void lkt_set_log_level(LOG_LEVEL); void lkt_set_log_logfile(struct lkt_logfile *); LOG_LEVEL lkt_get_log_level(void); diff --git a/inc/lektor/internal/config.def b/inc/lektor/internal/config.def index 40a9e847407296a767f091fbd1986c0096cc95dd..aaab5da7d3ddebedf92af41f77e71552fc5bdbc0 100644 --- a/inc/lektor/internal/config.def +++ b/inc/lektor/internal/config.def @@ -18,10 +18,11 @@ comment("The 'log/level' will override the 'log' with no section") comment("The log files will be present in the 'log/folder', at most 'file_count'.") comment("Every file will be rotated when the current file has reached the maximum") comment("number of lines.") -value_opt("level", "INFO") -value_opt("folder", "/home/kara/logs") -value_opt("file_count", "10") -value_opt("line_count", "1000") +value_opt("level", "INFO") +value_opt("lvl_verbose", "1") +value_opt("folder", "/home/kara/logs") +value_opt("file_count", "10") +value_opt("line_count", "1000") /* SERVER */ section("server") diff --git a/src/base/common.c b/src/base/common.c index 3a89b3fc65e6af7262eeb91436dd09ad955d3ca6..d77da87e671cf36bc32f82547fb1c5e016755962 100644 --- a/src/base/common.c +++ b/src/base/common.c @@ -40,8 +40,15 @@ __set_assert(void) /* Log functions */ -static LOG_LEVEL ___log_level = ___LAST_UNUSED_LOG_LEVEL; /* All by default */ -extern struct lkt_logfile *___log_logfile; /* Use the logfile globaly */ +static bool ___log_level_verbose = false; /* Set whether the log level is verbose or contracted */ +static LOG_LEVEL ___log_level = ___LAST_UNUSED_LOG_LEVEL; /* All by default */ +extern struct lkt_logfile *___log_logfile; /* Use the logfile globaly */ + +void +lkt_set_log_level_verbose(bool flag) +{ + ___log_level_verbose = flag; +} void lkt_set_log_level(LOG_LEVEL lvl) @@ -90,12 +97,17 @@ ___lkt_log(LOG_LEVEL level, const char *section, const char *func, const char *f if (level > ___log_level) return; - char c_level = level == LOG_LEVEL_ERROR ? '!' - : level == LOG_LEVEL_WARN ? '*' - : level == LOG_LEVEL_INFO ? '.' - : ' '; + const char *const c_level = (level == LOG_LEVEL_ERROR) && ___log_level_verbose ? "ERROR" + : (level == LOG_LEVEL_WARN) && ___log_level_verbose ? "WARN " + : (level == LOG_LEVEL_INFO) && ___log_level_verbose ? "INFO " + : (level == LOG_LEVEL_DEBUG) && ___log_level_verbose ? "DEBUG" + : (level == LOG_LEVEL_ERROR) && (!___log_level_verbose) ? "!" + : (level == LOG_LEVEL_WARN) && (!___log_level_verbose) ? "*" + : (level == LOG_LEVEL_INFO) && (!___log_level_verbose) ? "." + : (level == LOG_LEVEL_DEBUG) && (!___log_level_verbose) ? " " + : " "; ssize_t count = - safe_snprintf(line, LKT_MESSAGE_MAX, " %c [%02d:%02d:%02d] %-10s %s(%s+%ld): %s\n", c_level, + safe_snprintf(line, LKT_MESSAGE_MAX, " %s [%02d:%02d:%02d] %-10s %s(%s+%ld): %s\n", c_level, hour, min, sec, section, func, file, line_number, format); /* Check for overflow */ if (count >= LKT_MESSAGE_MAX - 1) { diff --git a/src/main/lkt.c b/src/main/lkt.c index af5ef3f7112019ca51fa593629302f852ce81c96..ba8a273af34b6b128e7b48a1c44489577a9d057c 100644 --- a/src/main/lkt.c +++ b/src/main/lkt.c @@ -1384,6 +1384,7 @@ lkt_logfile_write(UNUSED struct lkt_logfile *logfile, UNUSED const char *line) int main(int argc, const char **argv) { + lkt_set_log_level_verbose(true); lkt_segv_quiet(); lkt_install_segv_handler(); lkt_set_log_level(LOG_LEVEL_INFO); diff --git a/src/main/server.c b/src/main/server.c index 7d9225c13d5cc3c2bae72abf645185dbcfefad8b..80ffc08320ffab66e37c98577699a22680cae8f1 100644 --- a/src/main/server.c +++ b/src/main/server.c @@ -55,6 +55,7 @@ main(int argc, char *argv[]) int autoclear; int opt; + int log_lvl_verbose; int check_exclusive = 1; int dump_and_abort = 0; char *conf_file = LKT_ALLOC_ARRAY(char, PATH_MAX); @@ -105,11 +106,14 @@ main(int argc, char *argv[]) lkt_set_log_logfile(logfile); /* Read the configuration. We already know that the config is valid */ + database_config_get_int(srv.db, "log", "lvl_verbose", &log_lvl_verbose); database_config_get_int(srv.db, "player", "autoclear", &autoclear); database_config_get_text(srv.db, "database", "kara_dir", kara_dir, PATH_MAX); database_config_get_text(srv.db, "server", "host", srv.host, HOST_NAME_MAX); database_config_get_text(srv.db, "server", "port", srv.port, 5); + lkt_set_log_level_verbose((bool)log_lvl_verbose); + /* Quick check with an explicit error message, to remide the users to * create the kara folder */ FAIL_IF(access(kara_dir, R_OK | W_OK), "No access in read / write for folder %s", kara_dir); diff --git a/src/module/module_repo.c b/src/module/module_repo.c index 7311547283edc063078f67c49f77015f497c25e7..c62f5ea4abb2197987d949d60dec18016e3e6e0a 100644 --- a/src/module/module_repo.c +++ b/src/module/module_repo.c @@ -10,9 +10,9 @@ #define REPO_UPDATE_KARA ((unsigned int)(1 << 1)) /* Downloading or rescanning the bakabase */ #define REPO_UPDATE_FAV ((unsigned int)(1 << 2)) /* Downloading the favorites */ #define REPO_UPDATE_ALL (REPO_UPDATE_FAV | REPO_UPDATE_KARA) /* Update all flag */ -#define REPO_TOKEN_MAX 128 -#define REPO_HEADER_AUTH_NAME "X-Token-Authorization: " -#define REPO_HEADER_AUTH_SIZE (sizeof(REPO_HEADER_AUTH_NAME) + REPO_TOKEN_MAX + 1) +#define REPO_TOKEN_MAX 128 +#define REPO_HEADER_AUTH_NAME "X-Token-Authorization: " +#define REPO_HEADER_AUTH_SIZE (sizeof(REPO_HEADER_AUTH_NAME) + REPO_TOKEN_MAX + 1) /*********** * Globals * @@ -321,7 +321,8 @@ retest: char author_token[REPO_HEADER_AUTH_SIZE]; memset(author_token, 0, REPO_HEADER_AUTH_SIZE); - snprintf(author_token, REPO_HEADER_AUTH_SIZE - 1, REPO_HEADER_AUTH_NAME"%s", repo->download_token); + snprintf(author_token, REPO_HEADER_AUTH_SIZE - 1, REPO_HEADER_AUTH_NAME "%s", + repo->download_token); headers = curl_slist_append(headers, "Accept: video/x-matroska"); headers = curl_slist_append(headers, "Content-Type: video/x-matroska"); @@ -425,10 +426,10 @@ ___update_repo_timestamp_if_needed_on_ignore_kara(struct kara *kara, uint64_t re PRIVATE_FUNCTION int ___handle_got_json_internal_callback(const char *key, const char *val, int comp, void *user) { - struct json_parse_arg *arg = (struct json_parse_arg *)user; - struct kara *kara = (struct kara *)arg->real_arg; - struct module_repo_internal *repo = (struct module_repo_internal*)arg->repo; - const struct lkt_uri *filter = (const struct lkt_uri *)kara->filter_uri; + struct json_parse_arg *arg = (struct json_parse_arg *)user; + struct kara *kara = (struct kara *)arg->real_arg; + struct module_repo_internal *repo = (struct module_repo_internal *)arg->repo; + const struct lkt_uri *filter = (const struct lkt_uri *)kara->filter_uri; /* Check if interrupt was asked */ WORKER_STATUS sta = worker_pool_get_status(arg->worker); @@ -1061,7 +1062,8 @@ module_repo_new(struct module_repo_internal *repo_, struct queue *queue, lkt_db exit(EXIT_FAILURE); } - static_assert((LKT_LINE_MAX >= REPO_HEADER_AUTH_SIZE), "REPO_HEADER_AUTH_SIZE can't be bigger than LKT_LINE_MAX"); + static_assert((LKT_LINE_MAX >= REPO_HEADER_AUTH_SIZE), + "REPO_HEADER_AUTH_SIZE can't be bigger than LKT_LINE_MAX"); /* Check token config separately, as it's empty by default, and the error should ask the user to add it to the config */ if (!database_config_get_text(db, "repo", "token", repo.download_token, REPO_TOKEN_MAX)) { LOG_ERROR("REPO", "No download token in repo configuration, please add it");