librsync  2.3.4
trace.h
Go to the documentation of this file.
1/*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*-
2 *
3 * librsync -- generate and apply network deltas
4 *
5 * Copyright (C) 2000, 2001, 2004 by Martin Pool <mbp@sourcefrog.net>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation; either version 2.1 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22/** \file trace.h
23 * logging functions.
24 *
25 * trace may be turned off.
26 *
27 * error is always on, but you can return and continue in some way.
28 *
29 * fatal terminates the whole process.
30 *
31 * \todo A function like perror that includes strerror output. Apache does this
32 * by adding flags as well as the severity level which say whether such
33 * information should be included. */
34#ifndef TRACE_H
35# define TRACE_H
36
37# include <inttypes.h>
38# include "config.h"
39
40/* Printf format patters for standard librsync types. */
41# define FMT_LONG "%"PRIdMAX
42# define FMT_WEAKSUM "%08"PRIx32
43/* Old MSVC compilers don't support "%zu" and have "%Iu" instead. */
44# ifdef HAVE_PRINTF_Z
45# define FMT_SIZE "%zu"
46# else
47# define FMT_SIZE "%Iu"
48# endif
49
50/* Some old compilers don't support __func_ and have __FUNCTION__ instead. */
51# ifndef HAVE___FUNC__
52# ifdef HAVE___FUNCTION__
53# define __func__ __FUNCTION__
54# else
55# define __func__ ""
56# endif
57# endif
58
59/* Non-GNUC compatible compilers don't support __attribute__(). */
60# ifndef __GNUC__
61# define __attribute__(x)
62# endif
63
64void rs_log0(int level, char const *fn, char const *fmt, ...)
65 __attribute__((format(printf, 3, 4)));
66
67/** \def rs_trace_enabled()
68 * Call this before putting too much effort into generating trace messages. */
69# ifdef DO_RS_TRACE
70# define rs_trace_enabled() ((rs_trace_level & RS_LOG_PRIMASK) >= RS_LOG_DEBUG)
71# define rs_trace(...) rs_log0(RS_LOG_DEBUG, __func__, __VA_ARGS__)
72# else
73# define rs_trace_enabled() 0
74# define rs_trace(...)
75# endif /* !DO_RS_TRACE */
76
77# define rs_log(l, ...) rs_log0((l), __func__, __VA_ARGS__)
78# define rs_warn(...) rs_log0(RS_LOG_WARNING, __func__, __VA_ARGS__)
79# define rs_error(...) rs_log0(RS_LOG_ERR, __func__, __VA_ARGS__)
80# define rs_fatal(...) do { \
81 rs_log0(RS_LOG_CRIT, __func__, __VA_ARGS__); \
82 abort(); \
83} while (0)
84
85enum {
86 RS_LOG_PRIMASK = 7, /**< Mask to extract priority part. \internal */
87 RS_LOG_NONAME = 8 /**< \b Don't show function name in message. */
88};
89
90extern int rs_trace_level;
91
92#endif /* !TRACE_H */
@ RS_LOG_PRIMASK
Mask to extract priority part.
Definition: trace.h:86
@ RS_LOG_NONAME
Don't show function name in message.
Definition: trace.h:87