[Freeswitch-svn] [commit] r5252 - in freeswitch/branches/anthonyl/log2file-branch/src: include mod/loggers/mod_log2file

Freeswitch SVN anthonyl at freeswitch.org
Sun Jun 3 04:39:07 EDT 2007


Author: anthonyl
Date: Sun Jun  3 04:39:06 2007
New Revision: 5252

Modified:
   freeswitch/branches/anthonyl/log2file-branch/src/include/switch_apr.h
   freeswitch/branches/anthonyl/log2file-branch/src/mod/loggers/mod_log2file/mod_log2file.c

Log:
a fun update, the logging works which is nice ;) i had to add a def for switch_fopen_seek.. in the apr file_io.h code it just defines apr_seek as seek_set so i use that for now..
umm, i still need to work on some of the memory pool things as well as on adding some features.. but that's not to much work ;-p


Modified: freeswitch/branches/anthonyl/log2file-branch/src/include/switch_apr.h
==============================================================================
--- freeswitch/branches/anthonyl/log2file-branch/src/include/switch_apr.h	(original)
+++ freeswitch/branches/anthonyl/log2file-branch/src/include/switch_apr.h	Sun Jun  3 04:39:06 2007
@@ -641,7 +641,7 @@
 #define SWITCH_FOPEN_SENDFILE_ENABLED	0x01000		/**< Advisory flag that this file should support apr_socket_sendfile operation */
 #define SWITCH_FOPEN_LARGEFILE			0x04000		/**< Platform dependent flag to enable large file support */
 /** @} */
-
+#define SWITCH_FOPEN_SET                SEEK_SET    /**< Set the position of the file for seeking */
 /**
  * Open the specified file.
  * @param newf The opened file descriptor.

Modified: freeswitch/branches/anthonyl/log2file-branch/src/mod/loggers/mod_log2file/mod_log2file.c
==============================================================================
--- freeswitch/branches/anthonyl/log2file-branch/src/mod/loggers/mod_log2file/mod_log2file.c	(original)
+++ freeswitch/branches/anthonyl/log2file-branch/src/mod/loggers/mod_log2file/mod_log2file.c	Sun Jun  3 04:39:06 2007
@@ -45,16 +45,13 @@
 static switch_status_t mod_log2file_check(void);
 
 static switch_memory_pool_t *module_pool = NULL;
-static switch_hash_t *log_hash = NULL;
-static switch_hash_t *name_hash = NULL;
-static int8_t all_level = -1;
 
 static struct {
     unsigned int log_fd;
     unsigned int log_size;   /* keep the log size in check for rotation */
     unsigned int roll_size;  /* the size that we want to rotate the file at */
-    unsigned char *logfile;
-	unsigned char *format;
+    char *logfile;
+	char *format;
     switch_file_t    *log_afd;
 } globals;
 
@@ -131,7 +128,7 @@
 {
     char *q;
     
-    while (q = strsep(&p, ",")) {
+    while ((q = strsep(&p, ","))) {
         if (!strncasecmp(q, "emerg", strlen(q))) {
             levels[SWITCH_LOG_EMERG].on = 1;
         } else if (!strncasecmp(q, "alert", strlen(q))) {
@@ -163,37 +160,45 @@
 }
 static switch_status_t mod_log2file_openlogfile(void)
 {
-    int fd;
+    unsigned int flags = 0;
     switch_file_t *afd;
     switch_status_t stat;
+	switch_memory_pool_t *pool;
 
-    stat = switch_file_open(&afd, globals.logfile,
-                         APR_CREATE| APR_READ | APR_WRITE | APR_APPEND, NULL, NULL);
-
+    
+    flags |= SWITCH_FOPEN_CREATE;
+    flags |= SWITCH_FOPEN_READ;
+    flags |= SWITCH_FOPEN_WRITE;
+    flags |= SWITCH_FOPEN_APPEND;
+    
+    switch_core_new_memory_pool(&pool);       
+    stat = switch_file_open(&afd, globals.logfile,flags,SWITCH_FPROT_UREAD|SWITCH_FPROT_UWRITE, pool);
     if (stat != SWITCH_STATUS_SUCCESS) {
         return SWITCH_STATUS_FALSE;
     }
     globals.log_afd = afd;
     mod_log2file_check();
+    
     return SWITCH_STATUS_SUCCESS;
 }
 
 /* rotate the log file */
 static switch_status_t mod_log2file_rotate(void)
 {
-     unsigned int i = 0;
-    unsigned char *p = NULL;
-    unsigned char *q = NULL;
+    unsigned int i = 0;
+    unsigned int flags = 0;
+    char *p = NULL;
+    char *q = NULL;
     switch_status_t stat = 0;
     switch_size_t   nbytes = 1024;
     switch_file_t *l_afd = NULL;
+    switch_memory_pool_t *pool = NULL;
     
     globals.log_size = 0;
-    stat = switch_file_seek(globals.log_afd, APR_SET, 0);
-
+    switch_core_new_memory_pool(&pool);   
+    stat = switch_file_seek(globals.log_afd, SWITCH_FOPEN_SET, 0);
     if (stat != SWITCH_STATUS_SUCCESS)
         return SWITCH_STATUS_FALSE;
-    
     p = malloc(strlen(globals.logfile)+WARM_FUZZY_OFFSET);
     if (!p) {
         return SWITCH_STATUS_FALSE;
@@ -205,22 +210,28 @@
     }
     memset(p, '\0', strlen(globals.logfile)+WARM_FUZZY_OFFSET);
     for (i=1;i<MAX_ROT; i++) {
-        sprintf(p, "%s.%i", globals.logfile, i);
-        stat = switch_file_open(l_afd, p, APR_READ, NULL, NULL);
+        sprintf((char *)p, "%s.%i", globals.logfile, i);
+
+        stat = switch_file_open(&l_afd, p, SWITCH_FOPEN_READ, SWITCH_FPROT_UREAD, pool);
+
         if (stat == SWITCH_STATUS_SUCCESS) {
             switch_file_close(l_afd);
             continue;
         }
-        stat = switch_file_open(l_afd, p, APR_READ | APR_WRITE | APR_CREATE , NULL, NULL);
+        flags |= SWITCH_FOPEN_READ;
+        flags |= SWITCH_FOPEN_WRITE;
+        flags |= SWITCH_FOPEN_CREATE;
+        
+        stat = switch_file_open(&l_afd, p, flags , SWITCH_FPROT_UREAD | SWITCH_FPROT_UWRITE ,pool);
         if (stat == SWITCH_STATUS_SUCCESS)
             break;
     }
-    while ((stat = switch_file_read(&globals.log_afd, q, &nbytes)) == SWITCH_STATUS_SUCCESS) {
+    while ((stat = switch_file_read(globals.log_afd, q, &nbytes)) == SWITCH_STATUS_SUCCESS) {
         switch_file_write(l_afd, q, &nbytes);
         memset(q, '\0', 1024);
         nbytes = 1024;
     }
-    stat = switch_file_seek(&globals.log_afd, APR_SET, 0);
+    stat = switch_file_seek(globals.log_afd, SWITCH_FOPEN_SET, 0);
     free(p);
     free(q);
     return SWITCH_STATUS_SUCCESS;
@@ -229,26 +240,23 @@
 /* check the size of the file for rotation */
 static switch_status_t mod_log2file_check(void)
 {
-    switch_status_t stat;
     switch_size_t   fsize;
-    fsize = switch_file_get_size(&globals.log_afd);
-       
-    if (stat != SWITCH_STATUS_SUCCESS)
-        return SWITCH_STATUS_FALSE;
+    fsize = switch_file_get_size(globals.log_afd);
 
+    printf("Checking LogFile\n");
     if (fsize >= globals.roll_size) {
         return mod_log2file_rotate();
     }
-    
+    printf("File Size %i\n",fsize);
     return SWITCH_STATUS_SUCCESS;
 }
 
 /* write to the actual logfile */
 static switch_status_t mod_log2file_write(char *fmt, ...) 
 {
-    unsigned int len;
     char *log_data;
     switch_status_t stat;
+    switch_size_t len;
     va_list args;
     va_start(args, fmt);
     printf("Mod Log To File Write\n");
@@ -257,12 +265,14 @@
 #else
     len = vasprintf(&log_data, fmt, args);
 #endif
+    printf("log data %s\n", log_data);
     if (len <= 0)
         return SWITCH_STATUS_FALSE;
-    stat = switch_file_write(&globals.log_afd, log_data, len);
-    if (stat != SWITCH_STATUS_SUCCESS)
-        return SWITCH_STATUS_FALSE;
+    stat = switch_file_write(globals.log_afd, log_data, &len);
+    //if (stat != SWITCH_STATUS_SUCCESS)
+    //return SWITCH_STATUS_FALSE;
     globals.log_size += len;
+    printf("Done Writing To File");
     /* we may want to hold back on this for preformance reasons */
     mod_log2file_check();
     return SWITCH_STATUS_SUCCESS;
@@ -270,8 +280,7 @@
 
 static switch_status_t mod_log2file_logger(const switch_log_node_t *node, switch_log_level_t level)
 {
-    uint8_t *lookup = NULL;
-	char line_no[sizeof(int)*8+1];
+ 	char line_no[sizeof(int)*8+1];
 	char date[80] = "";
 	switch_time_exp_t time;
 	switch_size_t retsize;
@@ -326,6 +335,8 @@
 	char *cf = "log2file.conf";
 	switch_xml_t cfg, xml, settings, param;
 
+    printf("Running load_config\n");
+    
 	if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
 	} else {
@@ -366,7 +377,9 @@
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "OH OH no pool\n");
 		return SWITCH_STATUS_TERM;
 	}
-   
+
+
+    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT,"Loading ModLog2File\n");
 	*interface = &log2file_module_interface; 
     
 	if ((status=load_config()) != SWITCH_STATUS_SUCCESS) {



More information about the Freeswitch-svn mailing list