Modified directory path by tizen platform config
[platform/core/connectivity/net-config.git] / src / utils / log.c
index ae8825f..2472082 100755 (executable)
  */
 
 #include <glib.h>
-#include <time.h>
+#include <sys/time.h>
 #include <stdio.h>
 #include <stdarg.h>
 #include <unistd.h>
 #include <sys/stat.h>
+#include <tzplatform_config.h>
 
 #include "log.h"
 
-#define LOG_FILE_PATH  "/opt/usr/data/network/netconfig.log"
+#define LOG_FILE_PATH  tzplatform_mkpath(TZ_USER_DATA, "/network/netconfig.log")
 #define MAX_LOG_SIZE   1 * 1024 * 1024
 #define MAX_LOG_COUNT  1
 
@@ -76,16 +77,17 @@ static inline void __netconfig_log_get_local_time(char *strtime, const int size)
 {
        time_t buf;
        struct tm *local_ptm;
+       struct tm result = {0, };
 
        time(&buf);
        buf = time(NULL);
-       local_ptm = localtime(&buf);
+       local_ptm = localtime_r(&buf, &result);
 
-       if(local_ptm)
+       if (local_ptm)
                strftime(strtime, size, "%m/%d %H:%M:%S", local_ptm);
 }
 
-void __netconfig_debug(const char *format, ...)
+void netconfig_log(const char *format, ...)
 {
        va_list ap;
        int log_size = 0;
@@ -125,3 +127,12 @@ void __netconfig_debug(const char *format, ...)
 
        va_end(ap);
 }
+
+void log_cleanup(void)
+{
+       if (log_file == NULL)
+               return;
+
+       fclose(log_file);
+       log_file = NULL;
+}