summaryrefslogtreecommitdiff
path: root/src/trace.h
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@microsoft.com>2013-03-04 23:52:30 -0600
committerEdward Thomson <ethomson@edwardthomson.com>2013-03-07 12:42:33 -0600
commitb5ec5430a8cad68c1c534568a5a7047e42f75580 (patch)
tree1b2fa272f72c795cbfda61c93c18abb014be6c2b /src/trace.h
parent6a9ef012376e8a21dcfd0499ab16048eb6e954c3 (diff)
downloadlibgit2-b5ec5430a8cad68c1c534568a5a7047e42f75580.tar.gz
optional tracing
Diffstat (limited to 'src/trace.h')
-rw-r--r--src/trace.h56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/trace.h b/src/trace.h
new file mode 100644
index 000000000..f4bdff88a
--- /dev/null
+++ b/src/trace.h
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
+#ifndef INCLUDE_trace_h__
+#define INCLUDE_trace_h__
+
+#include <stdarg.h>
+
+#include <git2/trace.h>
+#include "buffer.h"
+
+#ifdef GIT_TRACE
+
+struct git_trace_data {
+ git_trace_level_t level;
+ git_trace_callback callback;
+};
+
+extern struct git_trace_data git_trace__data;
+
+GIT_INLINE(void) git_trace__write_fmt(
+ git_trace_level_t level,
+ const char *fmt, ...)
+{
+ git_trace_callback callback = git_trace__data.callback;
+ git_buf message = GIT_BUF_INIT;
+ va_list ap;
+
+ va_start(ap, fmt);
+ git_buf_vprintf(&message, fmt, ap);
+ va_end(ap);
+
+ callback(level, git_buf_cstr(&message));
+
+ git_buf_free(&message);
+}
+
+#define git_trace_level() (git_trace__data.level)
+#define git_trace(l, ...) { \
+ if (git_trace__data.level >= l && \
+ git_trace__data.callback != NULL) { \
+ git_trace__write_fmt(l, __VA_ARGS__); \
+ } \
+ }
+
+#else
+
+#define git_trace_level() ((void)0)
+#define git_trace(lvl, ...) ((void)0)
+
+#endif
+
+#endif