aboutsummaryrefslogtreecommitdiffstats
path: root/plugin
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
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')
-rw-r--r--plugin/icedteanp/IcedTeaNPPlugin.cc5
-rw-r--r--plugin/icedteanp/IcedTeaNPPlugin.h7
-rw-r--r--plugin/icedteanp/IcedTeaParseProperties.cc36
-rw-r--r--plugin/icedteanp/IcedTeaParseProperties.h9
-rw-r--r--plugin/icedteanp/IcedTeaPluginUtils.h68
5 files changed, 106 insertions, 19 deletions
diff --git a/plugin/icedteanp/IcedTeaNPPlugin.cc b/plugin/icedteanp/IcedTeaNPPlugin.cc
index 7a5428f..c7318ef 100644
--- a/plugin/icedteanp/IcedTeaNPPlugin.cc
+++ b/plugin/icedteanp/IcedTeaNPPlugin.cc
@@ -213,7 +213,12 @@ static gint instance_counter = 1;
static GPid appletviewer_pid = -1;
static guint appletviewer_watch_id = -1;
+bool debug_initiated = false;
int plugin_debug = getenv ("ICEDTEAPLUGIN_DEBUG") != NULL;
+bool plugin_debug_headers = false;
+bool plugin_debug_to_file = false ;
+bool plugin_debug_to_streams = true ;
+bool plugin_debug_to_system = false;
int plugin_debug_suspend = (getenv("ICEDTEAPLUGIN_DEBUG") != NULL) &&
(strcmp(getenv("ICEDTEAPLUGIN_DEBUG"), "suspend") == 0);
diff --git a/plugin/icedteanp/IcedTeaNPPlugin.h b/plugin/icedteanp/IcedTeaNPPlugin.h
index db6c421..cc1f9f5 100644
--- a/plugin/icedteanp/IcedTeaNPPlugin.h
+++ b/plugin/icedteanp/IcedTeaNPPlugin.h
@@ -115,8 +115,13 @@ extern pthread_t itnp_plugin_thread_id;
/* Mutex around plugin async call queue ops */
extern pthread_mutex_t pluginAsyncCallMutex;
-// debug switch
+// debug switches
+extern bool debug_initiated;
extern int plugin_debug;
+extern bool plugin_debug_headers;
+extern bool plugin_debug_to_file;
+extern bool plugin_debug_to_streams;
+extern bool plugin_debug_to_system;
// Browser function table.
extern NPNetscapeFuncs browser_functions;
diff --git a/plugin/icedteanp/IcedTeaParseProperties.cc b/plugin/icedteanp/IcedTeaParseProperties.cc
index e9d9b63..4c19a96 100644
--- a/plugin/icedteanp/IcedTeaParseProperties.cc
+++ b/plugin/icedteanp/IcedTeaParseProperties.cc
@@ -50,7 +50,7 @@ exception statement from your version. */
#include "IcedTeaPluginUtils.h"
-
+#include "IcedTeaNPPlugin.h"
#include "IcedTeaParseProperties.h"
/*
The public api is nearly impossible to test due to "hardcoded paths"
@@ -75,7 +75,8 @@ bool read_deploy_property_value(string user_file, string system_file, bool use
//for passing two dummy files
bool find_custom_jre(string user_file, string main_file,string& dest);
//end of non-public IcedTeaParseProperties api
-
+const std::string default_file_ITW_deploy_props_name = "deployment.properties";
+const std::string custom_jre_key = "deployment.jre.dir";
void remove_all_spaces(string& str)
{
@@ -147,6 +148,37 @@ bool find_system_config_file(string& dest){
}
return find_system_config_file(main_properties_file(), jdest, found, default_java_properties_file(), dest);
}
+
+
+bool read_bool_property(string key, bool defaultValue){
+ string value;
+ if (!read_deploy_property_value(key, value)) {
+ return defaultValue;
+ }
+ if (value == "true") {
+ return true;
+ } else {
+ return false;
+ }
+}
+
+bool is_debug_on(){
+ return read_bool_property("deployment.log",false);
+}
+bool is_debug_header_on(){
+ return read_bool_property("deployment.log.headers",false);
+}
+bool is_logging_to_file(){
+ return read_bool_property("deployment.log.file",false);
+}
+bool is_logging_to_stds(){
+ return read_bool_property("deployment.log.stdstreams",true);
+}
+bool is_logging_to_system(){
+ return read_bool_property("deployment.log.system",true);
+}
+
+
//abstraction for testing purposes
bool find_system_config_file(string main_file, string custom_jre_file, bool usecustom_jre, string default_java_file, string& dest){
if (IcedTeaPluginUtilities::file_exists(main_file)) {
diff --git a/plugin/icedteanp/IcedTeaParseProperties.h b/plugin/icedteanp/IcedTeaParseProperties.h
index 7fa054d..4370e3c 100644
--- a/plugin/icedteanp/IcedTeaParseProperties.h
+++ b/plugin/icedteanp/IcedTeaParseProperties.h
@@ -47,7 +47,12 @@ std::string user_properties_file();
bool find_system_config_file(std::string& dest);
bool find_custom_jre(std::string& dest);
bool read_deploy_property_value(std::string property, std::string& dest);
+bool is_debug_on();
+bool is_debug_header_on();
+bool is_logging_to_file();
+bool is_logging_to_stds();
+bool is_logging_to_system();
//half public api
-const std::string default_file_ITW_deploy_props_name = "deployment.properties";
-const std::string custom_jre_key = "deployment.jre.dir";
+extern const std::string default_file_ITW_deploy_props_name;
+extern const std::string custom_jre_key;
//end of public api
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) \