aboutsummaryrefslogtreecommitdiffstats
path: root/plugin/icedteanp/IcedTeaPluginUtils.h
diff options
context:
space:
mode:
authorJiri Vanek <[email protected]>2013-10-25 12:19:15 +0200
committerJiri Vanek <[email protected]>2013-10-25 12:19:15 +0200
commit7a81d6c45f69526857236d9d9d985602096caca6 (patch)
tree2abd5f549a322d82e36a75b0576249ddc45ef037 /plugin/icedteanp/IcedTeaPluginUtils.h
parent2783ad50d2746de5a8aaf302f11e24b11088eaef (diff)
Plugin debug can now be controlled from itw_settings, in same way java side. For now ICEDTEAPLUGIN_DEBUG on the debug in same way as deployment.log itw-settings property. Individual logging streams are controlled by deployment.log.{headers,file,stdstreams,system} System and file are not yet fully done (same as java side in this moment). Streams are true, all others false by default.
* plugin/icedteanp/IcedTeaNPPlugin.cc: initialized variables new bool variables (debug_initiated), (plugin_debug_headers), (plugin_debug_to_file), (plugin_debug_to_system) as false and (plugin_debug_to_streams) as true. * plugin/icedteanp/IcedTeaNPPlugin.h: above variables declared as extern * plugin/icedteanp/IcedTeaParseProperties.cc: initialization of (default_file_ITW_deploy_props_name) and (custom_jre_key) moved here from IcedTeaNPPlugin.h. New method (read_bool_property) and its more concrete shortcuts (is_debug_on) (is_debug_header_on) (is_logging_to_file) (is_logging_to_stds) (is_logging_to_system) implemented to access properties. * plugin/icedteanp/IcedTeaParseProperties.h: above methods declared. * plugin/icedteanp/IcedTeaPluginUtils.h: (PLUGIN_{ERROR,DEBUG}) methods adapted headers/debug/streams logic as described in title. Headers made more informative (like java side) * tests/cpp-unit-tests/IcedTeaPluginUtilsTest.cc: TEST(PLUGIN_DEBUG_ERROR_PROFILING_debug_on) extended to TEST(PLUGIN_DEBUG_ERROR_PROFILING_debug_on_headers_off).TEST(PLUGIN_DEBUG_ERROR_PROFILING_debug_off) extended to TEST(PLUGIN_DEBUG_ERROR_PROFILING_debug_off_headers_off), and new testsTEST(PLUGIN_DEBUG_ERROR_PROFILING_debug_on_headers_on) TEST(PLUGIN_DEBUG_ERROR_PROFILING_debug_off_headers_on) (100x slower then without headers)
Diffstat (limited to 'plugin/icedteanp/IcedTeaPluginUtils.h')
-rw-r--r--plugin/icedteanp/IcedTeaPluginUtils.h68
1 files changed, 54 insertions, 14 deletions
diff --git a/plugin/icedteanp/IcedTeaPluginUtils.h b/plugin/icedteanp/IcedTeaPluginUtils.h
index d5b1ef6..7d2abdb 100644
--- a/plugin/icedteanp/IcedTeaPluginUtils.h
+++ b/plugin/icedteanp/IcedTeaPluginUtils.h
@@ -45,6 +45,8 @@ exception statement from your version. */
#include <pthread.h>
#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
#include <cstring>
#include <iostream>
@@ -59,25 +61,63 @@ exception statement from your version. */
#include <glib.h>
#include <npruntime.h>
-#define PLUGIN_DEBUG(...) \
- do \
- { \
- if (plugin_debug) \
- { \
- fprintf (stdout, "ITNPP Thread# %ld: ", pthread_self()); \
- fprintf (stdout, __VA_ARGS__); \
- } \
+#include "IcedTeaParseProperties.h"
+
+// debugging macro.
+#define initialize_debug() \
+ do \
+ { \
+ if (!debug_initiated) { \
+ debug_initiated = true; \
+ plugin_debug = getenv ("ICEDTEAPLUGIN_DEBUG") != NULL || is_debug_on(); \
+ plugin_debug_headers = is_debug_header_on(); \
+ plugin_debug_to_file = is_logging_to_file(); \
+ plugin_debug_to_streams = is_logging_to_stds(); \
+ plugin_debug_to_system = is_logging_to_system(); \
+ } \
+ } while (0)
+
+
+#define PLUGIN_DEBUG(...) \
+ do \
+ { \
+ initialize_debug(); \
+ if (plugin_debug) { \
+ if (plugin_debug_to_streams) { \
+ if (plugin_debug_headers) { \
+ char s[1000]; \
+ time_t t = time(NULL); \
+ struct tm * p = localtime(&t); \
+ strftime(s, 1000, "%a %b %d %H:%M:%S %Z %Y", p); \
+ const char *userNameforDebug = (getenv("USERNAME") == NULL) ? "unknown user" : getenv("USERNAME"); \
+ fprintf (stdout, "[%s][ITW-C-PLUGIN][MESSAGE_DEBUG][%s][%s:%d] ITNPP Thread# %ld: ", \
+ userNameforDebug, s, __FILE__, __LINE__, pthread_self()); \
+ } \
+ fprintf (stdout, __VA_ARGS__); \
+ } \
+ } \
} while (0)
-
- // Error reporting macros.
+
+// Error reporting macro.
#define PLUGIN_ERROR(...) \
-do \
+ do \
{ \
- fprintf (stderr, "%s:%d: thread %p: Error: %s\n", \
- __FILE__, __LINE__, \
- g_thread_self (), __VA_ARGS__); \
+ initialize_debug(); \
+ if (plugin_debug_to_streams) { \
+ if (plugin_debug_headers) { \
+ char s[1000]; \
+ time_t t = time(NULL); \
+ struct tm * p = localtime(&t); \
+ strftime(s, 1000, "%A, %B %d %Y", p); \
+ const char *userNameforDebug = (getenv("USERNAME") == NULL) ? "unknown user" : getenv("USERNAME"); \
+ fprintf (stderr, "[%s][ITW-C-PLUGIN][ERROR_ALL][%s][%s:%d] thread %p: ", \
+ userNameforDebug, s, __FILE__, __LINE__, g_thread_self ()); \
+ } \
+ fprintf (stderr, __VA_ARGS__); \
+ } \
} while (0)
+
#define CHECK_JAVA_RESULT(result_data) \
{ \
if (((JavaResultData*) result_data)->error_occurred) \