Logo Search packages:      
Sourcecode: log4c version File versions  Download package

LOG4C_API void __log4c_category_vlog ( const log4c_category_t a_category,
const log4c_location_info_t a_locinfo,
int  a_priority,
const char *  a_format,
va_list  a_args 
)

For internal use only.

Definition at line 206 of file category.c.

References log4c_buffer_t::buf_data, log4c_buffer_t::buf_maxsize, log4c_buffer_t::buf_size, log4c_rc_t::bufsize, log4c_rc_t::config, log4c_logging_event_t::evt_buffer, log4c_logging_event_t::evt_category, log4c_logging_event_t::evt_loc, log4c_logging_event_t::evt_msg, log4c_logging_event_t::evt_priority, log4c_logging_event_t::evt_timestamp, and log4c_rc.

{
  char* message;
  log4c_logging_event_t evt;
  const log4c_category_t* cat;
  int yes = 0;
  
  if (!this)
    return;
  
  /* check if an appender is defined in the category hierarchy */
  for (cat = this; cat; cat = cat->cat_parent) {
    if (cat->cat_appender)
          yes++;
  }
  
  if (!yes)
    return;

  log4c_reread();

  /* when there is no limit on the buffer size, we use malloc() to
  * give the user the possiblity to reallocate if necessary. When
  * the buffer is limited in size, we use alloca() for more
  * efficiency.
  */
  evt.evt_buffer.buf_maxsize = log4c_rc->config.bufsize;
  
  if (!evt.evt_buffer.buf_maxsize) {
    evt.evt_buffer.buf_size = LOG4C_BUFFER_SIZE_DEFAULT;
    evt.evt_buffer.buf_data = sd_malloc(evt.evt_buffer.buf_size);
    message = sd_vsprintf(a_format, a_args);
  }
  else {
    size_t n;
    
    evt.evt_buffer.buf_size = evt.evt_buffer.buf_maxsize;
    evt.evt_buffer.buf_data = alloca(evt.evt_buffer.buf_size);
    message = alloca(evt.evt_buffer.buf_size);
    
    if ( (n = (size_t)vsnprintf(message, evt.evt_buffer.buf_size, a_format, a_args))
      >= evt.evt_buffer.buf_size)
    sd_error("truncating message of %d bytes (bufsize = %d)", n, 
      evt.evt_buffer.buf_size);
  }
  
  evt.evt_category      = this->cat_name;
  evt.evt_priority      = a_priority;
  evt.evt_msg             = message;
  evt.evt_loc             = a_locinfo;
  SD_GETTIMEOFDAY(&evt.evt_timestamp, NULL);
  
  for (cat = this; cat; cat = cat->cat_parent) {
    if (cat->cat_appender)
          log4c_appender_append(cat->cat_appender, &evt);
    
    if (!cat->cat_additive) break;  
  }
  
  if (!evt.evt_buffer.buf_maxsize) {
    free(message);
    free(evt.evt_buffer.buf_data);
  }
}


Generated by  Doxygen 1.6.0   Back to index