Fix Macro issue
[framework/telephony/libtcore.git] / include / log.h
1 /*
2  * libtcore
3  *
4  * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Ja-young Gu <jygu@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20
21 #ifndef __TCORE_LOG_H__
22 #define __TCORE_LOG_H__
23
24 __BEGIN_DECLS
25
26 #ifdef FEATURE_DLOG_DEBUG
27
28 #include <dlog.h>
29
30 #ifndef TCORE_LOG_TAG
31 #define TCORE_LOG_TAG "UNKNOWN"
32 #endif
33
34 #define info(fmt,args...)  do { RLOG(LOG_INFO, TCORE_LOG_TAG, fmt "\n", ##args); } while(0)
35 #define msg(fmt,args...)  do { RLOG(LOG_DEBUG, TCORE_LOG_TAG, fmt "\n", ##args); } while(0)
36 #define dbg(fmt,args...)  do { RLOG(LOG_DEBUG, TCORE_LOG_TAG, "<%s:%d> " fmt "\n", __func__, __LINE__, ##args); } while(0)
37 #define warn(fmt,args...)  do { RLOG(LOG_WARN, TCORE_LOG_TAG, "<%s:%d> " fmt "\n", __func__, __LINE__, ##args); } while(0)
38 #define err(fmt,args...)  do { RLOG(LOG_FATAL, TCORE_LOG_TAG, "<%s:%d> " fmt "\n", __func__, __LINE__, ##args); } while(0)
39
40 #elif defined(FEATURE_TLOG_DEBUG)
41
42 #ifndef TCORE_LOG_TAG
43 #define TCORE_LOG_TAG "UNKNOWN"
44 #endif
45
46 enum tcore_log_type {
47         TCORE_LOG_TYPE_MAIN = 0,
48         TCORE_LOG_TYPE_RADIO,
49         TCORE_LOG_TYPE_SYSTEM
50 };
51
52 enum tcore_log_priority {
53         TCORE_LOG_UNKNOWN = 0,
54         TCORE_LOG_DEFAULT,
55         TCORE_LOG_VERBOSE,
56         TCORE_LOG_DEBUG,
57         TCORE_LOG_INFO,
58         TCORE_LOG_WARN,
59         TCORE_LOG_ERROR,
60         TCORE_LOG_FATAL,
61         TCORE_LOG_SILENT
62 };
63
64 /*
65  * Virtual log function.
66  * Daemon should implement the actual content. (printrf/file writing/...)
67  */
68 void tcore_log(enum tcore_log_type type, enum tcore_log_priority priority, const char *tag, const char *fmt, ...);
69
70 #define info(fmt,args...)  do { tcore_log(TCORE_LOG_TYPE_RADIO, TCORE_LOG_INFO, TCORE_LOG_TAG, fmt "\n", ##args); } while(0)
71 #define msg(fmt,args...)  do { tcore_log(TCORE_LOG_TYPE_RADIO, TCORE_LOG_DEBUG, TCORE_LOG_TAG, fmt "\n", ##args); } while(0)
72 #define dbg(fmt,args...)  do { tcore_log(TCORE_LOG_TYPE_RADIO, TCORE_LOG_DEBUG, TCORE_LOG_TAG, "<%s:%d> " fmt "\n", __func__, __LINE__, ##args); } while(0)
73 #define warn(fmt,args...)  do { tcore_log(TCORE_LOG_TYPE_RADIO, TCORE_LOG_WARN, TCORE_LOG_TAG, "<%s:%d> " fmt "\n", __func__, __LINE__, ##args); } while(0)
74 #define err(fmt,args...)  do { tcore_log(TCORE_LOG_TYPE_RADIO, TCORE_LOG_FATAL, TCORE_LOG_TAG, "<%s:%d> " fmt "\n", __func__, __LINE__, ##args); } while(0)
75
76 #else
77
78 #define ANSI_COLOR_NORMAL "\e[0m"
79
80 #define ANSI_COLOR_BLACK "\e[0;30m"
81 #define ANSI_COLOR_RED "\e[0;31m"
82 #define ANSI_COLOR_GREEN "\e[0;32m"
83 #define ANSI_COLOR_BROWN "\e[0;33m"
84 #define ANSI_COLOR_BLUE "\e[0;34m"
85 #define ANSI_COLOR_MAGENTA "\e[0;35m"
86 #define ANSI_COLOR_CYAN "\e[0;36m"
87 #define ANSI_COLOR_LIGHTGRAY "\e[0;37m"
88
89 #define ANSI_COLOR_DARKGRAY "\e[1;30m"
90 #define ANSI_COLOR_LIGHTRED "\e[1;31m"
91 #define ANSI_COLOR_LIGHTGREEN "\e[1;32m"
92 #define ANSI_COLOR_YELLOW "\e[1;33m"
93 #define ANSI_COLOR_LIGHTBLUE "\e[1;34m"
94 #define ANSI_COLOR_LIGHTMAGENTA "\e[1;35m"
95 #define ANSI_COLOR_LIGHTCYAN "\e[1;36m"
96 #define ANSI_COLOR_WHITE "\e[1;37m"
97
98 #ifndef TCORE_LOG_FILE
99 #define TCORE_LOG_FILE stdout
100 #endif
101
102 #ifndef TCORE_LOG_FUNC
103 #define TCORE_LOG_FUNC fprintf
104 #endif
105
106 #define info(fmt,args...)  do { TCORE_LOG_FUNC(TCORE_LOG_FILE, fmt "\n", ##args); fflush(TCORE_LOG_FILE); } while(0)
107 #define msg(fmt,args...)  do { TCORE_LOG_FUNC(TCORE_LOG_FILE, fmt "\n", ##args); fflush(TCORE_LOG_FILE); } while(0)
108 #define dbg(fmt,args...)  do { TCORE_LOG_FUNC(TCORE_LOG_FILE, ANSI_COLOR_LIGHTGRAY "<%s:%s> " ANSI_COLOR_NORMAL fmt "\n", __FILE__, __FUNCTION__, ##args); fflush(TCORE_LOG_FILE); } while(0)
109 #define warn(fmt,args...)  do { TCORE_LOG_FUNC(TCORE_LOG_FILE, ANSI_COLOR_YELLOW "<%s:%s> " ANSI_COLOR_NORMAL fmt "\n", __FILE__, __FUNCTION__, ##args); fflush(TCORE_LOG_FILE); } while(0)
110 #define err(fmt,args...)  do { TCORE_LOG_FUNC(TCORE_LOG_FILE, ANSI_COLOR_LIGHTRED "<%s:%s> " ANSI_COLOR_NORMAL fmt "\n", __FILE__, __FUNCTION__, ##args); fflush(TCORE_LOG_FILE); } while(0)
111
112 #endif
113
114 __END_DECLS
115
116 #endif