]> glassweightruler.freedombox.rocks Git - Ventoy.git/blobdiff - LinuxGUI/Ventoy2Disk/Core/ventoy_log.c
Support TrueNAS Scale (Linux) distro. (#3069 #3137)
[Ventoy.git] / LinuxGUI / Ventoy2Disk / Core / ventoy_log.c
index 469f843ebae0e29eee13d407922f835a3232b808..2df37c22c020fc63296101f3aa5f9c98b43d248e 100644 (file)
 #include <unistd.h>
 #include <pthread.h>
 #include <time.h>
+#include <linux/limits.h>
 #include <ventoy_define.h>
 
+extern char g_log_file[PATH_MAX];
 static int g_ventoy_log_level = VLOG_DEBUG;
 static pthread_mutex_t g_log_mutex;
 
@@ -68,7 +70,7 @@ void ventoy_syslog_newline(int level, const char *Fmt, ...)
     va_end(arg);
 
     pthread_mutex_lock(&g_log_mutex);
-    fp = fopen(VTOY_LOG_FILE, "a+");
+    fp = fopen(g_log_file, "a+");
     if (fp)
     {
         fprintf(fp, "[%04u/%02u/%02u %02u:%02u:%02u] %s\n", 
@@ -80,6 +82,34 @@ void ventoy_syslog_newline(int level, const char *Fmt, ...)
     pthread_mutex_unlock(&g_log_mutex);
 }
 
+void ventoy_syslog_printf(const char *Fmt, ...)
+{
+    char log[512];
+    va_list arg;
+    time_t stamp;
+    struct tm ttm;
+    FILE *fp;
+    
+    time(&stamp);
+    localtime_r(&stamp, &ttm);
+
+    va_start(arg, Fmt);
+    vsnprintf(log, 512, Fmt, arg);
+    va_end(arg);
+
+    pthread_mutex_lock(&g_log_mutex);
+    fp = fopen(g_log_file, "a+");
+    if (fp)
+    {
+        fprintf(fp, "[%04u/%02u/%02u %02u:%02u:%02u] %s", 
+           ttm.tm_year, ttm.tm_mon, ttm.tm_mday,
+           ttm.tm_hour, ttm.tm_min, ttm.tm_sec,
+           log);
+        fclose(fp);
+    }
+    pthread_mutex_unlock(&g_log_mutex);
+}
+
 void ventoy_syslog(int level, const char *Fmt, ...)
 {
     char log[512];
@@ -101,11 +131,11 @@ void ventoy_syslog(int level, const char *Fmt, ...)
     va_end(arg);
 
     pthread_mutex_lock(&g_log_mutex);
-    fp = fopen(VTOY_LOG_FILE, "a+");
+    fp = fopen(g_log_file, "a+");
     if (fp)
     {
         fprintf(fp, "[%04u/%02u/%02u %02u:%02u:%02u] %s", 
-           ttm.tm_year, ttm.tm_mon, ttm.tm_mday,
+           ttm.tm_year + 1900, ttm.tm_mon, ttm.tm_mday,
            ttm.tm_hour, ttm.tm_min, ttm.tm_sec,
            log);
         fclose(fp);