document-viewer-plugins-4.0+svnr7001/plugins/common/log.h

Go to the documentation of this file.
00001 /*
00002  * File Name: log.h
00003  */
00004 
00005 /*
00006  * This file is part of uds-plugin-common.
00007  *
00008  * uds-plugin-common is free software: you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation, either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * uds-plugin-common is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00020  */
00021 
00022 /**
00023  * Copyright (C) 2008 iRex Technologies B.V.
00024  * All rights reserved.
00025  */
00026 
00027 #ifndef PLUGIN_LOG_H
00028 #define PLUGIN_LOG_H
00029 
00030 #include <stdio.h>
00031 #include <pthread.h>
00032 #include "config.h"
00033 
00034 #ifndef LOGGING_ON
00035 #define LOGGING_ON       0
00036 #endif
00037 #ifndef WARNING_ON
00038 #define WARNING_ON       1
00039 #endif
00040 #ifndef ERROR_ON
00041 #define ERROR_ON         1
00042 #endif
00043 #ifndef TRACE_ON 
00044 #define TRACE_ON         0
00045 #endif
00046 
00047 #define LOG_PREFIX  "UDS_" PACKAGE_NAME
00048 
00049 #if (LOGGING_ON)
00050 #define LOGPRINTF(x, ...) fprintf(stderr, "(" LOG_PREFIX "_L)[%d]" __FILE__ ":%d,%s() " x "\n", (unsigned int)pthread_self(), __LINE__, __FUNCTION__ , ##__VA_ARGS__)
00051 #else
00052 #define LOGPRINTF(x, ...) do {} while (0)
00053 #endif
00054 
00055 #if (WARNING_ON)
00056 #define WARNPRINTF(x, ...) fprintf(stderr, "(" LOG_PREFIX "_W)[%d]" __FILE__ ":%d,%s() " x "\n", (unsigned int)pthread_self(), __LINE__, __FUNCTION__ , ##__VA_ARGS__)
00057 #else
00058 #define WARNPRINTF(x, ...) do {} while (0)
00059 #endif
00060 
00061 #if (ERROR_ON)
00062 #define ERRORPRINTF(x, ...) fprintf(stderr, "(" LOG_PREFIX "_E)[%d]" __FILE__ ":%d,%s() " x "\n", (unsigned int)pthread_self(), __LINE__, __FUNCTION__, ##__VA_ARGS__)
00063 #else
00064 #define ERRORPRINTF(x, ...) do {} while (0)
00065 #endif
00066 
00067 #if (TRACE_ON)
00068 #ifdef PLAIN_C
00069 #define TRACEFUNCTION() do {} while (0)
00070 #else
00071 namespace {
00072     class TraceHelper
00073     {
00074         public:
00075             explicit TraceHelper (
00076                     const char* file,
00077                     const int line,
00078                     const char* func
00079                 ) :
00080                 m_file(file), m_line(line), m_func(func), m_threadid((unsigned int)pthread_self())
00081                 { fprintf(stderr, "(" LOG_PREFIX "_F)[%d]%s:%d,%s() entered -->\n", m_threadid, file, line, func); }
00082                 
00083             virtual ~TraceHelper() { fprintf(stderr, "(" LOG_PREFIX "_F)[%d]%s:%d,%s() exited  <--\n", m_threadid, m_file, m_line, m_func); }
00084             
00085         private:
00086             const char* m_file;
00087             const int m_line;
00088             const char* m_func;
00089             const unsigned int m_threadid;
00090     };
00091 };
00092 
00093 // TODO: [MDB] Change into FUNCPRINTF("") macro to allow tracing of input parameters of functions
00094 #define TRACEFUNCTION() TraceHelper th(__FILE__, __LINE__, __FUNCTION__); 
00095 #endif // PLAIN_C
00096 
00097 #else
00098 #define TRACEFUNCTION() do {} while (0)
00099 #endif
00100 
00101 #endif // PLUGIN_LOG_H
Generated by  doxygen 1.6.2-20100208