hw/yagl_log.h: Add Windows specific logging macro
authorIgor Mitsyanko <i.mitsyanko@samsung.com>
Thu, 15 Nov 2012 13:37:53 +0000 (17:37 +0400)
committerEvgeny Voevodin <e.voevodin@samsung.com>
Mon, 26 Nov 2012 09:25:36 +0000 (13:25 +0400)
Signed-off-by: Igor Mitsyanko <i.mitsyanko@samsung.com>
hw/yagl_log.h

index 34828d9..b8cfa50 100644 (file)
@@ -1,6 +1,10 @@
 #ifndef _QEMU_YAGL_LOG_H
 #define _QEMU_YAGL_LOG_H
 
+#ifdef _WIN32
+#include <windows.h>
+#endif
+
 #include "yagl_types.h"
 
 //#define YAGL_LOG_DISABLE
@@ -145,6 +149,22 @@ bool yagl_log_is_enabled_for_func_tracing(void);
             yagl_log_func_exit_split(_yagl_log_current_pid, _yagl_log_current_tid, _yagl_log_current_func, __LINE__, #ret_type, ret); \
         } \
     } while(0)
+
+#ifdef _WIN32
+#define YAGL_LOG_EVENT_WIN(log_level, pid, tid, facility, format, ...) \
+    do \
+    { \
+        if ( yagl_log_is_enabled_for_level(yagl_log_level_##log_level) && \
+             yagl_log_is_enabled_for_facility(facility) ) \
+        { \
+            LPVOID err_msg; \
+            FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, \
+                          NULL, GetLastError(), 0, (LPTSTR)&err_msg, 0 , NULL); \
+            yagl_log_event(yagl_log_level_##log_level, pid, tid, facility, __LINE__, format,##__VA_ARGS__); \
+            LocalFree(err_msg); \
+        } \
+    } while(0)
+#endif
 #else
 #define YAGL_LOG_EVENT(log_level, pid, tid, facility, format, ...)
 #define YAGL_LOG_FUNC_SET(pid, tid, func)
@@ -155,6 +175,7 @@ bool yagl_log_is_enabled_for_func_tracing(void);
 #define YAGL_LOG_FUNC_ENTER_SPLIT(pid, tid, func, num_args, ...)
 #define YAGL_LOG_FUNC_EXIT(format, ...)
 #define YAGL_LOG_FUNC_EXIT_SPLIT(ret_type, ret)
+#define YAGL_LOG_EVENT_WIN()
 #endif
 
 #define YAGL_LOG_FUNC_ENTER_SPLIT0(pid, tid, func) YAGL_LOG_FUNC_ENTER_SPLIT(pid, tid, func, 0)
@@ -219,6 +240,7 @@ bool yagl_log_is_enabled_for_func_tracing(void);
 #define YAGL_LOG_INFO(format, ...) YAGL_LOG_EVENT(info, _yagl_log_current_pid, _yagl_log_current_tid, _yagl_log_current_func, format,##__VA_ARGS__)
 #define YAGL_LOG_WARN(format, ...) YAGL_LOG_EVENT(warn, _yagl_log_current_pid, _yagl_log_current_tid, _yagl_log_current_func, format,##__VA_ARGS__)
 #define YAGL_LOG_ERROR(format, ...) YAGL_LOG_EVENT(error, _yagl_log_current_pid, _yagl_log_current_tid, _yagl_log_current_func, format,##__VA_ARGS__)
+#define YAGL_LOG_ERROR_WIN()        YAGL_LOG_EVENT_WIN(error, _yagl_log_current_pid, _yagl_log_current_tid, _yagl_log_current_func, "OS reports: ",)
 #define YAGL_LOG_CRITICAL(format, ...) \
     yagl_log_event(yagl_log_level_error, 0, 0, __FUNCTION__, __LINE__, format,##__VA_ARGS__)