You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by ab...@apache.org on 2013/11/19 11:21:18 UTC

svn commit: r1543369 - in /incubator/celix/trunk: framework/private/include/ framework/private/src/ framework/public/include/ launcher/private/src/

Author: abroekhuis
Date: Tue Nov 19 10:21:18 2013
New Revision: 1543369

URL: http://svn.apache.org/r1543369
Log:
CELIX-87: Improved logging. Removed unneeded printf calls and obsolete code.

Removed:
    incubator/celix/trunk/framework/private/include/framework_log.h
Modified:
    incubator/celix/trunk/framework/private/src/bundle_archive.c
    incubator/celix/trunk/framework/private/src/celix_log.c
    incubator/celix/trunk/framework/private/src/framework.c
    incubator/celix/trunk/framework/private/src/resolver.c
    incubator/celix/trunk/framework/private/src/version.c
    incubator/celix/trunk/framework/public/include/celix_log.h
    incubator/celix/trunk/launcher/private/src/launcher.c

Modified: incubator/celix/trunk/framework/private/src/bundle_archive.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/bundle_archive.c?rev=1543369&r1=1543368&r2=1543369&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/bundle_archive.c (original)
+++ incubator/celix/trunk/framework/private/src/bundle_archive.c Tue Nov 19 10:21:18 2013
@@ -806,7 +806,6 @@ static celix_status_t bundleArchive_dele
 	celix_status_t status = CELIX_SUCCESS;
 	apr_status_t stat = apr_dir_open(&dir, directory, mp);
 	if (stat != APR_SUCCESS) {
-	    printf("ERROR opening: %d\n", stat);
 	    status = CELIX_FILE_IO_EXCEPTION;
 	} else {
 		apr_finfo_t dp;

Modified: incubator/celix/trunk/framework/private/src/celix_log.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/celix_log.c?rev=1543369&r1=1543368&r2=1543369&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/celix_log.c (original)
+++ incubator/celix/trunk/framework/private/src/celix_log.c Tue Nov 19 10:21:18 2013
@@ -29,11 +29,33 @@
 #include "celix_log.h"
 
 void framework_log(framework_log_level_t level, const char *func, const char *file, int line, char *fmsg, ...) {
-	char msg[512];
-	va_list listPointer;
-	va_start(listPointer, fmsg);
-	vsprintf(msg, fmsg, listPointer);
-	printf("%s\n\tat %s(%s:%d)\n", msg, func, file, line);
+    char *levelStr = NULL;
+    char msg[512];
+    va_list listPointer;
+    va_start(listPointer, fmsg);
+    vsprintf(msg, fmsg, listPointer);
+    switch (level) {
+        case FW_LOG_ERROR:
+            levelStr = "ERROR";
+            break;
+        case FW_LOG_WARNING:
+            levelStr = "WARNING";
+            break;
+        case FW_LOG_INFO:
+            levelStr = "INFO";
+            break;
+        case FW_LOG_DEBUG:
+        default:
+            levelStr = "DEBUG";
+            break;
+    }
+
+    if (level == FW_LOG_ERROR) {
+        printf("%s: %s\n\tat %s(%s:%d)\n", levelStr, msg, func, file, line);
+    } else {
+        printf("%s: %s\n", levelStr, msg);
+    }
+
 }
 
 void framework_logCode(framework_log_level_t level, const char *func, const char *file, int line, celix_status_t code, char *fmsg, ...) {

Modified: incubator/celix/trunk/framework/private/src/framework.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/framework.c?rev=1543369&r1=1543368&r2=1543369&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/framework.c (original)
+++ incubator/celix/trunk/framework/private/src/framework.c Tue Nov 19 10:21:18 2013
@@ -1044,7 +1044,6 @@ celix_status_t fw_refreshBundles(framewo
 
     bool locked = framework_acquireGlobalLock(framework);
     if (!locked) {
-        printf("Unable to acquire the global lock to install the bundle\n");
         framework_releaseGlobalLock(framework);
         status = CELIX_ILLEGAL_STATE;
     } else {
@@ -1960,22 +1959,21 @@ celix_status_t framework_releaseGlobalLo
 
 celix_status_t framework_waitForStop(framework_pt framework) {
 	if (apr_thread_mutex_lock(framework->mutex) != 0) {
-		fw_log(FW_LOG_ERROR,  "Error locking the framework, shutdown gate not set.");
+		fw_log(FW_LOG_ERROR, "Error locking the framework, shutdown gate not set.");
 		return CELIX_FRAMEWORK_EXCEPTION;
 	}
 	while (!framework->shutdown) {
 		apr_status_t apr_status = apr_thread_cond_wait(framework->shutdownGate, framework->mutex);
-		printf("FRAMEWORK: Gate opened\n");
 		if (apr_status != 0) {
-			fw_log(FW_LOG_ERROR,  "Error waiting for shutdown gate.");
+			fw_log(FW_LOG_ERROR, "Error waiting for shutdown gate.");
 			return CELIX_FRAMEWORK_EXCEPTION;
 		}
 	}
 	if (apr_thread_mutex_unlock(framework->mutex) != 0) {
-		fw_log(FW_LOG_ERROR,  "Error unlocking the framework.");
+		fw_log(FW_LOG_ERROR, "Error unlocking the framework.");
 		return CELIX_FRAMEWORK_EXCEPTION;
 	}
-	printf("FRAMEWORK: Successful shutdown\n");
+	fw_log(FW_LOG_INFO, "FRAMEWORK: Successful shutdown");
 	return CELIX_SUCCESS;
 }
 
@@ -1985,7 +1983,7 @@ static void *APR_THREAD_FUNC framework_s
 	hash_map_iterator_pt iterator;
 	int err;
 
-	printf("FRAMEWORK: Shutdown\n");
+	fw_log(FW_LOG_INFO, "FRAMEWORK: Shutdown");
 
 	iterator = hashMapIterator_create(fw->installedBundleMap);
 	while (hashMapIterator_hasNext(iterator)) {
@@ -2010,12 +2008,8 @@ static void *APR_THREAD_FUNC framework_s
 		return NULL;
 	}
 	fw->shutdown = true;
-	printf("FRAMEWORK: Open gate\n");
 	err = apr_thread_cond_broadcast(fw->shutdownGate);
-	printf("FRAMEWORK: BC send %d\n", err);
-	printf("FRAMEWORK: BC send\n");
 	if (err != 0) {
-		printf("FRAMEWORK: BC send\n");
 		fw_log(FW_LOG_ERROR,  "Error waking the shutdown gate, cannot exit clean.");
 		err = apr_thread_mutex_unlock(fw->mutex);
 		if (err != 0) {
@@ -2025,16 +2019,14 @@ static void *APR_THREAD_FUNC framework_s
 		apr_thread_exit(thd, APR_ENOLOCK);
 		return NULL;
 	}
-	printf("FRAMEWORK: Unlock\n");
 	err = apr_thread_mutex_unlock(fw->mutex);
 	if (err != 0) {
 		fw_log(FW_LOG_ERROR,  "Error unlocking the framework, cannot exit clean.");
 	}
 
-	printf("FRAMEWORK: Exit thread\n");
 	apr_thread_exit(thd, APR_SUCCESS);
 
-	printf("FRAMEWORK: Shutdown done\n");
+	fw_log(FW_LOG_INFO, "FRAMEWORK: Shutdown done\n");
 
 	return NULL;
 }
@@ -2228,7 +2220,7 @@ celix_status_t bundleActivator_stop(void
 
 	if (bundleContext_getFramework(context, &framework) == CELIX_SUCCESS) {
 
-		printf("FRAMEWORK: Start shutdownthread\n");
+	    fw_log(FW_LOG_INFO, "FRAMEWORK: Start shutdownthread");
 	    if (apr_thread_create(&shutdownThread, NULL, framework_shutdown, framework, framework->mp) == APR_SUCCESS) {
             apr_thread_detach(shutdownThread);
 	    } else {

Modified: incubator/celix/trunk/framework/private/src/resolver.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/resolver.c?rev=1543369&r1=1543368&r2=1543369&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/resolver.c (original)
+++ incubator/celix/trunk/framework/private/src/resolver.c Tue Nov 19 10:21:18 2013
@@ -66,7 +66,6 @@ hash_map_pt resolver_resolve(module_pt r
 	hash_map_iterator_pt iter = NULL;
 
 	if (module_isResolved(root)) {
-	    printf("already resolved\n");
 		return NULL;
 	}
 

Modified: incubator/celix/trunk/framework/private/src/version.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/version.c?rev=1543369&r1=1543368&r2=1543369&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/version.c (original)
+++ incubator/celix/trunk/framework/private/src/version.c Tue Nov 19 10:21:18 2013
@@ -28,7 +28,6 @@
 #include <apr_strings.h>
 
 #include "celix_errno.h"
-#include "framework_log.h"
 #include "version_private.h"
 #include "celix_log.h"
 
@@ -57,15 +56,15 @@ celix_status_t version_createVersion(apr
 			(*version)->qualifier = apr_pstrdup(pool, qualifier);
 
 			if (major < 0) {
-				celix_log("Negative major");
+			    fw_log(FW_LOG_ERROR, "Negative major");
 				status = CELIX_ILLEGAL_ARGUMENT;
 			}
 			if (minor < 0) {
-				celix_log("Negative minor");
+			    fw_log(FW_LOG_ERROR, "Negative minor");
 				status = CELIX_ILLEGAL_ARGUMENT;
 			}
 			if (micro < 0) {
-				celix_log("Negative micro");
+			    fw_log(FW_LOG_ERROR, "Negative micro");
 				status = CELIX_ILLEGAL_ARGUMENT;
 			}
 
@@ -83,7 +82,7 @@ celix_status_t version_createVersion(apr
 				if ((ch == '_') || (ch == '-')) {
 					continue;
 				}
-				celix_log("Invalid qualifier");
+				fw_log(FW_LOG_ERROR, "Invalid qualifier");
 				status = CELIX_ILLEGAL_ARGUMENT;
 				break;
 			}
@@ -129,7 +128,7 @@ celix_status_t version_createVersionFrom
 			if (('0' <= ch) && (ch <= '9')) {
 				continue;
 			}
-			celix_log("Invalid format");
+			fw_log(FW_LOG_ERROR, "Invalid format");
 			status = CELIX_ILLEGAL_ARGUMENT;
 			break;
 		}
@@ -141,7 +140,7 @@ celix_status_t version_createVersionFrom
 				if (('0' <= ch) && (ch <= '9')) {
 					continue;
 				}
-				celix_log("Invalid format");
+				fw_log(FW_LOG_ERROR, "Invalid format");
 				status = CELIX_ILLEGAL_ARGUMENT;
 				break;
 			}
@@ -153,7 +152,7 @@ celix_status_t version_createVersionFrom
 					if (('0' <= ch) && (ch <= '9')) {
 						continue;
 					}
-					celix_log("Invalid format");
+					fw_log(FW_LOG_ERROR, "Invalid format");
 					status = CELIX_ILLEGAL_ARGUMENT;
 					break;
 				}

Modified: incubator/celix/trunk/framework/public/include/celix_log.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/public/include/celix_log.h?rev=1543369&r1=1543368&r2=1543369&view=diff
==============================================================================
--- incubator/celix/trunk/framework/public/include/celix_log.h (original)
+++ incubator/celix/trunk/framework/public/include/celix_log.h Tue Nov 19 10:21:18 2013
@@ -29,10 +29,8 @@
 
 #include <stdio.h>
 
-#if defined(WIN32)
-#define celix_log(msg) printf("%s\n", msg);
-#else
-#define celix_log(msg) printf("%s\n\tat %s(%s:%d)\n", msg, __func__, __FILE__, __LINE__);
+#include "framework_exports.h"
+
 #define fw_log(level, fmsg, args...) framework_log(level, __func__, __FILE__, __LINE__, fmsg, ## args)
 #define fw_logCode(level, code, fmsg, args...) framework_logCode(level, __func__, __FILE__, __LINE__, code, fmsg, ## args)
 #define framework_logIfError(status, error, fmsg, args...) \
@@ -43,7 +41,6 @@
             fw_logCode(FW_LOG_ERROR, status, #fmsg, ## args); \
         } \
     }
-#endif
 
 enum framework_log_level
 {
@@ -55,7 +52,7 @@ enum framework_log_level
 
 typedef enum framework_log_level framework_log_level_t;
 
-void framework_log(framework_log_level_t level, const char *func, const char *file, int line, char *fmsg, ...);
-void framework_logCode(framework_log_level_t level, const char *func, const char *file, int line, celix_status_t code, char *fmsg, ...);
+FRAMEWORK_EXPORT void framework_log(framework_log_level_t level, const char *func, const char *file, int line, char *fmsg, ...);
+FRAMEWORK_EXPORT void framework_logCode(framework_log_level_t level, const char *func, const char *file, int line, celix_status_t code, char *fmsg, ...);
 
 #endif /* CELIX_LOG_H_ */

Modified: incubator/celix/trunk/launcher/private/src/launcher.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/launcher/private/src/launcher.c?rev=1543369&r1=1543368&r2=1543369&view=diff
==============================================================================
--- incubator/celix/trunk/launcher/private/src/launcher.c (original)
+++ incubator/celix/trunk/launcher/private/src/launcher.c Tue Nov 19 10:21:18 2013
@@ -107,9 +107,7 @@ int main(void) {
                         // Only add bundle if it is installed correctly
                         arrayList_add(installed, current);
                     } else {
-                        char error[256];
-                        sprintf(error, "Could not install bundle from %s", location);
-                        celix_log(error);
+                        fw_logCode(FW_LOG_ERROR, CELIX_BUNDLE_EXCEPTION, "Could not install bundle from %s", location);
                     }
                     linkedListIterator_remove(iter);
                 }
@@ -131,13 +129,13 @@ int main(void) {
     }
 
     if (status != CELIX_SUCCESS) {
-        celix_log("Problem creating framework");
+        fw_logCode(FW_LOG_ERROR, status, "Problem creating framework");
     }
 
 	apr_pool_destroy(memoryPool);
 	apr_terminate();
 
-	printf("LAUNCHER: Exit\n");
+	fw_log(FW_LOG_INFO, "Launcher: Exit");
 
     return 0;
 }