diff options
author | Jeonghoon Park <jh1979.park@samsung.com> | 2018-04-09 18:41:12 +0900 |
---|---|---|
committer | Jeonghoon Park <jh1979.park@samsung.com> | 2018-04-09 18:41:12 +0900 |
commit | 2c93d3c9f5d18ed706a280fa097ac57218d0bf49 (patch) | |
tree | 3242755b1df75845162078dc21029643ce40c6a1 | |
parent | 4de826d0a20d9d3f3f94c28c4e96b4fc8f305182 (diff) | |
download | ttsd-worker-package-2c93d3c9f5d18ed706a280fa097ac57218d0bf49.tar.gz ttsd-worker-package-2c93d3c9f5d18ed706a280fa097ac57218d0bf49.tar.bz2 ttsd-worker-package-2c93d3c9f5d18ed706a280fa097ac57218d0bf49.zip |
removes log.c
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | inc/log.h | 20 | ||||
-rw-r--r-- | src/log.c | 138 |
3 files changed, 5 insertions, 154 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 622c17f..8006b9c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,6 @@ SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie") INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/inc) SET(SRCS - src/log.c src/package-manager-worker.c src/downloader.c src/installer.c @@ -25,23 +25,23 @@ #define LOG_TAG "PKG_MANAGER_WORKER" #if !defined(_V) -#define _V(fmt, arg...) log_print(DLOG_VERBOSE, LOG_TAG, "[%s:%d] " fmt "\n", __func__, __LINE__, ##arg) +#define _V(fmt, arg...) dlog_print(DLOG_VERBOSE, LOG_TAG, "[%s:%d] " fmt "\n", __func__, __LINE__, ##arg) #endif #if !defined(_D) -#define _D(fmt, arg...) log_print(DLOG_DEBUG, LOG_TAG, "[%s:%d] " fmt "\n", __func__, __LINE__, ##arg) +#define _D(fmt, arg...) dlog_print(DLOG_DEBUG, LOG_TAG, "[%s:%d] " fmt "\n", __func__, __LINE__, ##arg) #endif #if !defined(_I) -#define _I(fmt, arg...) log_print(DLOG_INFO, LOG_TAG, "[%s:%d] " fmt "\n", __func__, __LINE__, ##arg) +#define _I(fmt, arg...) dlog_print(DLOG_INFO, LOG_TAG, "[%s:%d] " fmt "\n", __func__, __LINE__, ##arg) #endif #if !defined(_W) -#define _W(fmt, arg...) log_print(DLOG_WARN, LOG_TAG, "[%s:%d] " fmt "\n", __func__, __LINE__, ##arg) +#define _W(fmt, arg...) dlog_print(DLOG_WARN, LOG_TAG, "[%s:%d] " fmt "\n", __func__, __LINE__, ##arg) #endif #if !defined(_E) -#define _E(fmt, arg...) log_print(DLOG_ERROR, LOG_TAG, "[%s:%d] " fmt "\n", __func__, __LINE__, ##arg) +#define _E(fmt, arg...) dlog_print(DLOG_ERROR, LOG_TAG, "[%s:%d] " fmt "\n", __func__, __LINE__, ##arg) #endif #define retvm_if(expr, val, fmt, arg...) do { \ @@ -95,14 +95,4 @@ } \ } -typedef enum { - LOG_TYPE_DLOG = 0, - LOG_TYPE_FILE, - LOG_TYPE_ALL, -} log_type; - -int log_print(log_priority prio, const char *tag, const char *fmt, ...); -int log_type_set(log_type type); -void log_file_close(void); - #endif /* __PACKAGE_MANAGER_WORKER_LOG_H__*/ diff --git a/src/log.c b/src/log.c deleted file mode 100644 index 442d62d..0000000 --- a/src/log.c +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.1 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include <stdio.h> -#include <stdarg.h> -#include <stdlib.h> -#include <time.h> -#include <dlog.h> -#include "log.h" - -static FILE *log_fp = NULL; -static log_type ltype = LOG_TYPE_DLOG; - -static const char log_prio_name[][DLOG_PRIO_MAX-1] = { - "UNKNOWN", - "DEFAULT", /**< Default */ - "VERBOSE", /**< Verbose */ - "DEBUG", /**< Debug */ - "INFO", /**< Info */ - "WARN", /**< Warning */ - "ERROR", /**< Error */ - "FATAL", /**< Fatal */ - "SILENT" /**< Silent */ -}; - -static inline char* getFormattedTime(void) -{ - struct timespec time_s; - struct tm *ptm; - static char res_time[40] = {0, }; - - if (0 == clock_gettime(CLOCK_REALTIME, &time_s)) { - ptm = localtime((const time_t *)&time_s.tv_sec); - - // format : YY-MM-DD hh:mm:ss:uuuuuu - snprintf(res_time, sizeof(res_time), - "%04d-%02d-%02d %02d:%02d:%02d:%06ld" - , ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday - , ptm->tm_hour, ptm->tm_min, ptm->tm_sec - , time_s.tv_nsec); - } - - return res_time; -} - -static int __open_log_file(void) -{ - log_fp = fopen("/var/log/ttd.log", "a"); - /* TODO : splits log file, if log file size is exceeded specified max size */ - if (log_fp == NULL) { - dlog_print(DLOG_WARN, LOG_TAG, "%s\n", strerror(errno)); - dlog_print(DLOG_WARN, LOG_TAG, - "error to use log file, so use dlog as log system\n"); - ltype = LOG_TYPE_DLOG; - return -1; - } - - return 0; -} - -int log_type_set(log_type type) -{ - ltype = type; - dlog_print(DLOG_DEBUG, LOG_TAG, "setting log type : [%d]\n", type); - switch (type) { - case LOG_TYPE_FILE: - case LOG_TYPE_ALL: - __open_log_file(); - break; - case LOG_TYPE_DLOG: /* nothing to do */ - default: - ltype = LOG_TYPE_DLOG; - break; - } - return 0; -} - -void log_file_close(void) -{ - if (log_fp) { - fclose(log_fp); - log_fp = NULL; - dlog_print(DLOG_DEBUG, LOG_TAG, "close log file\n"); - } - - log_type_set(LOG_TYPE_DLOG); - - return; -} - -int log_print(log_priority prio, const char *tag, const char *fmt, ...) -{ - va_list ap; - - switch (ltype) { - case LOG_TYPE_FILE: - if (log_fp) { - va_start(ap, fmt); - fprintf(log_fp, "[%s] [%s]", getFormattedTime(), log_prio_name[prio]); - vfprintf(log_fp, fmt, ap); - va_end(ap); - fflush(log_fp); - } - break; - case LOG_TYPE_ALL: - va_start(ap, fmt); - if (log_fp) { - fprintf(log_fp, "[%s] [%s]", getFormattedTime(), log_prio_name[prio]); - vfprintf(log_fp, fmt, ap); - } - dlog_vprint(prio, tag, fmt, ap); - va_end(ap); - - if (log_fp) - fflush(log_fp); - break; - case LOG_TYPE_DLOG: - default: - va_start(ap, fmt); - dlog_vprint(prio, tag, fmt, ap); - va_end(ap); - break; - } - return 0; -} |