Merge branch 'tizen_5.5' into tizen
[platform/core/uifw/capi-ui-sticker.git] / receiver / src / sticker_log.cpp
1 #include <dlog.h>
2 #include <stdio.h>
3 #include <string>
4 #include <sys/types.h>
5 #include <sys/stat.h>
6 #include <unistd.h>
7 #include <iostream>
8 #include <fstream>
9 #include <linux/limits.h>
10 #include <time.h>
11 #include <app_common.h>
12
13 #include "log.h"
14
15 using namespace std;
16
17 void sticker_save_log(const char *fmt, ...)
18 {
19     char buf[4000] = {0};
20     char time_buf[96] = {0};
21     char full_buf[4096] = {0};
22     char log_path[PATH_MAX];
23     char strLogFile[PATH_MAX];
24     va_list ap;
25
26     struct timespec ts;
27     clock_gettime(CLOCK_REALTIME, &ts);
28     const time_t tt = ts.tv_sec;
29     const long int real_millisec = ts.tv_nsec / 1000000;
30
31     struct tm *const ptm = localtime(&tt);
32     strftime(time_buf, sizeof(time_buf), "%m-%d %H:%M:%S", ptm);
33
34     va_start(ap, fmt);
35     vsnprintf(buf, sizeof (buf), fmt, ap);
36     va_end(ap);
37
38     snprintf(full_buf, sizeof(full_buf), "%s.%03ld %s", time_buf, real_millisec, buf);
39
40     char *data_path = NULL;
41     data_path = app_get_shared_data_path();
42     snprintf(log_path, sizeof(log_path), "%s/log", data_path);
43
44     if (data_path)
45         free(data_path);
46
47     snprintf(strLogFile, sizeof(strLogFile), "%s/sticker.log", log_path);
48
49     std::ofstream sticker_log_file (strLogFile, std::ios::app);
50     sticker_log_file << full_buf << std::endl;
51     sticker_log_file.flush ();
52 }