Пример #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 void AXIS2_CALL
axutil_log_impl_write(
    axutil_log_t *log,
    const axis2_char_t *buffer,
    axutil_log_levels_t level,
    const axis2_char_t *file,
    const int line)
{
    if (log && log->enabled && buffer)
    {
        axutil_log_impl_t *l = AXUTIL_INTF_TO_IMPL(log);
        if (!l->mutex)
            fprintf(stderr, "Log mutex is not found\n");
        if (!l->stream)
            fprintf(stderr, "Stream is not found\n");
        if(level <= log->level || level == AXIS2_LOG_LEVEL_CRITICAL)
        {
            axutil_log_impl_write_to_file(log, l->mutex, level, file, line, buffer);
        }
    }
#ifndef AXIS2_NO_LOG_FILE
    else if (buffer)
        fprintf(stderr, "please check your log and buffer");
#endif
    else
        fprintf(stderr, "please check your log and buffer");
}
Пример #3
0
AXIS2_EXTERN void AXIS2_CALL
axutil_log_impl_write_to_file(
    axutil_log_t *log,
    axutil_thread_mutex_t *mutex,
    axutil_log_levels_t level,
    const axis2_char_t *file,
    const int line,
    const axis2_char_t *value)
{
    const char *level_str = "";
    axutil_log_impl_t *log_impl = AXUTIL_INTF_TO_IMPL(log);
    FILE *fd = NULL;

    /**
       * print all critical and error logs irrespective of log->level setting
      */

    switch (level)
    {
    case AXIS2_LOG_LEVEL_CRITICAL:
        level_str = "[critical] ";
        break;
    case AXIS2_LOG_LEVEL_ERROR:
        level_str = "[error] ";
        break;
    case AXIS2_LOG_LEVEL_WARNING:
        level_str = "[warning] ";
        break;
    case AXIS2_LOG_LEVEL_INFO:
        level_str = "[info] ";
        break;
    case AXIS2_LOG_LEVEL_DEBUG:
        level_str = "[debug] ";
        break;
    case AXIS2_LOG_LEVEL_TRACE:
        level_str = "[...TRACE...] ";
        break;
    case AXIS2_LOG_LEVEL_USER:
        break;
    }
    axutil_thread_mutex_lock(mutex);

    axutil_log_impl_rotate(log);
    fd = log_impl->stream;
   
    if (fd)
    {
        if (file)
            fprintf(fd, "[%s] %s%s(%d) %s\n", axutil_log_impl_get_time_str(),
                level_str, file, line, value);
        else
            fprintf(fd, "[%s] %s %s\n", axutil_log_impl_get_time_str(), level_str,
                value);
        fflush(fd);
    }
    axutil_thread_mutex_unlock(mutex);
}
Пример #4
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;
}