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

logger.h

00001 /***************************************************************************
00002  * CVSID: $Id: logger.h,v 1.5 2004/03/03 17:56:56 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     HAL_LOGPRI_TRACE = (1 << 0),   
00040     HAL_LOGPRI_DEBUG = (1 << 1),   
00041     HAL_LOGPRI_INFO = (1 << 2),    
00042     HAL_LOGPRI_WARNING = (1 << 3), 
00043     HAL_LOGPRI_ERROR = (1 << 4)    
00044 };
00045 
00046 void logger_init ();
00047 
00048 void logger_setup (int priority, const char *file, int line,
00049            const char *function);
00050 
00051 void logger_emit (const char *format, ...);
00052 
00053 #ifdef ENABLE_VERBOSE_MODE
00054 
00055 /* Verbose mode */
00056 
00058 #define HAL_TRACE(expr)   do {logger_setup(HAL_LOGPRI_TRACE,   __FILE__, __LINE__, __FUNCTION__); logger_emit expr; } while(0)
00059 
00061 #define HAL_DEBUG(expr)   do {logger_setup(HAL_LOGPRI_DEBUG,   __FILE__, __LINE__, __FUNCTION__); logger_emit expr; } while(0)
00062 
00064 #define HAL_INFO(expr)    do {logger_setup(HAL_LOGPRI_INFO,    __FILE__, __LINE__, __FUNCTION__); logger_emit expr; } while(0)
00065 
00067 #define HAL_WARNING(expr) do {logger_setup(HAL_LOGPRI_WARNING, __FILE__, __LINE__, __FUNCTION__); logger_emit expr; } while(0)
00068 
00070 #define HAL_ERROR(expr)   do {logger_setup(HAL_LOGPRI_ERROR,   __FILE__, __LINE__, __FUNCTION__); logger_emit expr; } while(0)
00071 
00073 #define DIE(expr) do {printf("*** [DIE] %s:%s():%d : ", __FILE__, __FUNCTION__, __LINE__); printf expr; printf("\n"); exit(1); } while(0)
00074 
00075 #else
00076 
00077 /* If verbose mode is not requested only handle warning and error */
00078 
00079 #define HAL_TRACE(expr) do {;} while(0)
00080 #define HAL_DEBUG(expr) do {;} while(0)
00081 #define HAL_INFO(expr) do {;} while(0)
00082 
00083 #define HAL_WARNING(expr) do {logger_setup(HAL_LOGPRI_WARNING, __FILE__, __LINE__, __FUNCTION__); logger_emit expr; } while(0)
00084 
00085 #define HAL_ERROR(expr)   do {logger_setup(HAL_LOGPRI_ERROR,   __FILE__, __LINE__, __FUNCTION__); logger_emit expr; } while(0)
00086 
00087 #define DIE(expr) do {printf("*** [DIE] %s:%s():%d : ", __FILE__, __FUNCTION__, __LINE__); printf expr; printf("\n"); exit(1); } while(0)
00088 
00089 
00090 #endif              /* ENABLE_VERBOSE_MODE */
00091 
00094 #endif              /* LOGGER_H */

Generated on Sat Apr 24 19:57:45 2004 for HAL by doxygen 1.3.6-20040222