From adb0d00076c92242dcbb2a7a608c9e0a16ca0f02 Mon Sep 17 00:00:00 2001
From: Kubat <mael.martin31@gmail.com>
Date: Mon, 18 Jan 2021 15:01:12 +0100
Subject: [PATCH] MISC: Delete continuation logs, those where a really bad idea

---
 inc/lektor/common.h   |  9 --------
 src/base/common.c     | 53 +------------------------------------------
 src/base/config.c     |  4 ++--
 src/database/config.c |  2 +-
 src/module/mpv.c      | 40 ++++++++++++++++----------------
 5 files changed, 23 insertions(+), 85 deletions(-)

diff --git a/inc/lektor/common.h b/inc/lektor/common.h
index 80ebb14b..1816644d 100644
--- a/inc/lektor/common.h
+++ b/inc/lektor/common.h
@@ -81,19 +81,10 @@ enum log_level {
 };
 extern enum log_level __log_level;
 void __lkt_log(enum log_level, const char *section, const char *func, const char *format, ...);
-void __lkt_log_continuation(enum log_level, const char *format, ...);
-void __lkt_log_lock(enum log_level);
-void __lkt_log_unlock(enum log_level);
 #define LOG_INFO( section, ...) __lkt_log(INFO,  section, __func__, __VA_ARGS__)
 #define LOG_WARN( section, ...) __lkt_log(WARN,  section, __func__, __VA_ARGS__)
 #define LOG_ERROR(section, ...) __lkt_log(ERROR, section, __func__, __VA_ARGS__)
 #define LOG_DEBUG(section, ...) __lkt_log(DEBUG, section, __func__, __VA_ARGS__)
-#define LOG_INFO_CONT( ...)     __lkt_log_continuation(INFO, __VA_ARGS__)
-#define LOG_WARN_CONT( ...)     __lkt_log_continuation(INFO, __VA_ARGS__)
-#define LOG_ERROR_CONT(...)     __lkt_log_continuation(INFO, __VA_ARGS__)
-#define LOG_DEBUG_CONT(...)     __lkt_log_continuation(INFO, __VA_ARGS__)
-#define LOG_LOCK(level)         __lkt_log_lock(level)
-#define LOG_UNLOCK(level)       __lkt_log_unlock(level)
 
 #define SELF_EXECUTABLE_LINUX       "/proc/self/exe"
 #define SELF_EXECUTABLE_FREEBSD     "/proc/curproc/file"
diff --git a/src/base/common.c b/src/base/common.c
index 8f46555e..9a42b516 100644
--- a/src/base/common.c
+++ b/src/base/common.c
@@ -39,34 +39,7 @@ __set_assert(void)
 
 /* Log functions */
 
-enum log_level __log_level = __LAST_UNUSED_LOG_LEVEL;   /* All by default */
-static pthread_mutex_t __log_mutex;                     /* One thread can lock at the time */
-
-__attribute__((constructor)) static void
-___lkt_init_log_mutex(void)
-{
-    pthread_mutexattr_t attr;
-    pthread_mutexattr_init(&attr);
-    pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
-    pthread_mutex_init(&__log_mutex, &attr);
-    pthread_mutexattr_destroy(&attr);
-}
-
-void
-__lkt_log_lock(enum log_level level)
-{
-    if (level > __log_level)
-        return;
-    RETURN_IF(pthread_mutex_lock(&__log_mutex), "Failed to lock, not logging anything", NOTHING);
-}
-
-void
-__lkt_log_unlock(enum log_level level)
-{
-    if (level > __log_level)
-        return;
-    RETURN_IF(pthread_mutex_unlock(&__log_mutex), "Unlock failed, logging may be broken", NOTHING);
-}
+enum log_level __log_level = __LAST_UNUSED_LOG_LEVEL; /* All by default */
 
 void
 __lkt_log(enum log_level level, const char *section, const char *func, const char *format, ...)
@@ -89,8 +62,6 @@ __lkt_log(enum log_level level, const char *section, const char *func, const cha
     if (level > __log_level)
         return;
 
-    RETURN_IF(pthread_mutex_lock(&__log_mutex), "Failed to lock, not logging anything", NOTHING);
-
     safe_snprintf(line, LKT_MESSAGE_MAX, " %c [%02d:%02d:%02d] %-10s %s: %s\n",
                   level == ERROR ? '!' : level == WARN ? '*' : level == INFO ? '.' : ' ',
                   hour, min, sec,
@@ -99,28 +70,6 @@ __lkt_log(enum log_level level, const char *section, const char *func, const cha
     va_start(ap, format);
     vfprintf(stderr, line, ap);
     va_end(ap);
-
-    RETURN_IF(pthread_mutex_unlock(&__log_mutex), "Unlock failed, logging may be broken", NOTHING);
-}
-
-void
-__lkt_log_continuation(enum log_level level, const char *format, ...)
-{
-    char line[LKT_MESSAGE_MAX];
-    va_list ap;
-
-    if (level <= __log_level) {
-        RETURN_IF(pthread_mutex_lock(&__log_mutex), "Failed to lock, "
-                  "not logging anything", NOTHING);
-
-        safe_snprintf(line, LKT_MESSAGE_MAX, "                     ... %s\n", format);
-        va_start(ap, format);
-        vfprintf(stderr, line, ap);
-        va_end(ap);
-
-        RETURN_IF(pthread_mutex_unlock(&__log_mutex), "Failed to unlock, "
-                  "logging may be broken", NOTHING);
-    }
 }
 
 /* Not implemented */
diff --git a/src/base/config.c b/src/base/config.c
index 5a616553..274b4f1f 100644
--- a/src/base/config.c
+++ b/src/base/config.c
@@ -51,7 +51,7 @@ static inline void
 __set_log_level(const char *name, const char *level)
 {
     if (!STR_MATCH(name, "log")) {
-        LOG_WARN_CONT("Invalid option '%s[:=]%s' with no section", name, level);
+        LOG_WARN("CONFIG", "Invalid option '%s[:=]%s' with no section", name, level);
         return;
     }
 
@@ -71,7 +71,7 @@ __set_log_level(const char *name, const char *level)
     else
         __log_level = strtol(level, NULL, 0);
 
-    LOG_INFO_CONT("Log level set to %d", __log_level);
+    LOG_INFO("CONFIG", "Log level set to %d", __log_level);
 }
 
 static inline int
diff --git a/src/database/config.c b/src/database/config.c
index 00055e11..63b136b7 100644
--- a/src/database/config.c
+++ b/src/database/config.c
@@ -34,7 +34,7 @@ database_config_set(volatile sqlite3 *db, const char *section, const char *key,
         goto error;
     }
 
-    LOG_INFO_CONT("Set [%s.%s] to %s", section, key, value);
+    LOG_DEBUG("CONFIG", "Set [%s -> %s] to %s", section, key, value);
     ret = true;
 error:
     sqlite3_finalize(stmt);
diff --git a/src/module/mpv.c b/src/module/mpv.c
index 4d6da5ae..c86246bc 100644
--- a/src/module/mpv.c
+++ b/src/module/mpv.c
@@ -29,29 +29,27 @@ lmpv_prepare(volatile sqlite3 *db)
     RETURN_UNLESS(ctx, "Failed to create context", NULL);
     char _opt[LKT_LINE_MAX];
 
-#define MPV_SET_OPTION(opt, value)                                              \
-    if ((status = mpv_set_option_string(ctx, opt, value)) < 0) {                \
-        LOG_ERROR("WINDOW", "Failed to set %s to %s: %s",                       \
-                opt, value, mpv_error_string(status));                          \
-        return NULL;                                                            \
+#define MPV_SET_OPTION(opt, value)                                                          \
+    if ((status = mpv_set_option_string(ctx, opt, value)) < 0) {                            \
+        LOG_ERROR("WINDOW", "Failed to set %s to %s: %s",                                   \
+                opt, value, mpv_error_string(status));                                      \
+        return NULL;                                                                        \
     }
-#define MPV_SET_FROM_INI(opt, section, key)                                     \
-    if (!database_config_get_text(db, section, key, _opt, LKT_LINE_MAX)) {      \
-        LOG_WARN("WINDOW", "Failed to get option "                              \
-                        key " in section " section);                            \
-        return ctx;                                                             \
-    }                                                                           \
+#define MPV_SET_FROM_INI(opt, section, key)                                                 \
+    if (!database_config_get_text(db, section, key, _opt, LKT_LINE_MAX)) {                  \
+        LOG_WARN("WINDOW", "Failed to get option "                                          \
+                        key " in section " section);                                        \
+        return ctx;                                                                         \
+    }                                                                                       \
     MPV_SET_OPTION(opt, _opt);
-#define MPV_SET_OPTION_COND(opt, value, ini_section, ini_option, def) ({                                                                      \
-        int ___cond;                                                            \
-        if (!database_config_get_int(db, ini_section, ini_option, &___cond)) {  \
-            LOG_WARN("WINDOW", "Using default value '" #def "' because ["       \
-                     #ini_section "->" #ini_option "] was not present in ini "  \
-                    "config file");                                             \
-            ___cond = (def);                                                    \
-        }                                                                       \
-        if (___cond)                                                            \
-            MPV_SET_OPTION(opt, value);                                         \
+#define MPV_SET_OPTION_COND(opt, value, ini_section, ini_option, def) ({                                                                                      \
+        int ___cond;                                                                        \
+        if (!database_config_get_int(db, ini_section, ini_option, &___cond)) {              \
+            LOG_WARN("WINDOW", "Default [" #ini_section " -> " #ini_option "] to " #def);   \
+            ___cond = (def);                                                                \
+        }                                                                                   \
+        if (___cond)                                                                        \
+            MPV_SET_OPTION(opt, value);                                                     \
     })
 
     MPV_SET_OPTION("input-default-bindings", "yes");
-- 
GitLab