open-vm-tools 10.3.10
log.h
Go to the documentation of this file.
1/*********************************************************
2 * Copyright (C) 2011-2016 VMware, Inc. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as published
6 * by the Free Software Foundation version 2.1 and no later version.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 * or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
11 * License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
16 *
17 *********************************************************/
18
19#ifndef _VMTOOLS_LOG_H_
20#define _VMTOOLS_LOG_H_
21
136#if !defined(G_LOG_DOMAIN)
137# error "G_LOG_DOMAIN must be defined."
138#endif
139
140#include <glib.h>
141
142#if defined(__GNUC__)
143# define FUNC __func__
144#else
145# define FUNC __FUNCTION__
146#endif
147
148/*
149 *******************************************************************************
150 * g_info -- */
160#if !defined(g_info)
161# define g_info(fmt, ...) g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, fmt, ## __VA_ARGS__)
162#endif
163
165#ifdef VMX86_DEBUG
166#define VMTOOLS_LOGGING_LEVEL_DEFAULT "info"
167#else
168#define VMTOOLS_LOGGING_LEVEL_DEFAULT "message"
169#endif
170
171
172/*
173 * As of version 2.46, glib thinks the Windows compiler where
174 * _MSC_VER >= 1400 can handle G_HAVE_ISO_VARARGS. This makes our
175 * magic macros wrapping their macros fail in the simplest case,
176 * where only the fmt arg is present (eg vm_debug("test").
177 * vm_debug("test %d", 123) works fine.
178 *
179 * Work around this by making g_debug() et all be inline functions,
180 * which is how it works if G_HAVE_ISO_VARARGS isn't set.
181 *
182 * Though experimentation we found that this also works:
183 *
184 * #define LOGHELPER(...) ,##_VA_ARGS__
185 * #define LOG(fmt, ...) g_debug_macro(__FUNCTION__, ": " fmt, LOGHELPER(__VA_ARGS__))
186 *
187 * but since its disgusting and even more magical, the inline variant was chosen
188 * instead.
189 */
190
191#if defined(_WIN32) && GLIB_CHECK_VERSION(2, 46, 0)
192static inline void
193g_critical_inline(const gchar *fmt,
194 ...)
195{
196 va_list args;
197 va_start(args, fmt);
198 g_logv(G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, fmt, args);
199 va_end(args);
200}
201
202/*
203 *******************************************************************************
204 * vm_{critical,debug,error,info,message,warning} -- */
215#define vm_critical(fmt, ...) g_critical_inline("%s: " fmt, FUNC, ## __VA_ARGS__)
216
217static inline void
218g_debug_inline(const gchar *fmt,
219 ...)
220{
221 va_list args;
222 va_start(args, fmt);
223 g_logv(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, fmt, args);
224 va_end(args);
225}
226
228#define vm_debug(fmt, ...) g_debug_inline("%s: " fmt, FUNC, ## __VA_ARGS__)
229
230static inline void
231g_error_inline(const gchar *fmt,
232 ...)
233{
234 va_list args;
235 va_start(args, fmt);
236 g_logv(G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, fmt, args);
237 va_end(args);
238}
239
241#define vm_error(fmt, ...) g_error_inline("%s: " fmt, FUNC, ## __VA_ARGS__)
242
243
244static inline void
245g_info_inline(const gchar *fmt,
246 ...)
247{
248 va_list args;
249 va_start(args, fmt);
250 g_logv(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, fmt, args);
251 va_end(args);
252}
253
255#define vm_info(fmt, ...) g_info_inline("%s: " fmt, FUNC, ## __VA_ARGS__)
256
257static inline void
258g_message_inline(const gchar *fmt,
259 ...)
260{
261 va_list args;
262 va_start(args, fmt);
263 g_logv(G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, fmt, args);
264 va_end(args);
265}
266
268#define vm_message(fmt, ...) g_message_inline("%s: " fmt, FUNC, ## __VA_ARGS__)
269
270static inline void
271g_warning_inline(const gchar *fmt,
272 ...)
273{
274 va_list args;
275 va_start(args, fmt);
276 g_logv(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, fmt, args);
277 va_end(args);
278}
279
281#define vm_warning(fmt, ...) g_warning_inline("%s: " fmt, FUNC, ## __VA_ARGS__)
282
283#else // ! (windows & glib >= 2.46)
284
285/*
286 *******************************************************************************
287 * vm_{critical,debug,error,info,message,warning} -- */
298#define vm_critical(fmt, ...) g_critical("%s: " fmt, FUNC, ## __VA_ARGS__)
299
301#define vm_debug(fmt, ...) g_debug("%s: " fmt, FUNC, ## __VA_ARGS__)
302
304#define vm_error(fmt, ...) g_error("%s: " fmt, FUNC, ## __VA_ARGS__)
305
307#define vm_info(fmt, ...) g_info("%s: " fmt, FUNC, ## __VA_ARGS__)
308
310#define vm_message(fmt, ...) g_message("%s: " fmt, FUNC, ## __VA_ARGS__)
311
313#define vm_warning(fmt, ...) g_warning("%s: " fmt, FUNC, ## __VA_ARGS__)
314#endif // ! (windows & glib >= 2.46)
315
316
317G_BEGIN_DECLS
318
319void
320VMTools_ConfigLogToStdio(const gchar *domain);
321
322void
323VMTools_ConfigLogging(const gchar *defaultDomain,
324 GKeyFile *cfg,
325 gboolean force,
326 gboolean reset);
327
328G_END_DECLS
329
332#endif /* _VMTOOLS_LOG_H_ */
333
G_BEGIN_DECLS void VMTools_ConfigLogToStdio(const gchar *domain)
Definition: vmtoolsLog.c:1026
void VMTools_ConfigLogging(const gchar *defaultDomain, GKeyFile *cfg, gboolean force, gboolean reset)
Definition: vmtoolsLog.c:1076