]> git.proxmox.com Git - libgit2.git/blob - src/trace.h
New upstream version 1.4.3+dfsg.1
[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 "common.h"
11
12 #include <git2/trace.h>
13 #include "str.h"
14
15 struct git_trace_data {
16 git_trace_level_t level;
17 git_trace_cb 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 va_list ap)
26 {
27 git_trace_cb callback = git_trace__data.callback;
28 git_str message = GIT_STR_INIT;
29
30 git_str_vprintf(&message, fmt, ap);
31
32 callback(level, git_str_cstr(&message));
33
34 git_str_dispose(&message);
35 }
36
37 #define git_trace_level() (git_trace__data.level)
38
39 GIT_INLINE(void) git_trace(git_trace_level_t level, const char *fmt, ...)
40 {
41 if (git_trace__data.level >= level &&
42 git_trace__data.callback != NULL) {
43 va_list ap;
44
45 va_start(ap, fmt);
46 git_trace__write_fmt(level, fmt, ap);
47 va_end(ap);
48 }
49 }
50
51 #endif