]> git.proxmox.com Git - libgit2.git/blob - src/trace.h
Add payloads, bitmaps to trace API
[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 void *callback_payload;
19 };
20
21 extern struct git_trace_data git_trace__data;
22
23 GIT_INLINE(void) git_trace__write_fmt(
24 git_trace_level_t level,
25 void *message_payload,
26 const char *fmt,
27 ...)
28 {
29 git_trace_callback callback = git_trace__data.callback;
30 git_buf message = GIT_BUF_INIT;
31 va_list ap;
32
33 va_start(ap, fmt);
34 git_buf_vprintf(&message, fmt, ap);
35 va_end(ap);
36
37 callback(
38 level, git_trace__data.callback_payload, message_payload,
39 git_buf_cstr(&message));
40
41 git_buf_free(&message);
42 }
43
44 #define git_trace_level() (git_trace__data.level)
45 #define git_trace(l, p, ...) do { \
46 if ((git_trace__data.level & (l)) != 0 && git_trace__data.callback) { \
47 git_trace__write_fmt((l), (p), __VA_ARGS__); \
48 } } while (0)
49
50 #else
51
52 #define git_trace_level() ((void)0)
53 #define git_trace(lvl, ...) ((void)0)
54
55 #endif
56
57 #endif