OpenClovis Logo

clLogUtilApi.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2002-2012 OpenClovis Solutions Inc. All Rights Reserved.
3  *
4  * This file is available under a commercial license from the
5  * copyright holder or the GNU General Public License Version 2.0.
6  *
7  * The source code for this program is not published or otherwise
8  * divested of its trade secrets, irrespective of what has been
9  * deposited with the U.S. Copyright office.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * General Public License for more details.
15  *
16  * For more information, see the file COPYING provided with this
17  * material.
18  */
30 #ifndef _CL_LOG_UTIL_API_H_
31 #define _CL_LOG_UTIL_API_H_
32 
33 #ifdef __cplusplus
34 extern "C"
35 {
36 #endif
37 
38 #include <stdio.h>
39 #include <stdarg.h>
40 #include <clCommon.h>
41 #include <clHeapApi.h>
42 
43 
44 #define CL_LOG_MAX_MSG_LEN 1024
45 #define CL_LOG_MAX_NUM_MSGS 992
46 
54 /*
55  * Initialized
56  */
57 ClRcT
59 
60 ClRcT
61 clLogUtilLibFinalize(ClBoolT logLibInit);
62 
66 #define CL_LOG_AREA_UNSPECIFIED "---"
67 
71 #define CL_LOG_CONTEXT_UNSPECIFIED "---"
72 
76 #define CL_LOG_DEFAULT_SYS_SERVICE_ID 0x01
77 
78 
87 #define clLog(severity, area, context, ...) \
88 do \
89 { \
90  const ClCharT *pArea = CL_LOG_AREA_UNSPECIFIED; \
91  const ClCharT *pContext = CL_LOG_CONTEXT_UNSPECIFIED; \
92  if( NULL != area ) \
93  { \
94  pArea = area; \
95  } \
96  if( NULL != context ) \
97  { \
98  pContext = context; \
99  } \
100  clLogMsgWrite(CL_LOG_HANDLE_SYS, (ClLogSeverityT)severity, \
101  CL_LOG_DEFAULT_SYS_SERVICE_ID, \
102  pArea, pContext, __FILE__, __LINE__, \
103  __VA_ARGS__); \
104 } while(0)
105 
106 #define clLogDeferred(severity, area, context, ...) \
107 do \
108 { \
109  const ClCharT *pArea = CL_LOG_AREA_UNSPECIFIED; \
110  const ClCharT *pContext = CL_LOG_CONTEXT_UNSPECIFIED; \
111  if( NULL != area ) \
112  { \
113  pArea = area; \
114  } \
115  if( NULL != context ) \
116  { \
117  pContext = context; \
118  } \
119  clLogMsgWriteDeferred(CL_LOG_HANDLE_SYS, (ClLogSeverityT)severity, \
120  CL_LOG_DEFAULT_SYS_SERVICE_ID, \
121  pArea, pContext, __FILE__, __LINE__, \
122  __VA_ARGS__); \
123 } while(0)
124 
125 #define clLogConsole(severity, area, context, ...) \
126 do \
127 { \
128  const ClCharT *pArea = CL_LOG_AREA_UNSPECIFIED; \
129  const ClCharT *pContext = CL_LOG_CONTEXT_UNSPECIFIED; \
130  if( NULL != area ) \
131  { \
132  pArea = area; \
133  } \
134  if( NULL != context ) \
135  { \
136  pContext = context; \
137  } \
138  clLogMsgWriteConsole(CL_LOG_HANDLE_SYS, (ClLogSeverityT)severity, \
139  CL_LOG_DEFAULT_SYS_SERVICE_ID, \
140  pArea, pContext, __FILE__, __LINE__, \
141  __VA_ARGS__); \
142 } while(0)
143 
179 #define clAppLog(streamHandle, severity, serviceId, area, context, ...) \
180 do \
181 { \
182  const ClCharT *pArea = CL_LOG_AREA_UNSPECIFIED; \
183  const ClCharT *pContext = CL_LOG_AREA_UNSPECIFIED; \
184  if( NULL != area ) \
185  { \
186  pArea = area; \
187  } \
188  if( NULL != context ) \
189  { \
190  pContext = context; \
191  } \
192  clLogMsgWrite(streamHandle, severity, serviceId, pArea, pContext, \
193  __FILE__, __LINE__, __VA_ARGS__); \
194 } while(0)
195 
206 extern void parseMultiline(ClCharT **ppMsg, const ClCharT *pFmt, ...) CL_PRINTF_FORMAT(2, 3);
207 
208 #define clLogMultiline(severity, area, context, ...) \
209 do { \
210  ClCharT *msg = NULL; \
211  ClCharT str[CL_LOG_SLINE_MSG_LEN+10] = {0}; \
212  ClCharT *pTemp = NULL; \
213  ClCharT *pStr = NULL; \
214  ClUint32T length = 0; \
215  parseMultiline(&msg, __VA_ARGS__); \
216  if(msg) { \
217  pStr = msg; \
218  while( pStr ) { \
219  pTemp = pStr; \
220  pTemp = strchr(pTemp, '\n'); \
221  if( NULL == pTemp ) { \
222  if(*pStr) { \
223  snprintf(str, CL_LOG_SLINE_MSG_LEN+3, "%s%s", \
224  ((pStr==msg) ? "" : "- "), pStr); \
225  clLog(severity, area, context, str); \
226  } \
227  break; \
228  } \
229  length = pTemp - pStr; \
230  ++pTemp; \
231  if(length > 0 ) { \
232  snprintf(str, CL_LOG_SLINE_MSG_LEN+3,"%s%.*s", \
233  ((pStr==msg) ? "" : "- "), length, pStr); \
234  clLog(severity, area, context, str); \
235  } \
236  pStr += (pTemp - pStr); \
237  } \
238  clHeapFree(msg); \
239  } \
240 } while(0)
241 
242 
243 /*
244  * Macros to log messages at different levels of severity
245  */
246 
247 #define clLogEmergency(area, context, ...) \
248  clLog(CL_LOG_SEV_EMERGENCY, area, context, __VA_ARGS__)
249 
250 #define clLogConsoleEmergency(area, context, ...) \
251  clLogConsole(CL_LOG_SEV_EMERGENCY, area, context, __VA_ARGS__)
252 
253 #define clLogAlert(area, context, ...) \
254  clLog(CL_LOG_SEV_ALERT, area, context, __VA_ARGS__)
255 
256 #define clLogConsoleAlert(area, context, ...) \
257  clLogConsole(CL_LOG_SEV_ALERT, area, context, __VA_ARGS__)
258 
259 #define clLogCritical(area, context, ...) \
260  clLog(CL_LOG_SEV_CRITICAL, area, context, __VA_ARGS__)
261 
262 #define clLogConsoleCritical(area, context, ...) \
263  clLogConsole(CL_LOG_SEV_CRITICAL, area, context, __VA_ARGS__)
264 
265 #define clLogError(area, context, ...) \
266  clLog(CL_LOG_SEV_ERROR, area, context, __VA_ARGS__)
267 
268 #define clLogConsoleError(area, context, ...) \
269  clLogConsole(CL_LOG_SEV_ERROR, area, context, __VA_ARGS__)
270 
271 #define clLogWarning(area, context, ...) \
272  clLog(CL_LOG_SEV_WARNING, area, context, __VA_ARGS__)
273 
274 #define clLogConsoleWarning(area, context, ...) \
275  clLogConsole(CL_LOG_SEV_WARNING, area, context, __VA_ARGS__)
276 
277 #define clLogNotice(area, context, ...) \
278  clLog(CL_LOG_SEV_NOTICE, area, context, __VA_ARGS__)
279 
280 #define clLogConsoleNotice(area, context, ...) \
281  clLogConsole(CL_LOG_SEV_NOTICE, area, context, __VA_ARGS__)
282 
283 #define clLogInfo(area, context, ...) \
284  clLog(CL_LOG_SEV_INFO, area, context, __VA_ARGS__)
285 
286 #define clLogConsoleInfo(area, context, ...) \
287  clLogConsole(CL_LOG_SEV_INFO, area, context, __VA_ARGS__)
288 
289 #define clLogDebug(area, context, ...) \
290  clLog(CL_LOG_SEV_DEBUG, area, context, __VA_ARGS__)
291 
292 #define clLogConsoleDebug(area, context, ...) \
293  clLogConsole(CL_LOG_SEV_DEBUG, area, context, __VA_ARGS__)
294 
295 #define clLogTrace(area, context, ...) \
296  clLog(CL_LOG_SEV_TRACE, area, context, __VA_ARGS__)
297 
298 #define clLogConsoleTrace(area, context, ...) \
299  clLogConsole(CL_LOG_SEV_TRACE, area, context, __VA_ARGS__)
300 
301 #ifdef __cplusplus
302  }
303 #endif
304 #endif
305 

Generated on Tue Jan 10 10:29:15 PST 2012 for OpenClovis SDK using Doxygen