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