|
open-vm-tools 10.1.15
|
00001 /********************************************************* 00002 * Copyright (C) 2011-2016 VMware, Inc. All rights reserved. 00003 * 00004 * This program is free software; you can redistribute it and/or modify it 00005 * under the terms of the GNU Lesser General Public License as published 00006 * by the Free Software Foundation version 2.1 and no later version. 00007 * 00008 * This program is distributed in the hope that it will be useful, but 00009 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 00010 * or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public 00011 * License for more details. 00012 * 00013 * You should have received a copy of the GNU Lesser General Public License 00014 * along with this program; if not, write to the Free Software Foundation, Inc., 00015 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 00016 * 00017 *********************************************************/ 00018 00019 #ifndef _VMTOOLS_LOG_H_ 00020 #define _VMTOOLS_LOG_H_ 00021 00136 #if !defined(G_LOG_DOMAIN) 00137 # error "G_LOG_DOMAIN must be defined." 00138 #endif 00139 00140 #include <glib.h> 00141 00142 #if defined(__GNUC__) 00143 # define FUNC __func__ 00144 #else 00145 # define FUNC __FUNCTION__ 00146 #endif 00147 00148 /* 00149 ******************************************************************************* 00150 * g_info -- */ 00160 #if !defined(g_info) 00161 # define g_info(fmt, ...) g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, fmt, ## __VA_ARGS__) 00162 #endif 00163 00165 #ifdef VMX86_DEBUG 00166 #define VMTOOLS_LOGGING_LEVEL_DEFAULT "info" 00167 #else 00168 #define VMTOOLS_LOGGING_LEVEL_DEFAULT "message" 00169 #endif 00170 00171 00172 /* 00173 * As of version 2.46, glib thinks the Windows compiler where 00174 * _MSC_VER >= 1400 can handle G_HAVE_ISO_VARARGS. This makes our 00175 * magic macros wrapping their macros fail in the simplest case, 00176 * where only the fmt arg is present (eg vm_debug("test"). 00177 * vm_debug("test %d", 123) works fine. 00178 * 00179 * Work around this by making g_debug() et all be inline functions, 00180 * which is how it works if G_HAVE_ISO_VARARGS isn't set. 00181 * 00182 * Though experimentation we found that this also works: 00183 * 00184 * #define LOGHELPER(...) ,##_VA_ARGS__ 00185 * #define LOG(fmt, ...) g_debug_macro(__FUNCTION__, ": " fmt, LOGHELPER(__VA_ARGS__)) 00186 * 00187 * but since its disgusting and even more magical, the inline variant was chosen 00188 * instead. 00189 */ 00190 00191 #if defined(_WIN32) && GLIB_CHECK_VERSION(2, 46, 0) 00192 static inline void 00193 g_critical_inline(const gchar *fmt, 00194 ...) 00195 { 00196 va_list args; 00197 va_start(args, fmt); 00198 g_logv(G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, fmt, args); 00199 va_end(args); 00200 } 00201 00202 /* 00203 ******************************************************************************* 00204 * vm_{critical,debug,error,info,message,warning} -- */ 00215 #define vm_critical(fmt, ...) g_critical_inline("%s: " fmt, FUNC, ## __VA_ARGS__) 00216 00217 static inline void 00218 g_debug_inline(const gchar *fmt, 00219 ...) 00220 { 00221 va_list args; 00222 va_start(args, fmt); 00223 g_logv(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, fmt, args); 00224 va_end(args); 00225 } 00226 00228 #define vm_debug(fmt, ...) g_debug_inline("%s: " fmt, FUNC, ## __VA_ARGS__) 00229 00230 static inline void 00231 g_error_inline(const gchar *fmt, 00232 ...) 00233 { 00234 va_list args; 00235 va_start(args, fmt); 00236 g_logv(G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, fmt, args); 00237 va_end(args); 00238 } 00239 00241 #define vm_error(fmt, ...) g_error_inline("%s: " fmt, FUNC, ## __VA_ARGS__) 00242 00243 00244 static inline void 00245 g_info_inline(const gchar *fmt, 00246 ...) 00247 { 00248 va_list args; 00249 va_start(args, fmt); 00250 g_logv(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, fmt, args); 00251 va_end(args); 00252 } 00253 00255 #define vm_info(fmt, ...) g_info_inline("%s: " fmt, FUNC, ## __VA_ARGS__) 00256 00257 static inline void 00258 g_message_inline(const gchar *fmt, 00259 ...) 00260 { 00261 va_list args; 00262 va_start(args, fmt); 00263 g_logv(G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, fmt, args); 00264 va_end(args); 00265 } 00266 00268 #define vm_message(fmt, ...) g_message_inline("%s: " fmt, FUNC, ## __VA_ARGS__) 00269 00270 static inline void 00271 g_warning_inline(const gchar *fmt, 00272 ...) 00273 { 00274 va_list args; 00275 va_start(args, fmt); 00276 g_logv(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, fmt, args); 00277 va_end(args); 00278 } 00279 00281 #define vm_warning(fmt, ...) g_warning_inline("%s: " fmt, FUNC, ## __VA_ARGS__) 00282 00283 #else // ! (windows & glib >= 2.46) 00284 00285 /* 00286 ******************************************************************************* 00287 * vm_{critical,debug,error,info,message,warning} -- */ 00298 #define vm_critical(fmt, ...) g_critical("%s: " fmt, FUNC, ## __VA_ARGS__) 00299 00301 #define vm_debug(fmt, ...) g_debug("%s: " fmt, FUNC, ## __VA_ARGS__) 00302 00304 #define vm_error(fmt, ...) g_error("%s: " fmt, FUNC, ## __VA_ARGS__) 00305 00307 #define vm_info(fmt, ...) g_info("%s: " fmt, FUNC, ## __VA_ARGS__) 00308 00310 #define vm_message(fmt, ...) g_message("%s: " fmt, FUNC, ## __VA_ARGS__) 00311 00313 #define vm_warning(fmt, ...) g_warning("%s: " fmt, FUNC, ## __VA_ARGS__) 00314 #endif // ! (windows & glib >= 2.46) 00315 00316 00317 G_BEGIN_DECLS 00318 00319 void 00320 VMTools_ConfigLogToStdio(const gchar *domain); 00321 00322 void 00323 VMTools_ConfigLogging(const gchar *defaultDomain, 00324 GKeyFile *cfg, 00325 gboolean force, 00326 gboolean reset); 00327 00328 G_END_DECLS 00329 00332 #endif /* _VMTOOLS_LOG_H_ */ 00333
1.7.3