notepad/include/log.h
Go to the documentation of this file.00001 #ifndef PLUGIN_LOG_H
00002 #define PLUGIN_LOG_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
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 "NP_" 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
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