popupmenu/include/log.h

Go to the documentation of this file.
00001 #ifndef __LOG_H__
00002 #define __LOG_H__
00003 
00004 /**
00005  * File Name  : log.h
00006  *
00007  * Description: Macros for debug printing.
00008  *
00009  * The value of ERREGLOG_X_ON (with X one of LOGGING, WARNING or ERROR)
00010  * determines whether a message will be printed. The value as defined
00011  * in this file can be overruled by defining them before the inclusion of this file.
00012  *
00013  * This file is best included in c files only.
00014  */
00015 
00016 /*
00017  * This file is part of popupmenu.
00018  *
00019  * popupmenu is free software: you can redistribute it and/or modify
00020  * it under the terms of the GNU General Public License as published by
00021  * the Free Software Foundation, either version 2 of the License, or
00022  * (at your option) any later version.
00023  *
00024  * popupmenu is distributed in the hope that it will be useful,
00025  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00026  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00027  * GNU General Public License for more details.
00028  *
00029  * You should have received a copy of the GNU General Public License
00030  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00031  */
00032 
00033 /**
00034  * Copyright (C) 2008 iRex Technologies B.V.
00035  * All rights reserved.
00036  */
00037 
00038 #include <stdio.h>
00039 #include "config.h"
00040 
00041 #define LOG_PREFIX PACKAGE_NAME
00042 
00043 #ifndef USE_SYSLOG
00044 #define USE_SYSLOG 0
00045 #endif
00046 
00047 #ifndef TESTING_ON
00048 #define TESTING_ON 1
00049 #endif
00050  
00051 #ifndef LOGGING_ON
00052 #define LOGGING_ON 0
00053 #endif
00054 
00055 #ifndef WARNING_ON
00056 #define WARNING_ON 1
00057 #endif
00058 
00059 #ifndef ERROR_ON
00060 #define ERROR_ON 1
00061 #endif
00062 
00063 
00064 #if (USE_SYSLOG)
00065 #include <syslog.h>
00066 #define LOG_OPEN(X) openlog(X, LOG_PID | LOG_NDELAY, LOG_USER)
00067 #define LOG_CLOSE() closelog()
00068 #else
00069 #define LOG_OPEN(X) do {} while (0)
00070 #define LOG_CLOSE() do {} while (0)
00071 #endif
00072 
00073 #if (LOGGING_ON)
00074 #if (USE_SYSLOG)
00075 #define LOGPRINTF(format, args...) syslog(LOG_INFO | LOG_USER, __FILE__ ":%d,%s() " format "\n", __LINE__, __func__ , ##args)
00076 #else
00077 #define LOGPRINTF(format, args...) fprintf(stderr, "(" LOG_PREFIX "_L)" __FILE__ ":%d,%s() " format "\n", __LINE__, __func__ , ##args)
00078 #endif
00079 #else
00080 #define LOGPRINTF(format, args...) do {} while (0)
00081 #endif
00082 
00083 #if (WARNING_ON)
00084 #if (USE_SYSLOG)
00085 #define WARNPRINTF(format, args...) syslog(LOG_WARNING | LOG_USER, __FILE__ ":%d,%s() " format "\n", __LINE__, __func__ , ##args)
00086 #else
00087 #define WARNPRINTF(format, args...) fprintf(stderr, "(" LOG_PREFIX "_W)" __FILE__ ":%d,%s() " format "\n", __LINE__, __func__ , ##args)
00088 #endif
00089 #else
00090 #define WARNPRINTF(format, args...) do {} while (0)
00091 #endif
00092 
00093 #if (ERROR_ON)
00094 #include <errno.h>
00095 #include <string.h>
00096 #if (USE_SYSLOG)
00097 #define ERRORPRINTF(format, args...) syslog(LOG_ERR | LOG_USER, __FILE__ ":%d,%s() --- " format "\n", __LINE__, __func__ , ##args)
00098 #define ERRNOPRINTF(format, args...) syslog(LOG_ERR | LOG_USER, __FILE__ ":%d,%s() --- " format ", errno [%d] [%s]\n", __LINE__, __func__ , ##args, errno, strerror(errno))
00099 #else
00100 #define ERRORPRINTF(format, args...) fprintf(stderr, "(" LOG_PREFIX "_E)" __FILE__ ":%d,%s() --- " format "\n", __LINE__, __func__ , ##args)
00101 #define ERRNOPRINTF(format, args...) fprintf(stderr, "(" LOG_PREFIX "_E)" __FILE__ ":%d,%s() --- " format ", errno [%d] [%s]\n", __LINE__, __func__ , ##args, errno, strerror(errno))
00102 #endif
00103 #else
00104 #define ERRORPRINTF(format, args...) do {} while (0)
00105 #define ERRNOPRINTF(format, args...) do {} while (0)
00106 #endif
00107 
00108 //#define TRACE(format, args...) printf(format, ##args)
00109 #define TRACE(format, args...) do {} while (0)
00110 
00111 #if (TESTING_ON)
00112 #define DEBUG(format, args...) printf(format, ##args)
00113 #else
00114 #define DEBUG(format, args...) do {} while (0)
00115 #endif
00116 
00117 #endif // __LOG_H__
Generated by  doxygen 1.6.2-20100208