plog.h

00001 /*---------------------------------------------------------------------------*
00002  *  plog.h  *
00003  *                                                                           *
00004  *  Copyright 2007 Nuance Communciations, Inc.                               *
00005  *                                                                           *
00006  *  Licensed under the Apache License, Version 2.0 (the 'License');          *
00007  *  you may not use this file except in compliance with the License.         *
00008  *                                                                           *
00009  *  You may obtain a copy of the License at                                  *
00010  *      http://www.apache.org/licenses/LICENSE-2.0                           *
00011  *                                                                           *
00012  *  Unless required by applicable law or agreed to in writing, software      *
00013  *  distributed under the License is distributed on an 'AS IS' BASIS,        *
00014  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 
00015  *  See the License for the specific language governing permissions and      *
00016  *  limitations under the License.                                           *
00017  *                                                                           *
00018  *---------------------------------------------------------------------------*/
00019 
00020 #ifndef PLOG_H
00021 #define PLOG_H
00022 
00023 
00024 
00025 #include "ESR_ReturnCode.h"
00026 #include "PortPrefix.h"
00027 #ifdef USE_STACKTRACE
00028 #include "PStackTrace.h"
00029 #endif
00030 #include "passert.h"
00031 #include "PFileSystem.h"
00032 #include "ptypes.h"
00033 
00060 typedef struct PLogger_t
00061 {
00073   ESR_ReturnCode(*printf)(struct PLogger_t *self,
00074                           const LCHAR *format, ...);
00075                           
00084   ESR_ReturnCode(*flush)(struct PLogger_t *self);
00085   
00091   void(*destroy)(struct PLogger_t *self);
00092 }
00093 PLogger;
00094 
00098 typedef asr_uint16_t LOG_OUTPUT_FORMAT;
00099 
00103 #define LOG_OUTPUT_FORMAT_NONE 0x0000
00104 
00108 #define LOG_OUTPUT_FORMAT_DATE_TIME 0x0001
00109 
00113 #define LOG_OUTPUT_FORMAT_THREAD_ID 0x0002
00114 
00119 #define LOG_OUTPUT_FORMAT_MODULE_NAME 0x0004
00120 
00135 PORTABLE_API ESR_ReturnCode PLogInit(PLogger *logger, unsigned int logLevel);
00136 
00143 PORTABLE_API ESR_ReturnCode PLogIsInitialized(ESR_BOOL* isInit);
00144 
00151 PORTABLE_API ESR_ReturnCode PLogIsLocked(ESR_BOOL* isLocked);
00152 
00161 PORTABLE_API ESR_ReturnCode PLogShutdown(void);
00162 
00174 PORTABLE_API ESR_ReturnCode PLogSetFormat(LOG_OUTPUT_FORMAT format);
00175 
00186 PORTABLE_API ESR_ReturnCode PLogGetLevel(unsigned int *logLevel);
00187 
00188 
00198 PORTABLE_API ESR_ReturnCode PLogSetLevel(unsigned int logLevel);
00199 
00209 PORTABLE_API ESR_ReturnCode PLogMessage(const LCHAR* msg, ...);
00210 
00220 PORTABLE_API ESR_ReturnCode PLogError(const LCHAR* msg, ...);
00221 
00222 
00233 PORTABLE_API ESR_ReturnCode PLogCreateFileLogger(PFile* file,
00234     PLogger** logger);
00235     
00246 PORTABLE_API ESR_ReturnCode PLogCreateCircularFileLogger(const LCHAR* filename,
00247     unsigned int maxsize,
00248     PLogger** logger);
00249     
00250     
00251     
00256 /* show more information for vxworks due to lack of stack trace */
00257 #define CHKLOG(rc, function) do { rc = (function); if (rc != ESR_SUCCESS) { PLogError("%s in %s:%d", ESR_rc2str(rc),  __FILE__, __LINE__); goto CLEANUP; } } while (0)
00258 
00266 #define PLOG_CHKRC_ARGS(rc, function, args) do { if((rc = (function args)) != ESR_SUCCESS) { PLogError(ESR_rc2str(rc)); return rc; } } while (0)
00267 
00272 #define PLOG_CHKRC(rc, function) do { rc = (function); if (rc != ESR_SUCCESS) { PLogError(rc); return rc; } } while (0)
00273 
00274 #if defined(_DEBUG) && !defined(ENABLE_PLOG_TRACE) && ENABLE_STACKTRACE
00275 #define ENABLE_PLOG_TRACE
00276 #endif
00277 
00281 #ifdef ENABLE_PLOG_TRACE
00282 
00283 #define PLOG_DBG_ERROR(msg) ((void) (PLogError msg))
00284 
00290 #define PLOG_DBG_TRACE(args) ((void) (PLogMessage args))
00291 #define PLOG_DBG_BLOCK(block) block
00292 #define PLOG_DBG_API_ENTER() \
00293   do \
00294   { \
00295     LCHAR text[P_MAX_FUNCTION_NAME]; \
00296     size_t len = P_MAX_FUNCTION_NAME; \
00297     ESR_ReturnCode rc; \
00298     \
00299     rc = PStackTraceGetFunctionName(text, &len); \
00300     if (rc==ESR_SUCCESS) \
00301       PLogMessage(L("%s entered."), text); \
00302     else if (rc!=ESR_NOT_SUPPORTED) \
00303       pfprintf(PSTDERR, L("[%s:%d] PStackTraceGetValue failed with %s\n"), __FILE__, __LINE__, ESR_rc2str(rc)); \
00304   } while (0)
00305 
00306 #define PLOG_DBG_API_EXIT(rc) \
00307   \
00308   do \
00309   { \
00310     LCHAR text[P_MAX_FUNCTION_NAME]; \
00311     size_t len = P_MAX_FUNCTION_NAME; \
00312     ESR_ReturnCode rc2; \
00313     \
00314     rc2 = PStackTraceGetFunctionName(text, &len); \
00315     if (rc2==ESR_SUCCESS) \
00316       PLogMessage(L("%s returned %s"), text, ESR_rc2str(rc)); \
00317     else if (rc!=ESR_NOT_SUPPORTED) \
00318       pfprintf(PSTDERR, "[%s:%d] PStackTraceGetValue failed with %s\n", __FILE__, __LINE__, ESR_rc2str(rc2)); \
00319   } while (0)
00320 
00321 #else
00322 
00323 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00324 #define PLOG_DBG_ERROR(msg) ((void) 0)
00325 #define PLOG_DBG_MODULE(name, logLevel)
00326 #define PLOG_DBG_TRACE(args) ((void) 0)
00327 #define PLOG_DBG_BLOCK(block)
00328 #define PLOG_DBG_API_ENTER() ((void) 0)
00329 #define PLOG_DBG_API_EXIT(rc) ((void) 0)
00330 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
00331 #endif /* ENABLE_PLOG_TRACE */
00332 
00338 #endif 

Generated on Thu May 1 15:37:25 2008 for SREC by  doxygen 1.5.3