]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
enhance logger stuff
authorBrian West <brian@freeswitch.org>
Wed, 12 Apr 2006 14:41:35 +0000 (14:41 +0000)
committerBrian West <brian@freeswitch.org>
Wed, 12 Apr 2006 14:41:35 +0000 (14:41 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@1123 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_log.h
src/include/switch_types.h
src/mod/loggers/mod_console/mod_console.c
src/switch_log.c

index 84d91a31f8486e1f5964a1d829c5675a83df67c1..3a00c8b79a82cc16b40a6d48d7c4e4eb2000eaf4 100644 (file)
@@ -47,6 +47,18 @@ extern "C" {
 
 #include <switch.h>
 
+typedef struct {
+       char *data;
+       char *file;
+       char *func;
+       char *content;
+       uint32_t line;
+       switch_log_level level;
+       switch_time_t timestamp;
+} switch_log_node;
+
+typedef switch_status (*switch_log_function)(const switch_log_node *node, switch_log_level level);
+
 /*!
   \brief A method akin to printf that allows you to redirect output to a specific log
 */
index 96b5ea8706c2d4d536810cde7a5800aa79edc2bc..d14f5d7ba5aa387ca457176a64623116a3c22abe 100644 (file)
@@ -233,7 +233,6 @@ typedef enum {
        SWITCH_LOG_ALERT = 1,
        SWITCH_LOG_EMERG = 0
 } switch_log_level;
-typedef switch_status (*switch_log_function)(const char *data, switch_log_level level);
 
 
 /*!
index 5cab0926a98888d708a86d3b1ba9ca04be41ef10..b9eecdb50b0c13faacd430ca3c63fed904a5ce3a 100644 (file)
@@ -46,12 +46,12 @@ static switch_loadable_module_interface console_module_interface = {
        /*.directory_interface */ NULL
 };
 
-static switch_status switch_console_logger(const char *data, switch_log_level level)
+static switch_status switch_console_logger(const switch_log_node *node, switch_log_level level)
 {
        FILE *handle;
 
        if ((handle = switch_core_data_channel(SWITCH_CHANNEL_ID_LOG))) {
-               fprintf(handle, data);
+               fprintf(handle, node->data);
        }
        
        return SWITCH_STATUS_SUCCESS;
index bef8d6d6853fea3a888d8d594ac036b1a797c733..7b3e57d5f0d37b36ff496ffdcf3db28096a1921a 100644 (file)
@@ -49,12 +49,8 @@ struct switch_log_binding {
        switch_log_level level;
        struct switch_log_binding *next;
 };
-typedef struct switch_log_binding switch_log_binding;
 
-typedef struct {
-       char *data;
-       switch_log_level level;
-} switch_log_node;
+typedef struct switch_log_binding switch_log_binding;
 
 static switch_memory_pool *LOG_POOL = NULL;
 static switch_log_binding *BINDINGS = NULL;
@@ -117,7 +113,7 @@ static void *SWITCH_THREAD_FUNC log_thread(switch_thread *thread, void *obj)
                switch_mutex_lock(BINDLOCK);
                for(binding = BINDINGS; binding; binding = binding->next) {
                        if (binding->level >= node->level) {
-                               binding->function(node->data, node->level);
+                               binding->function(node, node->level);
                        }
                }
                switch_mutex_unlock(BINDLOCK);
@@ -125,9 +121,17 @@ static void *SWITCH_THREAD_FUNC log_thread(switch_thread *thread, void *obj)
                        if (node->data) {
                                free(node->data);
                        }
+
+                       if (node->file) {
+                               free(node->file);
+                       }
+
+                       if (node->func) {
+                               free(node->func);
+                       }
+
                        free(node);
                }
-
        }
        THREAD_RUNNING = 0;
        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Logger Ended.\n");
@@ -142,9 +146,10 @@ SWITCH_DECLARE(void) switch_log_printf(switch_text_channel channel, char *file,
        va_list ap;
        FILE *handle;
        char *filep = switch_cut_path(file);
-
+       char *content = NULL;
+       switch_time_t now = switch_time_now();
        uint32_t len;
-       const char *extra_fmt = "%s [%s] %s:%d %s() %s";
+       const char *extra_fmt = "%s [%s] %s:%d %s()%c%s";
        va_start(ap, fmt);
 
        handle = switch_core_data_channel(channel);
@@ -154,12 +159,12 @@ SWITCH_DECLARE(void) switch_log_printf(switch_text_channel channel, char *file,
                switch_size_t retsize;
                switch_time_exp_t tm;
 
-               switch_time_exp_lt(&tm, switch_time_now());
+               switch_time_exp_lt(&tm, now);
                switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
                
                len = (uint32_t)(strlen(extra_fmt) + strlen(date) + strlen(filep) + 32 + strlen(func) + strlen(fmt));
                new_fmt = malloc(len+1);
-               snprintf(new_fmt, len, extra_fmt, date, LEVELS[level], filep, line, func, fmt);
+               snprintf(new_fmt, len, extra_fmt, date, LEVELS[level], filep, line, func, (char) 128, fmt);
                fmt = new_fmt;
        }
 
@@ -173,6 +178,13 @@ SWITCH_DECLARE(void) switch_log_printf(switch_text_channel channel, char *file,
        if (ret == -1) {
                fprintf(stderr, "Memory Error\n");
        } else {
+
+               if (channel == SWITCH_CHANNEL_ID_LOG_CLEAN) {
+                       content = data;
+               } else {
+                       content = strchr(data, (char)128);
+               }
+
                if (channel == SWITCH_CHANNEL_ID_EVENT) {
                                switch_event *event;
                                if (switch_event_running() == SWITCH_STATUS_SUCCESS && switch_event_create(&event, SWITCH_EVENT_LOG) == SWITCH_STATUS_SUCCESS) {
@@ -190,7 +202,12 @@ SWITCH_DECLARE(void) switch_log_printf(switch_text_channel channel, char *file,
                        if (level >= MAX_LEVEL) {
                                switch_log_node *node = malloc(sizeof(*node));
                                node->data = data;
+                               node->file = strdup(filep);
+                               node->func = strdup(func);
+                               node->line = line;
                                node->level = level;
+                               node->content = content;
+                               node->timestamp = now;
                                switch_queue_push(LOG_QUEUE, node);
                        } else {
                                free(data);