celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From abroekh...@apache.org
Subject svn commit: r1652835 - in /celix/trunk/log_service/private: include/log.h src/log.c src/log_service_activator.c
Date Sun, 18 Jan 2015 19:14:20 GMT
Author: abroekhuis
Date: Sun Jan 18 19:14:20 2015
New Revision: 1652835

URL: http://svn.apache.org/r1652835
Log:
CELIX-115: Added properties to limit internal log entry list length. Added property to store
debug entries internally or not.

Modified:
    celix/trunk/log_service/private/include/log.h
    celix/trunk/log_service/private/src/log.c
    celix/trunk/log_service/private/src/log_service_activator.c

Modified: celix/trunk/log_service/private/include/log.h
URL: http://svn.apache.org/viewvc/celix/trunk/log_service/private/include/log.h?rev=1652835&r1=1652834&r2=1652835&view=diff
==============================================================================
--- celix/trunk/log_service/private/include/log.h (original)
+++ celix/trunk/log_service/private/include/log.h Sun Jan 18 19:14:20 2015
@@ -33,7 +33,7 @@
 
 typedef struct log * log_pt;
 
-celix_status_t log_create(log_pt *logger);
+celix_status_t log_create(int max_size, bool store_debug, log_pt *logger);
 celix_status_t log_destroy(log_pt logger);
 celix_status_t log_addEntry(log_pt log, log_entry_pt entry);
 celix_status_t log_getEntries(log_pt log, linked_list_pt *list);

Modified: celix/trunk/log_service/private/src/log.c
URL: http://svn.apache.org/viewvc/celix/trunk/log_service/private/src/log.c?rev=1652835&r1=1652834&r2=1652835&view=diff
==============================================================================
--- celix/trunk/log_service/private/src/log.c (original)
+++ celix/trunk/log_service/private/src/log.c Sun Jan 18 19:14:20 2015
@@ -42,6 +42,9 @@ struct log {
 	celix_thread_cond_t entriesToDeliver;
 	celix_thread_mutex_t deliverLock;
 	celix_thread_mutex_t listenerLock;
+
+	int max_size;
+	bool store_debug;
 };
 
 static celix_status_t log_startListenerThread(log_pt logger);
@@ -50,7 +53,7 @@ static celix_status_t log_stopListenerTh
 
 static void *log_listenerThread(void *data);
 
-celix_status_t log_create(log_pt *logger) {
+celix_status_t log_create(int max_size, bool store_debug, log_pt *logger) {
 	celix_status_t status = CELIX_ENOMEM;
 
 	*logger = calloc(1, sizeof(**logger));
@@ -65,6 +68,9 @@ celix_status_t log_create(log_pt *logger
 		(*logger)->listenerThread = celix_thread_default;
 		(*logger)->running = false;
 
+		(*logger)->max_size = max_size;
+		(*logger)->store_debug = store_debug;
+
 		arrayList_create(&(*logger)->listeners);
 		arrayList_create(&(*logger)->listenerEntries);
 
@@ -112,7 +118,21 @@ celix_status_t log_destroy(log_pt logger
 
 celix_status_t log_addEntry(log_pt log, log_entry_pt entry) {
 	celixThreadMutex_lock(&log->lock);
-	linkedList_addElement(log->entries, entry);
+
+	if (log->max_size != 0) {
+		if (log->store_debug || entry->level != OSGI_LOGSERVICE_DEBUG) {
+			linkedList_addElement(log->entries, entry);
+		}
+
+		if (log->max_size != -1) {
+			if (linkedList_size(log->entries) > log->max_size) {
+				log_entry_pt entry = linkedList_removeFirst(log->entries);
+				if (entry) {
+					logEntry_destroy(&entry);
+				}
+			}
+		}
+	}
 
 	arrayList_add(log->listenerEntries, entry);
 	celixThreadCondition_signal(&log->entriesToDeliver);

Modified: celix/trunk/log_service/private/src/log_service_activator.c
URL: http://svn.apache.org/viewvc/celix/trunk/log_service/private/src/log_service_activator.c?rev=1652835&r1=1652834&r2=1652835&view=diff
==============================================================================
--- celix/trunk/log_service/private/src/log_service_activator.c (original)
+++ celix/trunk/log_service/private/src/log_service_activator.c Sun Jan 18 19:14:20 2015
@@ -34,6 +34,12 @@
 #include "log_reader_service_impl.h"
 #include "service_registration.h"
 
+#define DEFAULT_MAX_SIZE 100
+#define DEFAULT_STORE_DEBUG false
+
+#define MAX_SIZE_PROPERTY "CELIX_LOG_MAX_SIZE"
+#define STORE_DEBUG_PROPERTY "CELIX_LOG_STORE_DEBUG"
+
 struct logActivator {
     bundle_context_pt bundleContext;
     service_registration_pt logServiceFactoryReg;
@@ -48,6 +54,9 @@ struct logActivator {
     log_reader_service_pt reader_service;
 };
 
+static celix_status_t bundleActivator_getMaxSize(struct logActivator *activator, int *max_size);
+static celix_status_t bundleActivator_getStoreDebug(struct logActivator *activator, bool
*store_debug);
+
 celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
     celix_status_t status = CELIX_SUCCESS;
 	struct logActivator * activator = NULL;
@@ -76,8 +85,13 @@ celix_status_t bundleActivator_start(voi
     struct logActivator * activator = (struct logActivator *) userData;
     celix_status_t status = CELIX_SUCCESS;
 
+    int max_size = 0;
+    bool store_debug = false;
+
+    bundleActivator_getMaxSize(activator, &max_size);
+    bundleActivator_getStoreDebug(activator, &store_debug);
 
-    log_create(&activator->logger);
+    log_create(max_size, store_debug, &activator->logger);
 
     // Add logger as Bundle- and FrameworkEvent listener
     activator->bundleListener = calloc(1, sizeof(*activator->bundleListener));
@@ -139,3 +153,37 @@ celix_status_t bundleActivator_destroy(v
 
     return CELIX_SUCCESS;
 }
+
+static celix_status_t bundleActivator_getMaxSize(struct logActivator *activator, int *max_size)
{
+	celix_status_t status = CELIX_SUCCESS;
+
+	char *max_size_str = NULL;
+
+	*max_size = DEFAULT_MAX_SIZE;
+
+	bundleContext_getProperty(activator->bundleContext, MAX_SIZE_PROPERTY, &max_size_str);
+	if (max_size_str) {
+		*max_size = atoi(max_size_str);
+	}
+
+	return status;
+}
+
+static celix_status_t bundleActivator_getStoreDebug(struct logActivator *activator, bool
*store_debug) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	char *store_debug_str = NULL;
+
+	*store_debug = DEFAULT_STORE_DEBUG;
+
+	bundleContext_getProperty(activator->bundleContext, STORE_DEBUG_PROPERTY, &store_debug_str);
+	if (store_debug_str) {
+		if (strcasecmp(store_debug_str, "true") == 0) {
+			*store_debug = true;
+		} else if (strcasecmp(store_debug_str, "false") == 0) {
+			*store_debug = false;
+		}
+	}
+
+	return status;
+}



Mime
View raw message