Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

trace.h

Go to the documentation of this file.
00001 /*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*-
00002  *
00003  * librsync -- generate and apply network deltas
00004  * $Id: trace.h,v 1.2 2003/11/03 16:52:30 eilers Exp $
00005  * 
00006  * Copyright (C) 2000, 2001 by Martin Pool <mbp@samba.org>
00007  * 
00008  * This program is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU Lesser General Public License as published by
00010  * the Free Software Foundation; either version 2.1 of the License, or
00011  * (at your option) any later version.
00012  * 
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU Lesser General Public License for more details.
00017  * 
00018  * You should have received a copy of the GNU Lesser General Public License
00019  * along with this program; if not, write to the Free Software
00020  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00021  */
00022 
00023 
00024 /*
00025  * TODO: A function like perror that includes strerror output.  Apache
00026  * does this by adding flags as well as the severity level which say
00027  * whether such information should be included.
00028  */
00029 
00030 
00031 /*
00032  * trace may be turned off.
00033  *
00034  * error is always on, but you can return and continue in some way
00035  *
00036  * fatal terminates the whole process
00037  */
00038 
00039 #if defined(HAVE_VARARG_MACROS) && defined(__GNUC__)
00040 /*
00041  * TODO: Don't assume this is a gcc thing; rather test in autoconf for
00042  * support for __FUNCTION__.  One simple way might just be to try compiling 
00043  * the definition of one of these functions!
00044  *
00045  * TODO: Also look for the C9X predefined identifier `_function', or
00046  * whatever it's called.
00047  */
00048 
00049 void rs_log0(int level, char const *fn, char const *fmt, ...)
00050     __attribute__ ((format(printf, 3, 4)));
00051 
00052 #ifdef DO_RS_TRACE
00053 #  define rs_trace(fmt, arg...)                            \
00054     do { rs_log0(RS_LOG_DEBUG, __FUNCTION__, fmt , ##arg);  \
00055     } while (0)
00056 #else
00057 #  define rs_trace(fmt, arg...)
00058 #endif  /* !DO_RS_TRACE */
00059 
00060 #define rs_log(l, s, str...) do {              \
00061      rs_log0((l), __FUNCTION__, (s) , ##str);  \
00062      } while (0)
00063 
00064 
00065 #define rs_error(s, str...) do {                       \
00066      rs_log0(RS_LOG_ERR,  __FUNCTION__, (s) , ##str);  \
00067      } while (0)
00068 
00069 
00070 #define rs_fatal(s, str...) do {               \
00071      rs_log0(RS_LOG_CRIT,  __FUNCTION__,       \
00072               (s) , ##str);                    \
00073      abort();                                  \
00074      } while (0)
00075 
00076 
00077 #else /************************* ! __GNUC__ */
00078 #  define rs_trace rs_trace0
00079 #  define rs_fatal rs_fatal0
00080 #  define rs_error rs_error0
00081 #  define rs_log   rs_log0_nofn
00082 #endif                          /* ! __GNUC__ */
00083 
00084 void rs_trace0(char const *s, ...);
00085 void rs_fatal0(char const *s, ...);
00086 void rs_error0(char const *s, ...);
00087 void rs_log0(int level, char const *fn, char const *fmt, ...);
00088 void rs_log0_nofn(int level, char const *fmt, ...);
00089 
00090 enum {
00091     RS_LOG_PRIMASK       = 7,   
00094     RS_LOG_NONAME        = 8    
00096 };
00097 
00098 
00106 extern int rs_trace_level;
00107 
00108 #ifdef DO_RS_TRACE
00109 #  define rs_trace_enabled() ((rs_trace_level & RS_LOG_PRIMASK) >= RS_LOG_DEBUG)
00110 #else
00111 #  define rs_trace_enabled() 0
00112 #endif

Generated on Sat Nov 5 16:18:35 2005 for OPIE by  doxygen 1.4.2