- fixed bug in logger_t not storing the name of it
authorJan Hutter <jhutter@hsr.ch>
Fri, 11 Nov 2005 11:20:22 +0000 (11:20 -0000)
committerJan Hutter <jhutter@hsr.ch>
Fri, 11 Nov 2005 11:20:22 +0000 (11:20 -0000)
Source/charon/logger.c
Source/charon/logger_manager.c
Source/charon/logger_manager.h
Source/charon/parser.c
Source/charon/thread_pool.c

index 98f69ab..eee03b7 100644 (file)
@@ -232,6 +232,7 @@ static status_t disable_level(private_logger_t *this, logger_level_t log_level)
  */
 static status_t destroy(private_logger_t *this)
 {
+       allocator_free(this->name);
        allocator_free(this);
        return SUCCESS;
 }
@@ -248,6 +249,11 @@ logger_t *logger_create(char *logger_name, logger_level_t log_level,FILE * outpu
                return NULL;    
        }
        
+       if (logger_name == NULL)
+       {
+               logger_name = "";
+       }
+       
        this->public.log = (status_t(*)(logger_t*,logger_level_t,char*,...))logg;
        this->public.log_bytes = (status_t(*)(logger_t*, logger_level_t, char*,char*,size_t))log_bytes;
        this->public.log_chunk = log_chunk;
@@ -259,7 +265,13 @@ logger_t *logger_create(char *logger_name, logger_level_t log_level,FILE * outpu
 
        /* private variables */
        this->level = log_level;
-       this->name = logger_name;
+       this->name = allocator_alloc(strlen(logger_name) + 1);
+       if (this->name == NULL)
+       {
+               allocator_free(this);
+               return NULL;
+       }
+       strcpy(this->name,logger_name);
        this->output = output;
 
        
index 5e331e7..80721bb 100644 (file)
@@ -127,6 +127,9 @@ static status_t get_logger (private_logger_manager_t *this, logger_context_t con
                case RECEIVER_THREAD:
                        context_name = "RECEIVER_THREAD";
                        break;
+               case THREAD_POOL:
+                       context_name = "THREAD_POOL";
+                       break;
                case TESTER:
                        context_name = "TESTER";
                        output = stdout;
@@ -137,10 +140,17 @@ static status_t get_logger (private_logger_manager_t *this, logger_context_t con
        }
        
        pthread_mutex_lock(&(this->mutex));
-       snprintf(buffer, MAX_LOGGER_NAME, "%s - %s",context_name,name);
+       if (name != NULL)
+       {
+               snprintf(buffer, MAX_LOGGER_NAME, "%s - %s",context_name,name);
+                       /* create logger with default log_level */
+               *logger = logger_create(buffer,logger_level,output);
+       }
+       else
+       {
+               *logger = logger_create(context_name,logger_level,output);
+       }
        
-       /* create logger with default log_level */
-       *logger = logger_create(buffer,logger_level,output);
        
        if (*logger == NULL)
        {
index 920a51d..59c88d1 100644 (file)
@@ -37,6 +37,7 @@ enum logger_context_e{
        GENERATOR,
        IKE_SA,
        MESSAGE,
+       THREAD_POOL,
        WORKER_THREAD,
        EVENT_THREAD,
        SENDER_THREAD,
index ecc0b23..b072bc2 100644 (file)
@@ -24,6 +24,7 @@
 #include <arpa/inet.h>
 
 #include "allocator.h"
+#include "globals.h"
 #include "types.h"
 #include "parser.h"
 #include "logger.h"
@@ -379,7 +380,7 @@ static status_t parse_payload(private_parser_t *this, payload_type_t payload_typ
  */
 static status_t destroy(private_parser_t *this)
 {
-       this->logger->destroy(this->logger);
+       global_logger_manager->destroy_logger(global_logger_manager,this->logger);
        allocator_free(this);   
        
        return SUCCESS;
@@ -397,7 +398,8 @@ parser_t *parser_create(payload_info_t **payload_infos)
                return NULL;
        }
        
-       this->logger = logger_create("parser", ALL,NULL);
+       global_logger_manager->get_logger(global_logger_manager,PARSER,&(this->logger),"");
+       
        if (this->logger == NULL)
        {
                allocator_free(this);
index 76783ef..532587e 100644 (file)
@@ -113,7 +113,7 @@ static status_t destroy(private_thread_pool_t *this)
        }       
 
        /* free mem */
-       this->logger->destroy(this->logger);
+       global_logger_manager->destroy_logger(global_logger_manager, this->logger);
        allocator_free(this->threads);
        allocator_free(this);
        return SUCCESS;
@@ -143,7 +143,7 @@ thread_pool_t *thread_pool_create(size_t pool_size)
                allocator_free(this);
                return NULL;
        }       
-       this->logger = logger_create("thread_pool", ALL,NULL);
+       global_logger_manager->get_logger(global_logger_manager,THREAD_POOL,&(this->logger),NULL);
        if (this->threads == NULL)
        {
                allocator_free(this);