changeset 252:bd7fb50078b4

Add logging.h for some logging / debug functions The stuff from debug.h is now in logging.h
author Andre Heinecke <aheinecke@intevation.de>
date Tue, 01 Apr 2014 10:49:40 +0000
parents c596568fa45b
children 3595ea4fd3fb
files cinst/mozilla.c common/CMakeLists.txt common/debug.h common/logging.c common/logging.h
diffstat 5 files changed, 105 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/cinst/mozilla.c	Tue Apr 01 10:48:35 2014 +0000
+++ b/cinst/mozilla.c	Tue Apr 01 10:49:40 2014 +0000
@@ -55,7 +55,7 @@
 #include <sys/types.h>
 
 #define DEBUGPREFIX "MOZ-"
-#include "debug.h"
+#include "logging.h"
 
 #include "errorcodes.h"
 #include "portpath.h"
--- a/common/CMakeLists.txt	Tue Apr 01 10:48:35 2014 +0000
+++ b/common/CMakeLists.txt	Tue Apr 01 10:49:40 2014 +0000
@@ -2,6 +2,7 @@
    listutil.c
    strhelp.c
    portpath.c
+   logging.c
 )
 
 add_library(m13_common STATIC ${m13_common_src})
--- a/common/debug.h	Tue Apr 01 10:48:35 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,41 +0,0 @@
-#ifndef DEBUG_H
-#define DEBUG_H
-
-/**
- * @file
- * @brief Helper macros for debugging
- */
-
-/**
- * @def DEBUGOUTPUT
- * @brief If defined code for extra debugging output will be generated.
- *
- * Will be defined if current build is not an RELEASE_BUILD.
- */
-#ifndef RELEASE_BUILD
-#define DEBUGOUTPUT
-#endif
-
-/**
- * @def DEBUGPREFIX
- * @brief A string prepended to debug output.
- *
- * Should be defined to indicate which module created the output.
- */
-#ifndef DEBUGPREFIX
-#define DEBUGPREFIX ""
-#endif
-
-/**
- * @def DEBUGPRINTF(fmt, ...)
- * @brief Debug printf
- *
- * Prints to stderr if DEBUGOUTPUT is defined.
- */
-#ifdef DEBUGOUTPUT
-#define DEBUGPRINTF(fmt, ...) fprintf(stderr, DEBUGPREFIX "DEBUG: " fmt, ##__VA_ARGS__);
-#else
-#define DEBUGPRINTF(fmt, ...)
-#endif
-
-#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/common/logging.c	Tue Apr 01 10:49:40 2014 +0000
@@ -0,0 +1,40 @@
+#include "logging.h"
+#include "strhelp.h"
+
+#include <stdio.h>
+
+#ifdef WIN32
+char *
+getLastErrorMsg()
+{
+  LPWSTR bufPtr = NULL;
+  DWORD err = GetLastError();
+  char *retval = NULL;
+  FormatMessageW (FORMAT_MESSAGE_ALLOCATE_BUFFER |
+                  FORMAT_MESSAGE_FROM_SYSTEM |
+                  FORMAT_MESSAGE_IGNORE_INSERTS,
+                  NULL, err, 0, (LPWSTR) &bufPtr, 0, NULL);
+  if (!bufPtr)
+    {
+      HMODULE hWinhttp = GetModuleHandleW (L"crypt32");
+      if (hWinhttp)
+        {
+          FormatMessageW (FORMAT_MESSAGE_ALLOCATE_BUFFER |
+                          FORMAT_MESSAGE_FROM_HMODULE |
+                          FORMAT_MESSAGE_IGNORE_INSERTS,
+                          hWinhttp, HRESULT_CODE (err), 0,
+                          (LPWSTR) &bufPtr, 0, NULL);
+        }
+    }
+  if (!bufPtr) {
+    fprintf (stderr, "Error getting last error for code: %lx \n", err);
+    return NULL;
+  }
+
+  retval = wchar_to_utf8(bufPtr, wcslen(bufPtr));
+  LocalFree (bufPtr);
+
+  return retval;
+}
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/common/logging.h	Tue Apr 01 10:49:40 2014 +0000
@@ -0,0 +1,63 @@
+#ifndef COMMON_LOGGING_H
+#define COMMON_LOGGING_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * @file
+ * @brief Logging and debugging functions
+ */
+
+#ifdef WIN32
+
+#include <windows.h>
+
+/** @brief Gets the localized error message for the last error
+ * returned by GetLastError
+ *
+ * @returns utf8 error message that needs to be freed by the caller.
+ **/
+
+char *getLastErrorMsg();
+
+#endif
+
+/**
+ * @def DEBUGOUTPUT
+ * @brief If defined code for extra debugging output will be generated.
+ *
+ * Will be defined if current build is not an RELEASE_BUILD.
+ */
+#ifndef RELEASE_BUILD
+#define DEBUGOUTPUT
+#endif
+
+/**
+ * @def DEBUGPREFIX
+ * @brief A string prepended to debug output.
+ *
+ * Should be defined to indicate which module created the output.
+ */
+#ifndef DEBUGPREFIX
+#define DEBUGPREFIX ""
+#endif
+
+/**
+ * @def DEBUGPRINTF(fmt, ...)
+ * @brief Debug printf
+ *
+ * Prints to stderr if DEBUGOUTPUT is defined.
+ */
+#ifdef DEBUGOUTPUT
+#define DEBUGPRINTF(fmt, ...) fprintf(stderr, DEBUGPREFIX "DEBUG: " fmt, ##__VA_ARGS__);
+#else
+#define DEBUGPRINTF(fmt, ...)
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* COMMON_LOGGING_H */

http://wald.intevation.org/projects/trustbridge/