about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2022-06-28 20:13:55 +0200
committerMichael Vetter <jubalh@iodoru.org>2022-06-28 20:13:55 +0200
commit9312333ba2299b09a77cea28403ff9c2e5de45a0 (patch)
tree149ea2ef900daf2dbe102ba07a81dce472e50b0a
parent38ea55431d240c9ee6d3403e4f844f3a7ef7f1a5 (diff)
downloadprofani-tty-9312333ba2299b09a77cea28403ff9c2e5de45a0.tar.gz
log: put static functions on top
-rw-r--r--src/log.c107
1 files changed, 52 insertions, 55 deletions
diff --git a/src/log.c b/src/log.c
index d9fbcf71..b85f1005 100644
--- a/src/log.c
+++ b/src/log.c
@@ -70,8 +70,58 @@ enum {
     STDERR_RETRY_NR = 5,
 };
 
-static void _rotate_log_file(void);
-static char* _log_abbreviation_string_from_level(log_level_t level);
+static void
+_rotate_log_file(void)
+{
+    gchar* log_file = g_strdup(mainlogfile);
+    size_t len = strlen(log_file);
+    gchar* log_file_new = malloc(len + 5);
+
+    // the mainlog file should always end in '.log', lets remove this last part
+    // so that we can have profanity.001.log later
+    if (len > 4) {
+        log_file[len - 4] = '\0';
+    }
+
+    // find an empty name. from .log -> log.001 -> log.999
+    for (int i = 1; i < 1000; i++) {
+        g_sprintf(log_file_new, "%s.%03d.log", log_file, i);
+        if (!g_file_test(log_file_new, G_FILE_TEST_EXISTS))
+            break;
+    }
+
+    log_close();
+
+    if (len > 4) {
+        log_file[len - 4] = '.';
+    }
+
+    rename(log_file, log_file_new);
+
+    log_init(log_get_filter(), NULL);
+
+    free(log_file_new);
+    free(log_file);
+    log_info("Log has been rotated");
+}
+
+// abbreviation string is the prefix thats used in the log file
+static char*
+_log_abbreviation_string_from_level(log_level_t level)
+{
+    switch (level) {
+    case PROF_LEVEL_ERROR:
+        return "ERR";
+    case PROF_LEVEL_WARN:
+        return "WRN";
+    case PROF_LEVEL_INFO:
+        return "INF";
+    case PROF_LEVEL_DEBUG:
+        return "DBG";
+    default:
+        return "LOG";
+    }
+}
 
 void
 log_debug(const char* const msg, ...)
@@ -220,59 +270,6 @@ log_string_from_level(log_level_t level)
     }
 }
 
-static void
-_rotate_log_file(void)
-{
-    gchar* log_file = g_strdup(mainlogfile);
-    size_t len = strlen(log_file);
-    gchar* log_file_new = malloc(len + 5);
-
-    // the mainlog file should always end in '.log', lets remove this last part
-    // so that we can have profanity.001.log later
-    if (len > 4) {
-        log_file[len - 4] = '\0';
-    }
-
-    // find an empty name. from .log -> log.001 -> log.999
-    for (int i = 1; i < 1000; i++) {
-        g_sprintf(log_file_new, "%s.%03d.log", log_file, i);
-        if (!g_file_test(log_file_new, G_FILE_TEST_EXISTS))
-            break;
-    }
-
-    log_close();
-
-    if (len > 4) {
-        log_file[len - 4] = '.';
-    }
-
-    rename(log_file, log_file_new);
-
-    log_init(log_get_filter(), NULL);
-
-    free(log_file_new);
-    free(log_file);
-    log_info("Log has been rotated");
-}
-
-// abbreviation string is the prefix thats used in the log file
-static char*
-_log_abbreviation_string_from_level(log_level_t level)
-{
-    switch (level) {
-    case PROF_LEVEL_ERROR:
-        return "ERR";
-    case PROF_LEVEL_WARN:
-        return "WRN";
-    case PROF_LEVEL_INFO:
-        return "INF";
-    case PROF_LEVEL_DEBUG:
-        return "DBG";
-    default:
-        return "LOG";
-    }
-}
-
 void
 log_stderr_handler(void)
 {