tizen 2.3.1 release
[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 #include <glib.h>
27 extern gboolean tcore_debug;
28
29 #ifdef FEATURE_DLOG_DEBUG
30
31 #include <dlog.h>
32
33 #ifndef TCORE_LOG_TAG
34 #define TCORE_LOG_TAG "UNKNOWN"
35 #endif
36
37 #define info(fmt,args...)  { if(tcore_debug) RLOG(LOG_INFO, TCORE_LOG_TAG, fmt "\n", ##args); }
38 #define msg(fmt,args...)  { if(tcore_debug) RLOG(LOG_DEBUG, TCORE_LOG_TAG, fmt "\n", ##args); }
39 #define dbg(fmt,args...)  { if(tcore_debug) RLOG(LOG_DEBUG, TCORE_LOG_TAG, fmt "\n", ##args); }
40 #define warn(fmt,args...)  { RLOG(LOG_WARN, TCORE_LOG_TAG, fmt "\n", ##args); }
41 #define err(fmt,args...)  { RLOG(LOG_ERROR, TCORE_LOG_TAG, fmt "\n", ##args); }
42 #define fatal(fmt,args...)  { RLOG(LOG_FATAL, TCORE_LOG_TAG, fmt "\n", ##args); }
43
44 #elif defined(FEATURE_TLOG_DEBUG)
45
46 #ifndef TCORE_LOG_TAG
47 #define TCORE_LOG_TAG "UNKNOWN"
48 #endif
49
50 enum tcore_log_type {
51         TCORE_LOG_TYPE_MAIN = 0,
52         TCORE_LOG_TYPE_RADIO,
53         TCORE_LOG_TYPE_SYSTEM,
54         TCORE_LOG_TYPE_TIME_CHECK
55 };
56
57 enum tcore_log_priority {
58         TCORE_LOG_UNKNOWN = 0,
59         TCORE_LOG_DEFAULT,
60         TCORE_LOG_VERBOSE,
61         TCORE_LOG_DEBUG,
62         TCORE_LOG_INFO,
63         TCORE_LOG_WARN,
64         TCORE_LOG_ERROR,
65         TCORE_LOG_FATAL,
66         TCORE_LOG_SILENT
67 };
68
69 /*
70  * Virtual log function.
71  * Daemon should implement the actual content. (printrf/file writing/...)
72  */
73 void tcore_log(enum tcore_log_type type, enum tcore_log_priority priority, const char *tag, const char *fmt, ...);
74
75 #define info(fmt,args...)  { if(tcore_debug) tcore_log(TCORE_LOG_TYPE_RADIO, TCORE_LOG_INFO, TCORE_LOG_TAG, fmt "\n", ##args); }
76 #define msg(fmt,args...)  { if(tcore_debug) tcore_log(TCORE_LOG_TYPE_RADIO, TCORE_LOG_DEBUG, TCORE_LOG_TAG, fmt "\n", ##args); }
77 #define dbg(fmt,args...)  { if(tcore_debug) tcore_log(TCORE_LOG_TYPE_RADIO, TCORE_LOG_DEBUG, TCORE_LOG_TAG, "<%s:%d> " fmt "\n", __func__, __LINE__, ##args); }
78 #define warn(fmt,args...)  { tcore_log(TCORE_LOG_TYPE_RADIO, TCORE_LOG_WARN, TCORE_LOG_TAG, "<%s:%d> " fmt "\n", __func__, __LINE__, ##args); }
79 #define err(fmt,args...)  { tcore_log(TCORE_LOG_TYPE_RADIO, TCORE_LOG_ERROR, TCORE_LOG_TAG, "<%s:%d> " fmt "\n", __func__, __LINE__, ##args); }
80 #define fatal(fmt,args...)  { tcore_log(TCORE_LOG_TYPE_RADIO, TCORE_LOG_FATAL, TCORE_LOG_TAG, "<%s:%d> " fmt "\n", __func__, __LINE__, ##args); }
81
82 #define info_ex(tag,fmt,args...)  { if(tcore_debug) tcore_log(TCORE_LOG_TYPE_RADIO, TCORE_LOG_INFO, tag, fmt "\n", ##args); }
83 #define msg_ex(tag,fmt,args...)  { if(tcore_debug) tcore_log(TCORE_LOG_TYPE_RADIO, TCORE_LOG_DEBUG, tag, fmt "\n", ##args); }
84 #define dbg_ex(tag,fmt,args...)  { if(tcore_debug) tcore_log(TCORE_LOG_TYPE_RADIO, TCORE_LOG_DEBUG, tag, "<%s:%d> " fmt "\n", __func__, __LINE__, ##args); }
85 #define warn_ex(tag,fmt,args...)  { tcore_log(TCORE_LOG_TYPE_RADIO, TCORE_LOG_WARN, tag, "<%s:%d> " fmt "\n", __func__, __LINE__, ##args); }
86 #define err_ex(tag,fmt,args...)  { tcore_log(TCORE_LOG_TYPE_RADIO, TCORE_LOG_ERROR, tag, "<%s:%d> " fmt "\n", __func__, __LINE__, ##args); }
87 #define fatal_ex(tag,fmt,args...)  { tcore_log(TCORE_LOG_TYPE_RADIO, TCORE_LOG_FATAL, tag, "<%s:%d> " fmt "\n", __func__, __LINE__, ##args); }
88
89 #define TIME_CHECK(fmt,args...) { tcore_log(TCORE_LOG_TYPE_TIME_CHECK, TCORE_LOG_INFO, "TIME_CHECK", fmt "\n", ##args); }
90
91 #else
92
93 #define ANSI_COLOR_NORMAL "\e[0m"
94
95 #define ANSI_COLOR_BLACK "\e[0;30m"
96 #define ANSI_COLOR_RED "\e[0;31m"
97 #define ANSI_COLOR_GREEN "\e[0;32m"
98 #define ANSI_COLOR_BROWN "\e[0;33m"
99 #define ANSI_COLOR_BLUE "\e[0;34m"
100 #define ANSI_COLOR_MAGENTA "\e[0;35m"
101 #define ANSI_COLOR_CYAN "\e[0;36m"
102 #define ANSI_COLOR_LIGHTGRAY "\e[0;37m"
103
104 #define ANSI_COLOR_DARKGRAY "\e[1;30m"
105 #define ANSI_COLOR_LIGHTRED "\e[1;31m"
106 #define ANSI_COLOR_LIGHTGREEN "\e[1;32m"
107 #define ANSI_COLOR_YELLOW "\e[1;33m"
108 #define ANSI_COLOR_LIGHTBLUE "\e[1;34m"
109 #define ANSI_COLOR_LIGHTMAGENTA "\e[1;35m"
110 #define ANSI_COLOR_LIGHTCYAN "\e[1;36m"
111 #define ANSI_COLOR_WHITE "\e[1;37m"
112
113 #ifndef TCORE_LOG_FILE
114 #define TCORE_LOG_FILE stdout
115 #endif
116
117 #ifndef TCORE_LOG_FUNC
118 #define TCORE_LOG_FUNC fprintf
119 #endif
120
121 #define info(fmt,args...) { if(tcore_debug) TCORE_LOG_FUNC(TCORE_LOG_FILE, fmt "\n", ##args); fflush(TCORE_LOG_FILE);}
122 #define msg(fmt,args...) { if(tcore_debug) TCORE_LOG_FUNC(TCORE_LOG_FILE, fmt "\n", ##args); fflush(TCORE_LOG_FILE);}
123 #define dbg(fmt,args...) { if(tcore_debug) TCORE_LOG_FUNC(TCORE_LOG_FILE, ANSI_COLOR_LIGHTGRAY "<%s:%s> " ANSI_COLOR_NORMAL fmt "\n", __FILE__, __FUNCTION__, ##args); fflush(TCORE_LOG_FILE);}
124 #define warn(fmt,args...) TCORE_LOG_FUNC(TCORE_LOG_FILE, ANSI_COLOR_YELLOW "<%s:%s> " ANSI_COLOR_NORMAL fmt "\n", __FILE__, __FUNCTION__, ##args); fflush(TCORE_LOG_FILE);
125 #define err(fmt,args...)  TCORE_LOG_FUNC(TCORE_LOG_FILE, ANSI_COLOR_LIGHTRED "<%s:%s> " ANSI_COLOR_NORMAL fmt "\n", __FILE__, __FUNCTION__, ##args); fflush(TCORE_LOG_FILE);
126 #define fatal(fmt,args...)  TCORE_LOG_FUNC(TCORE_LOG_FILE, ANSI_COLOR_LIGHTRED "<%s:%s> " ANSI_COLOR_NORMAL fmt "\n", __FILE__, __FUNCTION__, ##args); fflush(TCORE_LOG_FILE);
127
128 #endif
129
130 __END_DECLS
131
132 #endif