create libdeviced.so
[platform/core/system/system-server.git] / src / shared / log.h
1 /*
2  * deviced
3  * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
4  *
5  * Licensed under the Apache License, Version 2.0 (the License);
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18
19 #ifndef __LOG_H__
20 #define __LOG_H__
21
22 #include <stdio.h>
23
24 #if defined(ENABLE_DLOG_OUT)
25 #define LOG_TAG         "DEVICED"
26 #include <dlog.h>
27 #define DLOG_ERR                DLOG_ERROR
28 #define __LOG(prio, fmt, arg...) \
29         do { SLOG(prio, LOG_TAG, fmt, ##arg); } while (0)
30 #define __LOGD(prio, fmt, arg...) \
31         do { SLOG(prio, LOG_TAG, "%s: %s(%d) > " fmt, __MODULE__, __func__, __LINE__, ##arg); } while (0)
32 #define __PRT(prio, fmt, arg...) \
33         do { fprintf(((D##prio) == DLOG_ERR ? stderr : stdout), fmt"\n", ##arg); } while (0)
34 #define __PRTD(prio, fmt, arg...) \
35         do { \
36                 fprintf(((D##prio) == DLOG_ERR ? stderr : stdout), \
37                                 "%s: %s(%d) > "fmt"\n", __MODULE__, __func__, __LINE__, ##arg); \
38         } while (0)
39 #else
40 #include <syslog.h>
41 #define __LOG(prio, fmt, arg...) \
42         do { syslog(prio, fmt, ##arg); } while (0)
43 #define __LOGD(prio, fmt, arg...) \
44         do { syslog(prio, "%s: %s(%d) > "fmt"\n", __MODULE__, __func__, __LINE__, ##arg); } while (0)
45 #define __PRT(prio, fmt, arg...) \
46         do { fprintf(((prio) == LOG_ERR ? stderr : stdout), fmt"\n", ##arg); } while (0)
47 #define __PRTD(prio, fmt, arg...) \
48         do { \
49                 fprintf(((prio) == LOG_ERR ? stderr : stdout), \
50                                  "%s: %s(%d) > "fmt"\n", __MODULE__, __func__, __LINE__, ##arg); \
51         } while (0)
52 #endif
53
54 #ifdef DEBUG
55 extern int g_trace_depth;
56 #define __PRT_TRACE(prio, fmt, arg...) \
57         do { __LOGD(prio, fmt, ##arg); } while (0)
58 /*      do { \
59                 int ___i;\
60                 for(___i=0;___i<g_trace_depth;___i++)\
61                 {\
62                         fprintf(stdout, "  "); \
63                 }\
64                 fprintf(stdout,\
65                         "[%s:%d] "fmt"\n", __FUNCTION__, __LINE__,##arg); \
66                 __LOGD(prio, fmt, ##arg); \
67         } while (0) */
68 #define __PRT_TRACE_ERR(prio, fmt, arg...) \
69         do { __LOGD(prio, fmt, ##arg); } while (0)
70 /*      do { \
71                 int ___i;\
72                 for(___i=0;___i<g_trace_depth;___i++)\
73                 {\
74                         fprintf(stdout, "  "); \
75                 }\
76                 printf(\
77                         "%c[1;31m[%s:%d] "fmt"%c[0m\n",27, __FUNCTION__, __LINE__,##arg,27); \
78                 __LOGD(prio, fmt, ##arg); \
79         } while (0)*/
80 #define __PRT_TRACE_EM(prio, fmt, arg...) \
81         do { __LOGD(prio, fmt, ##arg); } while (0)
82 /*      do { \
83                 int ___i;\
84                 for(___i=0;___i<g_trace_depth;___i++)\
85                 {\
86                         fprintf(stdout, "  "); \
87                 }\
88                 printf(\
89                         "%c[1;34m[%s:%d] "fmt"%c[0m\n",27, __FUNCTION__, __LINE__,##arg,27); \
90                 __LOGD(prio, fmt, ##arg); \
91         } while (0)*/
92 #endif
93
94 #define _NOUT(prio, fmt, arg...) do { } while (0)
95
96 #ifdef DEBUG
97 #  define _LOGD __LOGD
98 #  define _LOG  __LOGD
99 #  define _PRTD __PRTD
100 #  define _PRT  __PRTD
101 #  define _PRT_TRACE __PRT_TRACE
102 #  define _PRT_TRACE_ERR __PRT_TRACE_ERR
103 #  define _PRT_TRACE_EM __PRT_TRACE_EM
104 #else
105 #  define _LOGD _NOUT
106 #  define _LOG  __LOG
107 #  define _PRTD _NOUT
108 #  define _PRT  __PRT
109 #  define _PRT_TRACE _NOUT
110 #  define _PRT_TRACE_ERR _NOUT
111 #  define _PRT_TRACE_EM _NOUT
112 #endif
113
114 #define PRT_INFO(fmt, arg...) _PRT(LOG_INFO, fmt, ##arg)
115 #define PRT_ERR(fmt, arg...) _PRT(LOG_ERR, fmt, ##arg)
116 #define PRT_DBG(fmt, arg...) _PRTD(LOG_DEBUG, fmt, ##arg)
117 #define PRT_TRACE(fmt, arg...) _PRT_TRACE(LOG_DEBUG, fmt, ##arg)
118 #define PRT_TRACE_ERR(fmt, arg...) _PRT_TRACE_ERR(LOG_ERR, fmt, ##arg)
119 #define PRT_TRACE_EM(fmt, arg...) _PRT_TRACE_EM(LOG_DEBUG, fmt, ##arg)
120
121 #if defined(SYSLOG_OUT)
122 #  define SYSLOG_INFO(fmt, arg...) _LOG(LOG_INFO, fmt, ##arg)
123 #  define SYSLOG_ERR(fmt, arg...) _LOG(LOG_ERR, fmt, ##arg)
124 #  define SYSLOG_DBG(fmt, arg...) _LOGD(LOG_DEBUG, fmt, ##arg)
125 #  define INFO SYSLOG_INFO
126 #  define ERR SYSLOG_ERR
127 #  define DBG SYSLOG_DBG
128 #elif defined(ENABLE_DLOG_OUT)
129 #  define INFO SLOGI
130 #  define ERR SLOGE
131 #  define DBG SLOGD
132 #else
133 #  define INFO PRT_INFO
134 #  define ERR PRT_ERR
135 #  define DBG PRT_DBG
136 #endif
137
138 #endif