89.1.1
by Mikkel Kamstrup Erlandsen
Add a Unity.Trace API for logging that will be compiled out unless ENABLE_UNITY_TRACE_LOG is passed to the C compiler. The functions are Trace.log(fmt) and Trace.log_object(obj,fmt) |
1 |
/*
|
2 |
* Copyright (C) 2011 Canonical, Ltd.
|
|
3 |
*
|
|
4 |
* This library is free software; you can redistribute it and/or modify
|
|
5 |
* it under the terms of the GNU Lesser General Public License
|
|
6 |
* version 3.0 as published by the Free Software Foundation.
|
|
7 |
*
|
|
8 |
* This library is distributed in the hope that it will be useful,
|
|
9 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
* GNU Lesser General Public License version 3.0 for more details.
|
|
12 |
*
|
|
13 |
* You should have received a copy of the GNU Lesser General Public
|
|
14 |
* License along with this library. If not, see
|
|
15 |
* <http://www.gnu.org/licenses/>.
|
|
16 |
*
|
|
17 |
* Authored by Mikkel Kamstrup Erlandsen <mikkel.kamstrup@canonical.com>
|
|
18 |
*/
|
|
19 |
||
20 |
/*
|
|
21 |
* This file contains some special GObject-centric debugging macros that
|
|
22 |
* can be compiled completely out out of the final binary
|
|
23 |
*/
|
|
24 |
||
25 |
#include <glib.h> |
|
26 |
||
27 |
#ifndef _UNITY_TRACE_LOG_H
|
|
28 |
#define _UNITY_TRACE_LOG_H
|
|
29 |
||
30 |
G_BEGIN_DECLS
|
|
31 |
||
32 |
/*
|
|
33 |
* Make trace() a noop if ENABLE_UNITY_TRACE_LOG is not defined
|
|
34 |
*/
|
|
35 |
#ifdef ENABLE_UNITY_TRACE_LOG
|
|
36 |
||
37 |
void unity_trace_log_object_va (void *obj, const gchar *format, va_list args); |
|
38 |
void unity_trace_log_object_real (void *obj, const gchar *format, ...); |
|
39 |
||
40 |
# ifdef G_HAVE_ISO_VARARGS
|
|
89.1.6
by Mikkel Kamstrup Erlandsen
Use the default glib log domain (G_LOG_DOMAIN) for logging |
41 |
# define unity_trace_log(...) g_log (G_LOG_DOMAIN, \
|
89.1.1
by Mikkel Kamstrup Erlandsen
Add a Unity.Trace API for logging that will be compiled out unless ENABLE_UNITY_TRACE_LOG is passed to the C compiler. The functions are Trace.log(fmt) and Trace.log_object(obj,fmt) |
42 |
G_LOG_LEVEL_DEBUG, \
|
43 |
__VA_ARGS__)
|
|
44 |
# define unity_trace_log_object(object, ...) unity_trace_log_object_real (object, __VA_ARGS__)
|
|
45 |
||
46 |
# elif defined(G_HAVE_GNUC_VARARGS)
|
|
89.1.6
by Mikkel Kamstrup Erlandsen
Use the default glib log domain (G_LOG_DOMAIN) for logging |
47 |
# define unity_trace_log(format...) g_log (G_LOG_DOMAIN, \
|
89.1.1
by Mikkel Kamstrup Erlandsen
Add a Unity.Trace API for logging that will be compiled out unless ENABLE_UNITY_TRACE_LOG is passed to the C compiler. The functions are Trace.log(fmt) and Trace.log_object(obj,fmt) |
48 |
G_LOG_LEVEL_DEBUG, \
|
49 |
format)
|
|
50 |
# define unity_trace_log_object(object, format...) unity_trace_log_object_real (object, format)
|
|
51 |
# else /* no varargs macros */ |
|
52 |
static void |
|
53 |
unity_trace_log (const gchar *format, |
|
54 |
...)
|
|
55 |
{
|
|
56 |
va_list args; |
|
57 |
va_start (args, format); |
|
58 |
g_logv (TRACE_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format, args); |
|
59 |
va_end (args); |
|
60 |
}
|
|
61 |
||
62 |
static void |
|
63 |
unity_trace_log_object (void *obj, |
|
64 |
const gchar *format, |
|
65 |
...)
|
|
66 |
{
|
|
67 |
va_list args; |
|
68 |
va_start (args, format); |
|
69 |
unity_trace_log_object_va (obj, format, args); |
|
70 |
va_end (args); |
|
71 |
}
|
|
199.54.1
by Pawel Stolowski
First cut at LTTNG instrumentation. |
72 |
|
89.1.1
by Mikkel Kamstrup Erlandsen
Add a Unity.Trace API for logging that will be compiled out unless ENABLE_UNITY_TRACE_LOG is passed to the C compiler. The functions are Trace.log(fmt) and Trace.log_object(obj,fmt) |
73 |
# endif /* !__GNUC__ */ |
74 |
||
75 |
#else /* NO TRACE LOGGING OUTPUT */ |
|
76 |
||
77 |
# ifdef G_HAVE_ISO_VARARGS
|
|
78 |
# define unity_trace_log(...) G_STMT_START{ (void)0; }G_STMT_END
|
|
79 |
# define unity_trace_log_object(object, ...) G_STMT_START{ (void)0; }G_STMT_END
|
|
80 |
# elif defined(G_HAVE_GNUC_VARARGS)
|
|
81 |
# define unity_trace_log(format...) G_STMT_START{ (void)0; }G_STMT_END
|
|
82 |
# define unity_trace_log_object(object, format...) G_STMT_START{ (void)0; }G_STMT_END
|
|
83 |
# else /* no varargs macros */ |
|
84 |
||
85 |
static void unity_trace_log (const gchar *format, ...) { ; } |
|
86 |
static void unity_trace_log_object (GObject *obj, const gchar *format, ...) { ; } |
|
87 |
||
88 |
# endif /* !__GNUC__ */ |
|
89 |
||
90 |
#endif /* ENABLE_UNITY_TRACE_LOG */ |
|
91 |
||
199.54.1
by Pawel Stolowski
First cut at LTTNG instrumentation. |
92 |
#ifdef ENABLE_LTTNG
|
301.2.1
by Michal Hruby
Make tracing easy |
93 |
void unity_trace_tracepoint_va (const gchar *format, va_list args); |
94 |
||
199.54.3
by Pawel Stolowski
Made unity_trace_tracepoint support printf-style args. |
95 |
static void unity_trace_tracepoint (const gchar *format, ...) |
96 |
{
|
|
97 |
va_list args; |
|
98 |
va_start (args, format); |
|
301.2.1
by Michal Hruby
Make tracing easy |
99 |
unity_trace_tracepoint_va (format, args); |
199.54.3
by Pawel Stolowski
Made unity_trace_tracepoint support printf-style args. |
100 |
va_end (args); |
101 |
}
|
|
199.54.1
by Pawel Stolowski
First cut at LTTNG instrumentation. |
102 |
#else
|
199.54.7
by Pawel Stolowski
Use macros for unity_trace_tracepoint if LTTNG is disabled. |
103 |
# ifdef G_HAVE_ISO_VARARGS
|
104 |
# define unity_trace_tracepoint(...) G_STMT_START{ (void)0; }G_STMT_END
|
|
105 |
# elif defined(G_HAVE_GNUC_VARARGS)
|
|
106 |
# define unity_trace_tracepoint(format...) G_STMT_START{ (void)0; }G_STMT_END
|
|
107 |
# else /* no varargs macros */ |
|
199.54.3
by Pawel Stolowski
Made unity_trace_tracepoint support printf-style args. |
108 |
static void unity_trace_tracepoint (const gchar *format, ...) { ; } |
199.54.7
by Pawel Stolowski
Use macros for unity_trace_tracepoint if LTTNG is disabled. |
109 |
# endif
|
110 |
||
199.54.1
by Pawel Stolowski
First cut at LTTNG instrumentation. |
111 |
#endif /* ENABLE_LTTNG */ |
112 |
||
113 |
||
89.1.1
by Mikkel Kamstrup Erlandsen
Add a Unity.Trace API for logging that will be compiled out unless ENABLE_UNITY_TRACE_LOG is passed to the C compiler. The functions are Trace.log(fmt) and Trace.log_object(obj,fmt) |
114 |
G_END_DECLS
|
115 |
||
116 |
#endif /* _UNITY_TRACE_LOG_H */ |
|
117 |