$treeview $search $mathjax $extrastylesheet
librsync
2.0.2
$projectbrief
|
$projectbrief
|
$searchbox |
00001 /*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- 00002 * 00003 * librsync -- generate and apply network deltas 00004 * 00005 * Copyright (C) 2000, 2001, 2004 by Martin Pool <mbp@sourcefrog.net> 00006 * 00007 * This program is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU Lesser General Public License as published by 00009 * the Free Software Foundation; either version 2.1 of the License, or 00010 * (at your option) any later version. 00011 * 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public License 00018 * along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00020 */ 00021 00022 /** \file trace.h logging functions. 00023 * 00024 * trace may be turned off. 00025 * 00026 * error is always on, but you can return and continue in some way. 00027 * 00028 * fatal terminates the whole process. 00029 * 00030 * \todo A function like perror that includes strerror output. Apache does this 00031 * by adding flags as well as the severity level which say whether such 00032 * information should be included. */ 00033 00034 #include <inttypes.h> 00035 /* Printf format patters for standard librsync types. */ 00036 #define FMT_LONG "%"PRIdMAX 00037 #define FMT_WEAKSUM "%08"PRIx32 00038 /* Old MSVC compilers don't support "%zu" and have "%Iu" instead. */ 00039 #ifdef HAVE_PRINTF_Z 00040 # define FMT_SIZE "%zu" 00041 #else 00042 # define FMT_SIZE "%Iu" 00043 #endif 00044 00045 #if defined(__clang__) || defined(__GNUC__) 00046 /** \todo Also look for the C9X predefined identifier `_function', or whatever 00047 * it's called. */ 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 # define rs_error(s, str...) do { \ 00065 rs_log0(RS_LOG_ERR, __FUNCTION__, (s) , ##str); \ 00066 } while (0) 00067 00068 # define rs_fatal(s, str...) do { \ 00069 rs_log0(RS_LOG_CRIT, __FUNCTION__, \ 00070 (s) , ##str); \ 00071 abort(); \ 00072 } while (0) 00073 00074 #else /* !__GNUC__ */ 00075 # define rs_trace rs_trace0 00076 # define rs_fatal rs_fatal0 00077 # define rs_error rs_error0 00078 # define rs_log rs_log0_nofn 00079 #endif /* !__GNUC__ */ 00080 00081 void rs_trace0(char const *s, ...); 00082 void rs_fatal0(char const *s, ...); 00083 void rs_error0(char const *s, ...); 00084 void rs_log0(int level, char const *fn, char const *fmt, ...); 00085 void rs_log0_nofn(int level, char const *fmt, ...); 00086 00087 enum { 00088 RS_LOG_PRIMASK = 7, /**< Mask to extract priority part. \internal */ 00089 00090 RS_LOG_NONAME = 8 /**< \b Don't show function name in message. */ 00091 }; 00092 00093 /** \macro rs_trace_enabled() 00094 * 00095 * Call this before putting too much effort into generating trace messages. */ 00096 00097 extern int rs_trace_level; 00098 00099 #ifdef DO_RS_TRACE 00100 # define rs_trace_enabled() ((rs_trace_level & RS_LOG_PRIMASK) >= RS_LOG_DEBUG) 00101 #else 00102 # define rs_trace_enabled() 0 00103 #endif