]> git.proxmox.com Git - libgit2.git/blob - src/trace.h
Merge pull request #1558 from bmorganpa/ssh_transport
[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 <stdarg.h>
11
12 #include <git2/trace.h>
13 #include "buffer.h"
14
15 #ifdef GIT_TRACE
16
17 struct git_trace_data {
18 git_trace_level_t level;
19 git_trace_callback callback;
20 };
21
22 extern struct git_trace_data git_trace__data;
23
24 GIT_INLINE(void) git_trace__write_fmt(
25 git_trace_level_t level,
26 const char *fmt, ...)
27 {
28 git_trace_callback callback = git_trace__data.callback;
29 git_buf message = GIT_BUF_INIT;
30 va_list ap;
31
32 va_start(ap, fmt);
33 git_buf_vprintf(&message, fmt, ap);
34 va_end(ap);
35
36 callback(level, git_buf_cstr(&message));
37
38 git_buf_free(&message);
39 }
40
41 #define git_trace_level() (git_trace__data.level)
42 #define git_trace(l, ...) { \
43 if (git_trace__data.level >= l && \
44 git_trace__data.callback != NULL) { \
45 git_trace__write_fmt(l, __VA_ARGS__); \
46 } \
47 }
48
49 #else
50
51 #define git_trace_level() ((void)0)
52 #define git_trace(lvl, ...) ((void)0)
53
54 #endif
55
56 #endif