ergtk_log.h

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