4 * Copyright (c) 2011-2013 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
20 #include <sys/types.h>
27 #include "debug_util.h"
29 #define GPG_DUMP_LOG "/tmp/dump_gps.log"
33 struct tm * __get_current_time(struct tm *cur_time)
37 return localtime_r(&now, cur_time);
42 LOG_GPS(DBG_ERR, "gps_init_log");
45 char buf[256] = {0, };
46 fd = open(GPG_DUMP_LOG, O_RDWR | O_APPEND | O_CREAT, 0644);
48 LOG_GPS(DBG_ERR, "Fail to open file[%s]", GPG_DUMP_LOG);
52 if (!__get_current_time(&cur_time)) {
53 LOG_GPS(DBG_ERR, "Can't get current time[%s]", GPG_DUMP_LOG);
57 g_snprintf(buf, 256, "[%02d:%02d:%02d] -- START GPS -- \n", cur_time.tm_hour, cur_time.tm_min, cur_time.tm_sec);
58 ret = write(fd, buf, strlen(buf));
61 LOG_GPS(DBG_ERR, "Fail to write file[%s]", GPG_DUMP_LOG);
66 LOG_GPS(DBG_ERR, "gps_deinit_log");
70 char buf[256] = {0, };
72 if (!__get_current_time(&cur_time)) {
73 LOG_GPS(DBG_ERR, "Can't get current time[%s]", GPG_DUMP_LOG);
75 g_snprintf(buf, 256, "[%02d:%02d:%02d] -- END GPS -- \n", cur_time.tm_hour, cur_time.tm_min, cur_time.tm_sec);
76 ret = write(fd, buf, strlen(buf));
79 LOG_GPS(DBG_ERR, "Fail to write file[%s]", GPG_DUMP_LOG);
85 void gps_dump_log(const char *str, const char *app_id)
88 LOG_GPS(DBG_ERR, "Not available fd[%d]", fd);
92 char buf[256] = {0, };
95 if (!__get_current_time(&cur_time)) {
96 LOG_GPS(DBG_ERR, "Can't get current time[%s]", GPG_DUMP_LOG);
101 g_snprintf(buf, 256, "[%02d:%02d:%02d] %s\n", cur_time.tm_hour, cur_time.tm_min, cur_time.tm_sec, str);
103 g_snprintf(buf, 256, "[%02d:%02d:%02d] %s from [%s]\n", cur_time.tm_hour, cur_time.tm_min, cur_time.tm_sec, str, app_id);
105 LOG_GPS(DBG_ERR, "Add dump log [%s", buf);
106 ret = write(fd, buf, strlen(buf));
108 LOG_GPS(DBG_ERR, "Fail to write file[%s]", GPG_DUMP_LOG);