2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.tizenopensource.org/license
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
24 #include <sys/types.h>
33 #include "critical_log.h"
49 HAPI int critical_log(const char *func, int line, const char *fmt, ...)
58 if (gettimeofday(&tv, NULL) < 0) {
63 fprintf(s_info.fp, "%d %lu.%lu [%s:%d] ", getpid(), tv.tv_sec, tv.tv_usec, util_basename((char *)func), line);
66 ret = vfprintf(s_info.fp, fmt, ap);
70 if (s_info.nr_of_lines == MAX_LOG_LINE) {
74 s_info.file_id = (s_info.file_id + 1) % MAX_LOG_FILE;
76 namelen = strlen(s_info.filename) + strlen(SLAVE_LOG_PATH) + 20;
77 filename = malloc(namelen);
79 snprintf(filename, namelen, "%s/%d_%s", SLAVE_LOG_PATH, s_info.file_id, s_info.filename);
84 s_info.fp = fopen(filename, "w+");
86 ErrPrint("Failed to open a file: %s\n", filename);
91 s_info.nr_of_lines = 0;
98 HAPI int critical_log_init(const char *name)
106 s_info.filename = strdup(name);
107 if (!s_info.filename) {
108 ErrPrint("Failed to create a log file\n");
112 namelen = strlen(name) + strlen(SLAVE_LOG_PATH) + 20;
114 filename = malloc(namelen);
116 ErrPrint("Failed to create a log file\n");
117 DbgFree(s_info.filename);
118 s_info.filename = NULL;
122 snprintf(filename, namelen, "%s/%d_%s", SLAVE_LOG_PATH, s_info.file_id, name);
124 s_info.fp = fopen(filename, "w+");
126 ErrPrint("Failed to open log: %s\n", strerror(errno));
127 DbgFree(s_info.filename);
128 s_info.filename = NULL;
139 HAPI int critical_log_fini(void)
141 if (s_info.filename) {
142 DbgFree(s_info.filename);
143 s_info.filename = NULL;