]> git.proxmox.com Git - libgit2.git/blob - src/trace.h
libgit2 v0.21.0
[libgit2.git] / src / trace.h
1 /*
2 * Copyright (C) the libgit2 contributors. All rights reserved.
3 *
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
6 */
7 #ifndef INCLUDE_trace_h__
8 #define INCLUDE_trace_h__
9
10 #include <git2/trace.h>
11 #include "buffer.h"
12
13 #ifdef GIT_TRACE
14
15 struct git_trace_data {
16 git_trace_level_t level;
17 git_trace_callback callback;
18 };
19
20 extern struct git_trace_data git_trace__data;
21
22 GIT_INLINE(void) git_trace__write_fmt(
23 git_trace_level_t level,
24 const char *fmt, ...)
25 {
26 git_trace_callback callback = git_trace__data.callback;
27 git_buf message = GIT_BUF_INIT;
28 va_list ap;
29
30 va_start(ap, fmt);
31 git_buf_vprintf(&message, fmt, ap);
32 va_end(ap);
33
34 callback(level, git_buf_cstr(&message));
35
36 git_buf_free(&message);
37 }
38
39 #define git_trace_level() (git_trace__data.level)
40 #define git_trace(l, ...) { \
41 if (git_trace__data.level >= l && \
42 git_trace__data.callback != NULL) { \
43 git_trace__write_fmt(l, __VA_ARGS__); \
44 } \
45 }
46
47 #else
48
49 #define git_trace_level() ((void)0)
50 #define git_trace(lvl, ...) ((void)0)
51
52 #endif
53
54 #endif