2 * Copyright (C) the libgit2 contributors. All rights reserved.
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.
7 #ifndef INCLUDE_trace_h__
8 #define INCLUDE_trace_h__
12 #include <git2/trace.h>
15 struct git_trace_data
{
16 git_trace_level_t level
;
17 git_trace_cb callback
;
20 extern struct git_trace_data git_trace__data
;
22 GIT_INLINE(void) git_trace__write_fmt(
23 git_trace_level_t level
,
27 git_trace_cb callback
= git_trace__data
.callback
;
28 git_str message
= GIT_STR_INIT
;
30 git_str_vprintf(&message
, fmt
, ap
);
32 callback(level
, git_str_cstr(&message
));
34 git_str_dispose(&message
);
37 #define git_trace_level() (git_trace__data.level)
39 GIT_INLINE(void) git_trace(git_trace_level_t level
, const char *fmt
, ...)
41 if (git_trace__data
.level
>= level
&&
42 git_trace__data
.callback
!= NULL
) {
46 git_trace__write_fmt(level
, fmt
, ap
);