1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
/*
* devman
*
* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
*
* Contact: DongGi Jang <dg0402.jang@samsung.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef __DEVLOG_H__
#define __DEVLOG_H__
/*
* SYSLOG_INFO(), SYSLOG_ERR(), SYSLOG_DBG() are syslog() wrappers.
* PRT_INFO(), PRT_ERR(), PRT_DBG() are fprintf() wrappers.
*
* If SLP_DEBUG is not defined, SYSLOG_DBG() and PRT_DBG() is ignored.
*
* IF SLP_SYSLOG_OUT is defined,
* INFO(), ERR(), DBG() are SYSLOG_XXX()
* IF ENABLE_DLOG_OUT is defined,
* INFO(), ERR(), DBG() are SLOGI(), SLOGE(), SLOGD()
* Otherwise,
* They are PRT_XXX()
*
*
* warn_if(exrp, fmt, ...)
* If expr is true, The fmt string is printed using ERR().
*
* ret_if(), retv_if(), retm_if(), retvm_if()
* If expr is true, current function return.
* Postfix 'v' means that it has a return value and 'm' means that it has output message.
*
*/
#include <stdio.h>
#include <stdlib.h>
#if defined(ENABLE_DLOG_OUT)
# define LOG_TAG "DEVMAN"
# include <dlog.h>
#else
# include <syslog.h>
# define __LOG(prio, fmt, arg...) \
do { syslog(prio, fmt, ##arg); } while (0)
# define __LOGD(prio, fmt, arg...) \
do { \
if (getenv("SLP_DEBUG")) { \
syslog(prio, "[%s:%d] "fmt"\n", __FILE__, __LINE__, ##arg); \
} \
} while (0)
#endif
#define __PRTI(fmt, arg...) \
do { fprintf(stdout, fmt"\n", ##arg); } while (0)
#define __PRTE(fmt, arg...) \
do { fprintf(stderr, fmt"\n", ##arg); } while (0)
#define __PRTD(fmt, arg...) \
do { \
if (getenv("SLP_DEBUG")) { \
fprintf(stdout, "[%s:%d] "fmt"\n", __FILE__, __LINE__, ##arg); \
} \
} while(0)
#define _NOUT(arg...) do { } while (0)
#ifdef SLP_DEBUG
# define _LOGD __LOGD
# define _LOG __LOG
# define _PRTD __PRTD
# define _PRTI __PRTI
# define _PRTE __PRTE
#else
# define _LOGD _NOUT
# define _LOG __LOG
# define _PRTD _NOUT
# define _PRTI __PRTI
# define _PRTE __PRTE
#endif
#define PRT_INFO(fmt, arg...) _PRTI(fmt, ##arg)
#define PRT_ERR(fmt, arg...) _PRTE(fmt, ##arg)
#define PRT_DBG(fmt, arg...) _PRTD(fmt, ##arg)
#if defined(SLP_SYSLOG_OUT)
# define SYSLOG_INFO(fmt, arg...) _LOG(LOG_INFO, fmt, ##arg)
# define SYSLOG_ERR(fmt, arg...) _LOG(LOG_ERR, fmt, ##arg)
# define SYSLOG_DBG(fmt, arg...) _LOGD(LOG_DEBUG, fmt, ##arg)
# define INFO SYSLOG_INFO
# define ERR SYSLOG_ERR
# define DBG SYSLOG_DBG
#elif defined(ENABLE_DLOG_OUT)
# define INFO SLOGI
# define ERR SLOGE
# define DBG SLOGD
#else
# define INFO PRT_INFO
# define ERR PRT_ERR
# define DBG PRT_DBG
#endif
#ifdef SLP_DEBUG
# define warn_if(expr, fmt, arg...) do { \
if (expr) { \
DBG("(%s) -> "fmt, #expr, ##arg); \
} \
} while (0)
# define ret_if(expr) do { \
if (expr) { \
DBG("(%s) -> %s() return", #expr, __FUNCTION__); \
return; \
} \
} while (0)
# define retv_if(expr, val) do { \
if (expr) { \
DBG("(%s) -> %s() return", #expr, __FUNCTION__); \
return (val); \
} \
} while (0)
# define retm_if(expr, fmt, arg...) do { \
if (expr) { \
ERR(fmt, ##arg); \
DBG("(%s) -> %s() return", #expr, __FUNCTION__); \
return; \
} \
} while (0)
# define retvm_if(expr, val, fmt, arg...) do { \
if (expr) { \
ERR(fmt, ##arg); \
DBG("(%s) -> %s() return", #expr, __FUNCTION__); \
return (val); \
} \
} while (0)
#else
# define warn_if(expr, fmt, arg...) do { \
if (expr) { \
ERR(fmt, ##arg); \
} \
} while (0)
# define ret_if(expr) do { \
if (expr) { \
return; \
} \
} while (0)
# define retv_if(expr, val) do { \
if (expr) { \
return (val); \
} \
} while (0)
# define retm_if(expr, fmt, arg...) do { \
if (expr) { \
ERR(fmt, ##arg); \
return; \
} \
} while (0)
# define retvm_if(expr, val, fmt, arg...) do { \
if (expr) { \
ERR(fmt, ##arg); \
return (val); \
} \
} while (0)
#endif
#endif /* __DEVLOG_H__ */
|