Main Page | Modules | Data Structures | File List | Data Fields | Related Pages

logger.h

00001 /***************************************************************************
00002  * CVSID: $Id: logger.h,v 1.4 2004/01/02 12:11:24 david Exp $
00003  *
00004  * logger.h : Logging facility
00005  *
00006  * Copyright (C) 2003 David Zeuthen, <david@fubar.dk>
00007  *
00008  * Licensed under the Academic Free License version 2.0
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023  *
00024  **************************************************************************/
00025 
00026 #ifndef LOGGER_H
00027 #define LOGGER_H
00028 
00038 enum
00039 {
00040     HAL_LOGPRI_TRACE   =  (1<<0),  
00041     HAL_LOGPRI_DEBUG   =  (1<<1),  
00042     HAL_LOGPRI_INFO    =  (1<<2),  
00043     HAL_LOGPRI_WARNING =  (1<<3),  
00044     HAL_LOGPRI_ERROR   =  (1<<4)   
00045 };
00046 
00047 void logger_init();
00048 
00049 void logger_setup(int priority, const char* file, int line, 
00050                   const char* function);
00051 
00052 void logger_emit(const char* format,...);
00053 
00054 #ifdef ENABLE_VERBOSE_MODE
00055 
00056 /* Verbose mode */
00057 
00059 #define HAL_TRACE(expr)   do {logger_setup(HAL_LOGPRI_TRACE,   __FILE__, __LINE__, __FUNCTION__); logger_emit expr; } while(0)
00060 
00062 #define HAL_DEBUG(expr)   do {logger_setup(HAL_LOGPRI_DEBUG,   __FILE__, __LINE__, __FUNCTION__); logger_emit expr; } while(0)
00063 
00065 #define HAL_INFO(expr)    do {logger_setup(HAL_LOGPRI_INFO,    __FILE__, __LINE__, __FUNCTION__); logger_emit expr; } while(0)
00066 
00068 #define HAL_WARNING(expr) do {logger_setup(HAL_LOGPRI_WARNING, __FILE__, __LINE__, __FUNCTION__); logger_emit expr; } while(0)
00069 
00071 #define HAL_ERROR(expr)   do {logger_setup(HAL_LOGPRI_ERROR,   __FILE__, __LINE__, __FUNCTION__); logger_emit expr; } while(0)
00072 
00074 #define DIE(expr) do {printf("*** [DIE] %s:%s():%d : ", __FILE__, __FUNCTION__, __LINE__); printf expr; printf("\n"); exit(1); } while(0)
00075 
00076 #else
00077 
00078 /* If verbose mode is not requested only handle warning and error */
00079 
00080 #define HAL_TRACE(expr) do {;} while(0)
00081 #define HAL_DEBUG(expr) do {;} while(0)
00082 #define HAL_INFO(expr) do {;} while(0)
00083 
00084 #define HAL_WARNING(expr) do {logger_setup(HAL_LOGPRI_WARNING, __FILE__, __LINE__, __FUNCTION__); logger_emit expr; } while(0)
00085 
00086 #define HAL_ERROR(expr)   do {logger_setup(HAL_LOGPRI_ERROR,   __FILE__, __LINE__, __FUNCTION__); logger_emit expr; } while(0)
00087 
00088 #define DIE(expr) do {printf("*** [DIE] %s:%s():%d : ", __FILE__, __FUNCTION__, __LINE__); printf expr; printf("\n"); exit(1); } while(0)
00089 
00090 
00091 #endif /* ENABLE_VERBOSE_MODE */
00092 
00095 #endif /* LOGGER_H */

Generated on Sat Feb 7 22:11:48 2004 for HAL by doxygen 1.3.5