librsync
2.3.2
src
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
35
#include <inttypes.h>
36
/* Printf format patters for standard librsync types. */
37
#define FMT_LONG "%"
PRIdMAX
38
#define FMT_WEAKSUM "%08"
PRIx32
39
/* Old MSVC compilers don't support "%zu" and have "%Iu" instead. */
40
#ifdef HAVE_PRINTF_Z
41
# define FMT_SIZE "%zu"
42
#else
43
# define FMT_SIZE "%Iu"
44
#endif
45
46
/* Some old compilers don't support __func_ and have __FUNCTION__ instead. */
47
#ifndef HAVE___FUNC__
48
# ifdef HAVE___FUNCTION__
49
# define __func__ __FUNCTION__
50
# else
51
# define __func__ ""
52
# endif
53
#endif
54
55
/* Non-GNUC compatible compilers don't support __attribute__(). */
56
#ifndef __GNUC__
57
# define __attribute__(x)
58
#endif
59
60
void
rs_log0(
int
level,
char
const
*fn,
char
const
*fmt, ...)
61
__attribute__((format(printf, 3, 4)));
62
63
/** \def rs_trace_enabled()
64
* Call this before putting too much effort into generating trace messages. */
65
#ifdef DO_RS_TRACE
66
# define rs_trace_enabled() ((rs_trace_level & RS_LOG_PRIMASK) >= RS_LOG_DEBUG)
67
# define rs_trace(...) rs_log0(RS_LOG_DEBUG, __func__, __VA_ARGS__)
68
#else
69
# define rs_trace_enabled() 0
70
# define rs_trace(...)
71
#endif
/* !DO_RS_TRACE */
72
73
#define rs_log(l, ...) rs_log0((l), __func__, __VA_ARGS__)
74
#define rs_warn(...) rs_log0(RS_LOG_WARNING, __func__, __VA_ARGS__)
75
#define rs_error(...) rs_log0(RS_LOG_ERR, __func__, __VA_ARGS__)
76
#define rs_fatal(...) do { \
77
rs_log0(RS_LOG_CRIT, __func__, __VA_ARGS__); \
78
abort(); \
79
} while (0)
80
81
enum
{
82
RS_LOG_PRIMASK
= 7,
/**< Mask to extract priority part. \internal */
83
RS_LOG_NONAME
= 8
/**< \b Don't show function name in message. */
84
};
85
86
extern
int
rs_trace_level;
RS_LOG_PRIMASK
@ RS_LOG_PRIMASK
Mask to extract priority part.
Definition:
trace.h:82
RS_LOG_NONAME
@ RS_LOG_NONAME
Don't show function name in message.
Definition:
trace.h:83
Generated on Sat Apr 10 2021 00:00:00 for librsync by
1.9.1