summaryrefslogtreecommitdiff
path: root/src/critical_log.c
diff options
context:
space:
mode:
authorSung-jae Park <nicesj.park@samsung.com>2013-02-14 05:17:28 +0000
committerSung-jae Park <nicesj.park@samsung.com>2013-02-14 05:17:28 +0000
commitf350fef4a102a3e0036f824e73bb3fa2cf542d81 (patch)
treef65567b30bf31f12eedc0dffcbe786380cd71895 /src/critical_log.c
parent7f262791e53ad0eb9f680265d3a3a20949b2cf68 (diff)
downloaddata-provider-master-f350fef4a102a3e0036f824e73bb3fa2cf542d81.tar.gz
data-provider-master-f350fef4a102a3e0036f824e73bb3fa2cf542d81.tar.bz2
data-provider-master-f350fef4a102a3e0036f824e73bb3fa2cf542d81.zip
Revise the code.
1. Update the liveinfo tool Add more functions. Make easy to use the tool 2. Time compensator is updated. 3. Code is revised by myself. Change-Id: Ib4b64da80727edb394a12e50398ed6f10e97b6e1
Diffstat (limited to 'src/critical_log.c')
-rw-r--r--src/critical_log.c54
1 files changed, 31 insertions, 23 deletions
diff --git a/src/critical_log.c b/src/critical_log.c
index 2af51a8..36e7ccf 100644
--- a/src/critical_log.c
+++ b/src/critical_log.c
@@ -46,6 +46,36 @@ static struct {
+static inline void rotate_log(void)
+{
+ char *filename;
+ int namelen;
+
+ if (s_info.nr_of_lines < MAX_LOG_LINE)
+ return;
+
+ s_info.file_id = (s_info.file_id + 1) % MAX_LOG_FILE;
+
+ namelen = strlen(s_info.filename) + strlen(SLAVE_LOG_PATH) + 20;
+ filename = malloc(namelen);
+ if (filename) {
+ snprintf(filename, namelen, "%s/%d_%s", SLAVE_LOG_PATH, s_info.file_id, s_info.filename);
+
+ if (s_info.fp)
+ fclose(s_info.fp);
+
+ s_info.fp = fopen(filename, "w+");
+ if (!s_info.fp)
+ ErrPrint("Failed to open a file: %s\n", filename);
+
+ DbgFree(filename);
+ }
+
+ s_info.nr_of_lines = 0;
+}
+
+
+
HAPI int critical_log(const char *func, int line, const char *fmt, ...)
{
va_list ap;
@@ -67,29 +97,7 @@ HAPI int critical_log(const char *func, int line, const char *fmt, ...)
va_end(ap);
s_info.nr_of_lines++;
- if (s_info.nr_of_lines == MAX_LOG_LINE) {
- char *filename;
- int namelen;
-
- s_info.file_id = (s_info.file_id + 1) % MAX_LOG_FILE;
-
- namelen = strlen(s_info.filename) + strlen(SLAVE_LOG_PATH) + 20;
- filename = malloc(namelen);
- if (filename) {
- snprintf(filename, namelen, "%s/%d_%s", SLAVE_LOG_PATH, s_info.file_id, s_info.filename);
-
- if (s_info.fp)
- fclose(s_info.fp);
-
- s_info.fp = fopen(filename, "w+");
- if (!s_info.fp)
- ErrPrint("Failed to open a file: %s\n", filename);
-
- DbgFree(filename);
- }
-
- s_info.nr_of_lines = 0;
- }
+ rotate_log();
return ret;
}