ws-axis-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dami...@apache.org
Subject svn commit: r587843 - in /webservices/axis2/branches/c/29092007/util: include/axutil_file_handler.h include/axutil_log.h src/file_handler.c src/log.c
Date Wed, 24 Oct 2007 10:04:50 GMT
Author: damitha
Date: Wed Oct 24 03:04:49 2007
New Revision: 587843

URL: http://svn.apache.org/viewvc?rev=587843&view=rev
Log:
adding log rotate functionality

Modified:
    webservices/axis2/branches/c/29092007/util/include/axutil_file_handler.h
    webservices/axis2/branches/c/29092007/util/include/axutil_log.h
    webservices/axis2/branches/c/29092007/util/src/file_handler.c
    webservices/axis2/branches/c/29092007/util/src/log.c

Modified: webservices/axis2/branches/c/29092007/util/include/axutil_file_handler.h
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/29092007/util/include/axutil_file_handler.h?rev=587843&r1=587842&r2=587843&view=diff
==============================================================================
--- webservices/axis2/branches/c/29092007/util/include/axutil_file_handler.h (original)
+++ webservices/axis2/branches/c/29092007/util/include/axutil_file_handler.h Wed Oct 24 03:04:49
2007
@@ -19,6 +19,7 @@
 #define AXUTIL_FILE_HANDLER_H
 
 #include <axutil_string.h>
+#include <stdio.h>
 
 #ifdef __cplusplus
 extern "C"
@@ -71,6 +72,15 @@
     axutil_file_handler_access(
         const axis2_char_t * path,
         int mode);
+
+    AXIS2_EXTERN axis2_status_t AXIS2_CALL
+    axutil_file_handler_copy(
+        FILE *from, 
+        FILE *to);
+
+    long 
+    axutil_file_handler_size(
+        const axis2_char_t *const name);
 
     /** @} */
 

Modified: webservices/axis2/branches/c/29092007/util/include/axutil_log.h
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/29092007/util/include/axutil_log.h?rev=587843&r1=587842&r2=587843&view=diff
==============================================================================
--- webservices/axis2/branches/c/29092007/util/include/axutil_log.h (original)
+++ webservices/axis2/branches/c/29092007/util/include/axutil_log.h Wed Oct 24 03:04:49 2007
@@ -188,6 +188,7 @@
         const axis2_char_t * file,
         const int line);
 
+
 #define AXIS2_LOG_FREE(allocator, log) \
       axutil_log_free(allocator, log)
 

Modified: webservices/axis2/branches/c/29092007/util/src/file_handler.c
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/29092007/util/src/file_handler.c?rev=587843&r1=587842&r2=587843&view=diff
==============================================================================
--- webservices/axis2/branches/c/29092007/util/src/file_handler.c (original)
+++ webservices/axis2/branches/c/29092007/util/src/file_handler.c Wed Oct 24 03:04:49 2007
@@ -20,6 +20,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <platforms/axutil_platform_auto_sense.h>
+#include <sys/stat.h>
 
 #include <axutil_file_handler.h>
 
@@ -67,3 +68,43 @@
     }
     return status;
 }
+
+axis2_status_t
+axutil_file_handler_copy(
+    FILE *from, 
+    FILE *to)
+{
+    axis2_char_t ch;
+    
+    /* It is assumed that source and destination files are accessible and open*/
+    while(!feof(from)) 
+    {
+        ch = fgetc(from);
+        if(ferror(from)) 
+        {
+            /* Error reading source file */
+            return AXIS2_FAILURE;
+        }
+        if(!feof(from)) fputc(ch, to);
+        if(ferror(to)) 
+        {
+            /* Error writing destination file */
+            return AXIS2_FAILURE;
+        }
+    }
+    return AXIS2_SUCCESS;
+}
+
+long 
+axutil_file_handler_size(
+    const axis2_char_t *const name)
+{
+    struct stat stbuf;
+    if(stat(name, &stbuf) == -1)
+    {
+        /* The file could not be accessed */
+        return AXIS2_FAILURE;
+    }
+    return stbuf.st_size;
+}
+

Modified: webservices/axis2/branches/c/29092007/util/src/log.c
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/29092007/util/src/log.c?rev=587843&r1=587842&r2=587843&view=diff
==============================================================================
--- webservices/axis2/branches/c/29092007/util/src/log.c (original)
+++ webservices/axis2/branches/c/29092007/util/src/log.c Wed Oct 24 03:04:49 2007
@@ -25,6 +25,11 @@
 #include <axutil_thread.h>
 
 typedef struct axutil_log_impl axutil_log_impl_t;
+#define AXUTIL_LOG_FILE_SIZE 2000
+
+static axis2_status_t
+axutil_log_impl_rotate(
+    axutil_log_t * log);
 
 static void AXIS2_CALL axutil_log_impl_write(
     axutil_log_t * log,
@@ -34,6 +39,7 @@
     const int line);
 
 AXIS2_EXTERN void AXIS2_CALL axutil_log_impl_write_to_file(
+    axutil_log_t * log,
     FILE * fd,
     axutil_thread_mutex_t * mutex,
     axutil_log_levels_t level,
@@ -49,6 +55,7 @@
 {
     axutil_log_t log;
     void *stream;
+    axis2_char_t *file_name;
     axutil_thread_mutex_t *mutex;
 };
 
@@ -74,12 +81,13 @@
         {
             axutil_thread_mutex_destroy(log_impl->mutex);
         }
-        if (AXIS2_INTF_TO_IMPL(log)->stream)
+        if (log_impl->stream)
         {
-            if (log_impl->stream)
-            {
-                axutil_file_handler_close(log_impl->stream);
-            }
+            axutil_file_handler_close(log_impl->stream);
+        }
+        if (log_impl->file_name)
+        {
+            AXIS2_FREE(allocator, log_impl->file_name);
         }
         AXIS2_FREE(allocator, log_impl);
     }
@@ -157,10 +165,16 @@
     {
         AXIS2_SNPRINTF(log_file_name, 500, "%s", tmp_filename);
     }
+    log_impl->file_name = AXIS2_MALLOC(allocator, 500);
+    sprintf(log_impl->file_name, "%s", log_file_name);
 
     axutil_thread_mutex_lock(log_impl->mutex);
 
     log_impl->stream = axutil_file_handler_open(log_file_name, "a+");
+    if(!axutil_log_impl_rotate((axutil_log_t *) log_impl))
+    {
+        return NULL;
+    }
 
     axutil_thread_mutex_unlock(log_impl->mutex);
 
@@ -227,6 +241,7 @@
 
 AXIS2_EXTERN void AXIS2_CALL
 axutil_log_impl_write_to_file(
+    axutil_log_t * log,
     FILE * fd,
     axutil_thread_mutex_t * mutex,
     axutil_log_levels_t level,
@@ -262,6 +277,9 @@
         break;
     }
     axutil_thread_mutex_lock(mutex);
+
+    axutil_log_impl_rotate(log);
+    
     if (file)
         fprintf(fd, "[%s] %s%s(%d) %s\n", axutil_log_impl_get_time_str(),
                 level_str, file, line, value);
@@ -272,6 +290,40 @@
     axutil_thread_mutex_unlock(mutex);
 }
 
+static axis2_status_t
+axutil_log_impl_rotate(
+    axutil_log_t * log)
+{
+    FILE *old_log_fd = NULL;
+    axis2_char_t old_log_file_name[500];
+    axutil_log_impl_t *log_impl = AXIS2_INTF_TO_IMPL(log);
+    long size = axutil_file_handler_size(log_impl->file_name);
+  
+    printf("size:%ld\n", size); 
+    if(size >= AXUTIL_LOG_FILE_SIZE)
+    {
+        AXIS2_SNPRINTF(old_log_file_name, 500, "%s%s", log_impl->file_name, 
+            ".old");
+        printf("file_name:%s\n", log_impl->file_name ); 
+        printf("old_file_name:%s\n", old_log_file_name); 
+        old_log_fd = axutil_file_handler_open(old_log_file_name, "w");
+        if (!old_log_fd)
+            return;
+        f(!axutil_file_handler_copy(AXIS2_INTF_TO_IMPL(log)->stream, 
+            old_log_fd))
+        {
+            axutil_file_handler_close(old_log_fd);
+            return AXIS2_FAILURE;
+        }
+        axutil_file_handler_close(AXIS2_INTF_TO_IMPL(log)->stream);
+        axutil_file_handler_close(old_log_fd);
+        remove(log_impl->file_name);
+        AXIS2_INTF_TO_IMPL(log)->stream = axutil_file_handler_open(
+            log_impl->file_name, "a+");
+    }
+    return AXIS2_SUCCESS;
+}
+
 AXIS2_EXTERN void AXIS2_CALL
 axutil_log_impl_log_debug(
     axutil_log_t * log,
@@ -304,7 +356,7 @@
             va_start(ap, format);
             AXIS2_VSNPRINTF(value, AXIS2_LEN_VALUE, format, ap);
             va_end(ap);
-            axutil_log_impl_write_to_file(fd, mutex, AXIS2_LOG_LEVEL_DEBUG,
+            axutil_log_impl_write_to_file(log, fd, mutex, AXIS2_LOG_LEVEL_DEBUG,
                                           filename, linenumber, value);
         }
     }
@@ -342,8 +394,8 @@
             va_start(ap, format);
             AXIS2_VSNPRINTF(value, AXIS2_LEN_VALUE, format, ap);
             va_end(ap);
-            axutil_log_impl_write_to_file(fd, mutex, AXIS2_LOG_LEVEL_INFO, NULL,
-                                          -1, value);
+            axutil_log_impl_write_to_file(log, fd, mutex, AXIS2_LOG_LEVEL_INFO, 
+                    NULL, -1, value);
         }
     }
     else
@@ -383,8 +435,8 @@
             va_start(ap, format);
             AXIS2_VSNPRINTF(value, AXIS2_LEN_VALUE, format, ap);
             va_end(ap);
-            axutil_log_impl_write_to_file(fd, mutex, AXIS2_LOG_LEVEL_WARNING,
-                                          filename, linenumber, value);
+            axutil_log_impl_write_to_file(log, fd, mutex, 
+                AXIS2_LOG_LEVEL_WARNING, filename, linenumber, value);
         }
     }
     else
@@ -422,7 +474,7 @@
         va_start(ap, format);
         AXIS2_VSNPRINTF(value, AXIS2_LEN_VALUE, format, ap);
         va_end(ap);
-        axutil_log_impl_write_to_file(fd, mutex, AXIS2_LOG_LEVEL_ERROR,
+        axutil_log_impl_write_to_file(log, fd, mutex, AXIS2_LOG_LEVEL_ERROR,
                                       filename, linenumber, value);
     }
     else
@@ -462,7 +514,7 @@
         va_start(ap, format);
         AXIS2_VSNPRINTF(value, AXIS2_LEN_VALUE, format, ap);
         va_end(ap);
-        axutil_log_impl_write_to_file(fd, mutex, AXIS2_LOG_LEVEL_CRITICAL,
+        axutil_log_impl_write_to_file(log, fd, mutex, AXIS2_LOG_LEVEL_CRITICAL,
                                       filename, linenumber, value);
     }
     else
@@ -559,7 +611,7 @@
             va_start(ap, format);
             AXIS2_VSNPRINTF(value, AXIS2_LEN_VALUE, format, ap);
             va_end(ap);
-            axutil_log_impl_write_to_file(fd, mutex, AXIS2_LOG_LEVEL_TRACE,
+            axutil_log_impl_write_to_file(log, fd, mutex, AXIS2_LOG_LEVEL_TRACE,
                                           filename, linenumber, value);
         }
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org


Mime
View raw message