37614672dbd25a26dd47252840fd668904aede8e
[platform/core/system/system-server.git] / src / core / log.h
1 /*
2  * deviced
3  *
4  * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
5  *
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
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  */
18
19
20 #ifndef __LOG_H__
21 #define __LOG_H__
22
23 #include <stdio.h>
24
25 #if defined(ENABLE_DLOG_OUT)
26 #define LOG_TAG "SYSTEM_SERVER"
27 #include <dlog.h>
28 #define DLOG_ERR                DLOG_ERROR
29 #define _D(fmt, arg...) \
30         do { SLOGD(fmt, ##arg); } while(0)
31 #define _I(fmt, arg...) \
32         do { SLOGI(fmt, ##arg); } while(0)
33 #define _W(fmt, arg...) \
34         do { SLOGW(fmt, ##arg); } while(0)
35 #define _E(fmt, arg...) \
36         do { SLOGE(fmt, ##arg); } while(0)
37 #define _SD(fmt, arg...) \
38         do { SECURE_SLOGD(fmt, ##arg); } while(0)
39 #define _SI(fmt, arg...) \
40         do { SECURE_SLOGI(fmt, ##arg); } while(0)
41 #define _SW(fmt, arg...) \
42         do { SECURE_SLOGW(fmt, ##arg); } while(0)
43 #define _SE(fmt, arg...) \
44         do { SECURE_SLOGE(fmt, ##arg); } while(0)
45 #define __LOGD(prio, fmt, arg...) \
46         do { SLOG(prio, LOG_TAG, fmt, ##arg); } while (0)
47 #define __PRT(prio, fmt, arg...) \
48         do { fprintf(((D##prio) == DLOG_ERR ? stderr : stdout), fmt"\n", ##arg); } while (0)
49 #else
50 #include <syslog.h>
51 #define _D(x, ...)      do { } while (0)
52 #define _I(x, ...)      do { } while (0)
53 #define _W(x, ...)      do { } while (0)
54 #define _E(x, ...)      do { } while (0)
55 #define _SD(fmt, args...)       do { } while (0)
56 #define _SI(fmt, args...)       do { } while (0)
57 #define _SW(fmt, args...)       do { } while (0)
58 #define _SE(fmt, args...)       do { } while (0)
59 #define __LOGD(prio, fmt, arg...) \
60         do { syslog(prio, "%s: %s(%d) > "fmt"\n", __MODULE__, __func__, __LINE__, ##arg); } while (0)
61 #define __PRT(prio, fmt, arg...) \
62         do { fprintf(((prio) == LOG_ERR ? stderr : stdout), fmt"\n", ##arg); } while (0)
63 #endif
64
65 #ifdef DEBUG
66 extern int g_trace_depth;
67 #define __PRT_TRACE(prio, fmt, arg...) \
68         do { __LOGD(prio, fmt, ##arg); } while (0)
69 /*      do { \
70                 int ___i;\
71                 for(___i=0;___i<g_trace_depth;___i++)\
72                 {\
73                         fprintf(stdout, "  "); \
74                 }\
75                 fprintf(stdout,\
76                         "[%s:%d] "fmt"\n", __FUNCTION__, __LINE__,##arg); \
77                 __LOGD(prio, fmt, ##arg); \
78         } while (0) */
79 #define __PRT_TRACE_ERR(prio, fmt, arg...) \
80         do { __LOGD(prio, fmt, ##arg); } while (0)
81 /*      do { \
82                 int ___i;\
83                 for(___i=0;___i<g_trace_depth;___i++)\
84                 {\
85                         fprintf(stdout, "  "); \
86                 }\
87                 printf(\
88                         "%c[1;31m[%s:%d] "fmt"%c[0m\n",27, __FUNCTION__, __LINE__,##arg,27); \
89                 __LOGD(prio, fmt, ##arg); \
90         } while (0)*/
91 #define __PRT_TRACE_EM(prio, fmt, arg...) \
92         do { __LOGD(prio, fmt, ##arg); } while (0)
93 /*      do { \
94                 int ___i;\
95                 for(___i=0;___i<g_trace_depth;___i++)\
96                 {\
97                         fprintf(stdout, "  "); \
98                 }\
99                 printf(\
100                         "%c[1;34m[%s:%d] "fmt"%c[0m\n",27, __FUNCTION__, __LINE__,##arg,27); \
101                 __LOGD(prio, fmt, ##arg); \
102         } while (0)*/
103 #endif
104
105 #define _NOUT(prio, fmt, arg...) do { } while (0)
106
107 #ifdef DEBUG
108 #  define _LOGD __LOGD
109 #  define _LOG  __LOGD
110 #  define _PRTD __PRTD
111 #  define _PRT  __PRTD
112 #  define _PRT_TRACE __PRT_TRACE
113 #  define _PRT_TRACE_ERR __PRT_TRACE_ERR
114 #  define _PRT_TRACE_EM __PRT_TRACE_EM
115 #else
116 #  define _LOGD _NOUT
117 #  define _LOG  __LOG
118 #  define _PRTD _NOUT
119 #  define _PRT  __PRT
120 #  define _PRT_TRACE _NOUT
121 #  define _PRT_TRACE_ERR _NOUT
122 #  define _PRT_TRACE_EM _NOUT
123 #endif
124
125 #define PRT_TRACE(fmt, arg...) _PRT_TRACE(LOG_DEBUG, fmt, ##arg)
126 #define PRT_TRACE_ERR(fmt, arg...) _PRT_TRACE_ERR(LOG_ERR, fmt, ##arg)
127 #define PRT_TRACE_EM(fmt, arg...) _PRT_TRACE_EM(LOG_DEBUG, fmt, ##arg)
128
129 #if defined(SYSLOG_OUT)
130 #  define SYSLOG_INFO(fmt, arg...) _LOG(LOG_INFO, fmt, ##arg)
131 #  define SYSLOG_ERR(fmt, arg...) _LOG(LOG_ERR, fmt, ##arg)
132 #  define SYSLOG_DBG(fmt, arg...) _LOGD(LOG_DEBUG, fmt, ##arg)
133 #  define INFO SYSLOG_INFO
134 #  define ERR SYSLOG_ERR
135 #  define DBG SYSLOG_DBG
136 #elif defined(ENABLE_DLOG_OUT)
137 #  define INFO SLOGI
138 #  define ERR SLOGE
139 #  define DBG SLOGD
140 #else
141 #  define INFO PRT_INFO
142 #  define ERR PRT_ERR
143 #  define DBG PRT_DBG
144 #endif
145
146 #endif