From: Sung-jae Park Date: Fri, 24 May 2013 09:28:08 +0000 (+0900) Subject: Update the log filename X-Git-Tag: submit/tizen_mobile/20150527.071719~2^2~48^2~21^2~180^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7e9db94d7c59211130504dc57cdcfe8f57331a98;p=platform%2Fcore%2Fappfw%2Fdata-provider-master.git Update the log filename [model] Redwood [binary_type] AP [customer] Docomo / Orange / Open [issue#] N/A [problem] Log file is overwritten by restarted process [cause] filename is not uniq [solution] Add the pid to the filename [team] Home [request] [horizontal_expansion] Change-Id: Ib9989252347bd41fc582858cd0079667535b84f7 --- diff --git a/src/critical_log.c b/src/critical_log.c index 3b6059c..7469013 100644 --- a/src/critical_log.c +++ b/src/critical_log.c @@ -57,10 +57,10 @@ static inline void rotate_log(void) s_info.file_id = (s_info.file_id + 1) % MAX_LOG_FILE; - namelen = strlen(s_info.filename) + strlen(SLAVE_LOG_PATH) + 20; + namelen = strlen(s_info.filename) + strlen(SLAVE_LOG_PATH) + 30; filename = malloc(namelen); if (filename) { - snprintf(filename, namelen, "%s/%d_%s", SLAVE_LOG_PATH, s_info.file_id, s_info.filename); + snprintf(filename, namelen, "%s/%d_%s.%d", SLAVE_LOG_PATH, s_info.file_id, s_info.filename, getpid()); if (s_info.fp) fclose(s_info.fp); @@ -81,18 +81,11 @@ HAPI int critical_log(const char *func, int line, const char *fmt, ...) { va_list ap; int ret; - struct timeval tv; if (!s_info.fp) return LB_STATUS_ERROR_IO; - if (gettimeofday(&tv, NULL) < 0) { - ErrPrint("gettimeofday: %s\n", strerror(errno)); - tv.tv_sec = 0; - tv.tv_usec = 0; - } - - fprintf(s_info.fp, "%d %lu.%lu [%s:%d] ", getpid(), tv.tv_sec, tv.tv_usec, util_basename((char *)func), line); + fprintf(s_info.fp, "%lf [%s:%d] ", util_timestamp(), util_basename((char *)func), line); va_start(ap, fmt); ret = vfprintf(s_info.fp, fmt, ap); @@ -121,7 +114,7 @@ HAPI int critical_log_init(const char *name) return LB_STATUS_ERROR_MEMORY; } - namelen = strlen(name) + strlen(SLAVE_LOG_PATH) + 20; + namelen = strlen(name) + strlen(SLAVE_LOG_PATH) + 30; filename = malloc(namelen); if (!filename) { @@ -131,7 +124,7 @@ HAPI int critical_log_init(const char *name) return LB_STATUS_ERROR_MEMORY; } - snprintf(filename, namelen, "%s/%d_%s", SLAVE_LOG_PATH, s_info.file_id, name); + snprintf(filename, namelen, "%s/%d_%s.%d", SLAVE_LOG_PATH, s_info.file_id, name, getpid()); s_info.fp = fopen(filename, "w+"); if (!s_info.fp) {