]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
file/func specific logging
authorBrian West <brian@freeswitch.org>
Wed, 12 Apr 2006 17:51:47 +0000 (17:51 +0000)
committerBrian West <brian@freeswitch.org>
Wed, 12 Apr 2006 17:51:47 +0000 (17:51 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@1128 d0543943-73ff-0310-b7d9-9358b9ac24b2

conf/freeswitch.conf
src/include/switch_log.h
src/mod/loggers/mod_console/mod_console.c
src/switch_log.c

index a90985986d7926397e7d2137663360037fbf4d81..8768f918e53f0509867ebc24fda2bff649cadb3c 100644 (file)
@@ -1,6 +1,16 @@
 ; Unified Config file
 ; each section denoted with a + could also be in it's own file
 
+;---- CONSOLE LOGGER
+;--------------------------------------------------------------------------------
+[+console.conf]
+[mappings]
+; pick a file name, a function name or 'all'
+; map as many as you need for specific debugging
+;mod_exosip.c => DEBUG
+;log_event => DEBUG
+;all => DEBUG
+
 ;---- MODULES
 ;--------------------------------------------------------------------------------
 [+modules.conf]
index 50ccec1225d993fda6e28e16d2f0788500bf6ad9..9aeb4870939f2010ea13012b33b9b0d7545919be 100644 (file)
@@ -114,6 +114,13 @@ SWITCH_DECLARE(switch_status) switch_log_bind_logger(switch_log_function functio
 */
 SWITCH_DECLARE(const char *) switch_log_level2str(switch_log_level level);
 
+/*! 
+  \brief Return the level number of the specified log level name
+  \param str the name of the level
+  \return the log level
+*/
+SWITCH_DECLARE(switch_log_level) switch_log_str2level(const char *str);
+
 ///\}
 #ifdef __cplusplus
 }
index b9eecdb50b0c13faacd430ca3c63fed904a5ce3a..051dde3f3ce84a1d6114ee989244056a2f31b468 100644 (file)
@@ -46,12 +46,65 @@ static switch_loadable_module_interface console_module_interface = {
        /*.directory_interface */ NULL
 };
 
+static switch_memory_pool *module_pool = NULL;
+static switch_hash *log_hash = NULL;
+static int8_t all_level = -1;
+
+static switch_status config_logger(void)
+{
+       switch_config cfg;
+       char *var, *val;
+       char *cf = "console.conf";
+
+       if (!switch_config_open_file(&cfg, cf)) {
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "open of %s failed\n", cf);
+               return SWITCH_STATUS_FALSE;
+       }
+
+       switch_core_hash_init(&log_hash, module_pool);
+
+       while (switch_config_next_pair(&cfg, &var, &val)) {
+               if (!strcasecmp(cfg.category, "mappings")) {
+                       switch_core_hash_insert(log_hash, switch_core_strdup(module_pool, var), switch_core_strdup(module_pool, val));
+               }
+       }
+       
+       return SWITCH_STATUS_SUCCESS;
+}
+
 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, node->data);
+               char *lookup = NULL;
+               switch_log_level level = SWITCH_LOG_DEBUG;
+               
+               if (all_level > -1) {
+                       level = (switch_log_level) all_level;
+               } else if (log_hash) {
+                       lookup = switch_core_hash_find(log_hash, node->file);
+                       if (!lookup) {
+                               lookup = switch_core_hash_find(log_hash, node->func);
+
+                               if (!lookup && all_level == -1) {
+                                       if ((lookup = switch_core_hash_find(log_hash, "all"))) {
+                                               all_level = (int) switch_log_str2level(lookup);
+                                       } else {
+                                               all_level = -2;
+                                       }
+                               }
+
+                       }
+               }
+
+               if (lookup) {
+                       level = switch_log_str2level(lookup);
+               }
+               
+               if (!log_hash || (((all_level > - 1) || lookup) && level >= node->level)) {
+                       fprintf(handle, node->data);
+               }
        }
        
        return SWITCH_STATUS_SUCCESS;
@@ -59,12 +112,20 @@ static switch_status switch_console_logger(const switch_log_node *node, switch_l
 
 SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, char *filename)
 {
+       if (switch_core_new_memory_pool(&module_pool) != SWITCH_STATUS_SUCCESS) {
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "OH OH no pool\n");
+               return SWITCH_STATUS_TERM;
+       }
+
+
        /* connect my internal structure to the blank pointer passed to me */
        *interface = &console_module_interface;
 
        /* setup my logger function */
        switch_log_bind_logger(switch_console_logger, SWITCH_LOG_DEBUG);
        
+       config_logger();
+
        /* indicate that the module should continue to be loaded */
        return SWITCH_STATUS_SUCCESS;
 }
index 93bad6c36b8371912ad7668c8240a93f582bad89..0cfdece4d420794979f4c492988d66fb0d1e129b 100644 (file)
@@ -41,7 +41,8 @@ static const char *LEVELS[] = {
        "NOTICE" , 
        "INFO"   , 
        "DEBUG"  , 
-       "CONSOLE" 
+       "CONSOLE",
+       NULL
 };
 
 struct switch_log_binding {
@@ -59,6 +60,28 @@ static switch_queue_t *LOG_QUEUE = NULL;
 static int8_t THREAD_RUNNING = 0;
 static uint8_t MAX_LEVEL = 0;
 
+SWITCH_DECLARE(const char *) switch_log_level2str(switch_log_level level)
+{
+       return LEVELS[level];
+}
+
+SWITCH_DECLARE(switch_log_level) switch_log_str2level(const char *str)
+{
+       int x = 0;
+       switch_log_level level = SWITCH_LOG_DEBUG;
+       for(x = 0;;x++) {
+               if (!LEVELS[x]) {
+                       break;
+               }
+               if (!strcasecmp(LEVELS[x], str)) {
+                       level = (switch_log_level) x;
+                       break;
+               }
+       }
+
+       return level;
+}
+
 SWITCH_DECLARE(switch_status) switch_log_bind_logger(switch_log_function function, switch_log_level level)
 {
        switch_log_binding *binding = NULL, *ptr = NULL;