示例#1
0
static void AXIS2_CALL
axutil_log_impl_free(
    axutil_allocator_t *allocator,
    axutil_log_t *log)
{
    axutil_log_impl_t *log_impl = NULL;

    if (log)
    {
        log_impl = AXUTIL_INTF_TO_IMPL(log);

        if (log_impl->mutex)
        {
            axutil_thread_mutex_destroy(log_impl->mutex);
        }
        if (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);
    }
}
示例#2
0
static axis2_status_t
axutil_log_impl_rotate(
    axutil_log_t *log)
{
    long size = -1;
    FILE *old_log_fd = NULL;
    axis2_char_t old_log_file_name[AXUTIL_LOG_FILE_NAME_SIZE];
    axutil_log_impl_t *log_impl = AXUTIL_INTF_TO_IMPL(log);

    /*If the log stream is a file*/
    if(log_impl->stream_type == AXUTIL_LOG_FILE)
    {
        if(log_impl->file_name)
            size = axutil_file_handler_size(log_impl->file_name);

        if(size >= log->size)
        {
            AXIS2_SNPRINTF(old_log_file_name, AXUTIL_LOG_FILE_NAME_SIZE, "%s%s", log_impl->file_name,
                ".old");
            axutil_file_handler_close(log_impl->stream);
            old_log_fd = axutil_file_handler_open(old_log_file_name, "w+");
            log_impl->stream = axutil_file_handler_open(log_impl->file_name, "r");
            if(old_log_fd && log_impl->stream)
            {
                axutil_file_handler_copy(log_impl->stream, old_log_fd);
                axutil_file_handler_close(old_log_fd);
                axutil_file_handler_close(log_impl->stream);
                old_log_fd = NULL;
                log_impl->stream = NULL;
            }
            if(old_log_fd)
            {
                axutil_file_handler_close(old_log_fd);
            }
            if(log_impl->stream)
            {
                axutil_file_handler_close(log_impl->stream);
            }
            log_impl->stream = axutil_file_handler_open(log_impl->file_name, "w+");
        }
    }
    return AXIS2_SUCCESS;
}