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 clLogFL(file,line,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  clLogMsgWrite(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 
126 #define clLogDeferred(severity, area, context, ...) \
127 do \
128 { \
129  const ClCharT *pArea = CL_LOG_AREA_UNSPECIFIED; \
130  const ClCharT *pContext = CL_LOG_CONTEXT_UNSPECIFIED; \
131  if( NULL != area ) \
132  { \
133  pArea = area; \
134  } \
135  if( NULL != context ) \
136  { \
137  pContext = context; \
138  } \
139  clLogMsgWriteDeferred(CL_LOG_HANDLE_SYS, (ClLogSeverityT)severity, \
140  CL_LOG_DEFAULT_SYS_SERVICE_ID, \
141  pArea, pContext, __FILE__, __LINE__, \
142  __VA_ARGS__); \
143 } while(0)
144 
145 #define clLogConsole(severity, area, context, ...) \
146 do \
147 { \
148  const ClCharT *pArea = CL_LOG_AREA_UNSPECIFIED; \
149  const ClCharT *pContext = CL_LOG_CONTEXT_UNSPECIFIED; \
150  if( NULL != area ) \
151  { \
152  pArea = area; \
153  } \
154  if( NULL != context ) \
155  { \
156  pContext = context; \
157  } \
158  clLogMsgWriteConsole(CL_LOG_HANDLE_SYS, (ClLogSeverityT)severity, \
159  CL_LOG_DEFAULT_SYS_SERVICE_ID, \
160  pArea, pContext, __FILE__, __LINE__, \
161  __VA_ARGS__); \
162 } while(0)
163 
199 #define clAppLog(streamHandle, severity, serviceId, area, context, ...) \
200 do \
201 { \
202  const ClCharT *pArea = CL_LOG_AREA_UNSPECIFIED; \
203  const ClCharT *pContext = CL_LOG_AREA_UNSPECIFIED; \
204  if( NULL != area ) \
205  { \
206  pArea = area; \
207  } \
208  if( NULL != context ) \
209  { \
210  pContext = context; \
211  } \
212  clLogMsgWrite(streamHandle, severity, serviceId, pArea, pContext, \
213  __FILE__, __LINE__, __VA_ARGS__); \
214 } while(0)
215 
226 extern void parseMultiline(ClCharT **ppMsg, const ClCharT *pFmt, ...) CL_PRINTF_FORMAT(2, 3);
227 
228 #define clLogMultiline(severity, area, context, ...) \
229 do { \
230  ClCharT *msg = NULL; \
231  ClCharT str[CL_LOG_SLINE_MSG_LEN+10] = {0}; \
232  ClCharT *pTemp = NULL; \
233  ClCharT *pStr = NULL; \
234  ClUint32T length = 0; \
235  parseMultiline(&msg, __VA_ARGS__); \
236  if(msg) { \
237  pStr = msg; \
238  while( pStr ) { \
239  pTemp = pStr; \
240  pTemp = strchr(pTemp, '\n'); \
241  if( NULL == pTemp ) { \
242  if(*pStr) { \
243  snprintf(str, CL_LOG_SLINE_MSG_LEN+3, "%s%s", \
244  ((pStr==msg) ? "" : "- "), pStr); \
245  clLog(severity, area, context, str); \
246  } \
247  break; \
248  } \
249  length = pTemp - pStr; \
250  ++pTemp; \
251  if(length > 0 ) { \
252  snprintf(str, CL_LOG_SLINE_MSG_LEN+3,"%s%.*s", \
253  ((pStr==msg) ? "" : "- "), length, pStr); \
254  clLog(severity, area, context, str); \
255  } \
256  pStr += (pTemp - pStr); \
257  } \
258  clHeapFree(msg); \
259  } \
260 } while(0)
261 
262 
263 /*
264  * Macros to log messages at different levels of severity
265  */
266 
267 #define clLogEmergency(area, context, ...) \
268  clLog(CL_LOG_SEV_EMERGENCY, area, context, __VA_ARGS__)
269 
270 #define clLogConsoleEmergency(area, context, ...) \
271  clLogConsole(CL_LOG_SEV_EMERGENCY, area, context, __VA_ARGS__)
272 
273 #define clLogAlert(area, context, ...) \
274  clLog(CL_LOG_SEV_ALERT, area, context, __VA_ARGS__)
275 
276 #define clLogConsoleAlert(area, context, ...) \
277  clLogConsole(CL_LOG_SEV_ALERT, area, context, __VA_ARGS__)
278 
279 #define clLogCritical(area, context, ...) \
280  clLog(CL_LOG_SEV_CRITICAL, area, context, __VA_ARGS__)
281 
282 #define clLogConsoleCritical(area, context, ...) \
283  clLogConsole(CL_LOG_SEV_CRITICAL, area, context, __VA_ARGS__)
284 
285 #define clLogError(area, context, ...) \
286  clLog(CL_LOG_SEV_ERROR, area, context, __VA_ARGS__)
287 
288 #define clLogConsoleError(area, context, ...) \
289  clLogConsole(CL_LOG_SEV_ERROR, area, context, __VA_ARGS__)
290 
291 #define clLogWarning(area, context, ...) \
292  clLog(CL_LOG_SEV_WARNING, area, context, __VA_ARGS__)
293 
294 #define clLogConsoleWarning(area, context, ...) \
295  clLogConsole(CL_LOG_SEV_WARNING, area, context, __VA_ARGS__)
296 
297 #define clLogNotice(area, context, ...) \
298  clLog(CL_LOG_SEV_NOTICE, area, context, __VA_ARGS__)
299 
300 #define clLogConsoleNotice(area, context, ...) \
301  clLogConsole(CL_LOG_SEV_NOTICE, area, context, __VA_ARGS__)
302 
303 #define clLogInfo(area, context, ...) \
304  clLog(CL_LOG_SEV_INFO, area, context, __VA_ARGS__)
305 
306 #define clLogConsoleInfo(area, context, ...) \
307  clLogConsole(CL_LOG_SEV_INFO, area, context, __VA_ARGS__)
308 
309 #define clLogDebug(area, context, ...) \
310  clLog(CL_LOG_SEV_DEBUG, area, context, __VA_ARGS__)
311 
312 #define clLogConsoleDebug(area, context, ...) \
313  clLogConsole(CL_LOG_SEV_DEBUG, area, context, __VA_ARGS__)
314 
315 #define clLogTrace(area, context, ...) \
316  clLog(CL_LOG_SEV_TRACE, area, context, __VA_ARGS__)
317 
318 #define clLogConsoleTrace(area, context, ...) \
319  clLogConsole(CL_LOG_SEV_TRACE, area, context, __VA_ARGS__)
320 
321 #ifdef __cplusplus
322  }
323 #endif
324 #endif
325 
Typical defines found in any software project.
Header file of Heap Management related APIs.
ClUint32T ClRcT
Clovis return code type.
Definition: clCommon.h:168
ClRcT clLogUtilLibInitialize(void)
It takes one of the above severity level.
void parseMultiline(ClCharT **ppMsg, const ClCharT *pFmt,...) CL_PRINTF_FORMAT(2
This macro provides the support to log messages by specifying the severity of log message and server ...

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