Example #1
0
static void materialize_deps(noit_log_stream_t ls) {
  if(ls->deps_materialized) return;
  if(ls->debug) ls->debug_below = 1;
  if(ls->timestamps) ls->timestamps_below = 1;
  if(ls->debug_below == 0 || ls->timestamps_below == 0) {
    /* we might have children than need these */
    struct _noit_log_stream_outlet_list *node;
    for(node = ls->outlets; node; node = node->next) {
      MATERIALIZE_DEPS(node->outlet);
      if(!ls->debug) ls->debug_below = node->outlet->debug_below;
      if(!ls->timestamps) ls->timestamps_below = node->outlet->timestamps_below;
    }
  }
  ls->deps_materialized = 1;
}
Example #2
0
static void materialize_deps(noit_log_stream_t ls) {
  struct _noit_log_stream_outlet_list *node;
  if(ls->deps_materialized) {
    debug_printf("materialize(%s) [already done]\n", ls->name);
    return;
  }
  /* pass forward all but enabled */
  ls->flags_below |= (ls->flags & NOIT_LOG_STREAM_FEATURES);

  /* we might have children than need these */
  for(node = ls->outlets; node; node = node->next) {
    MATERIALIZE_DEPS(node->outlet);
    /* our flags_below should be augments with our outlets flags_below
       unless we have them in our flags already */
    ls->flags_below |= (~(ls->flags) & NOIT_LOG_STREAM_FEATURES) &
                       node->outlet->flags_below;
    debug_printf("materialize(%s) |= (%s) %x\n", ls->name,
                 node->outlet->name,
                 node->outlet->flags_below & NOIT_LOG_STREAM_FEATURES);
  }
  debug_printf("materialize(%s) -> %x\n", ls->name, ls->flags_below);
  ls->deps_materialized = 1;
}
Example #3
0
int
noit_vlog(noit_log_stream_t ls, struct timeval *now,
          const char *file, int line,
          const char *format, va_list arg) {
  int rv = 0, allocd = 0;
  char buffer[4096], *dynbuff = NULL;
#ifdef va_copy
  va_list copy;
#endif

  if(ls->enabled || NOIT_LOG_LOG_ENABLED()) {
    int len;
    char tbuf[48], dbuf[80];
    int tbuflen = 0, dbuflen = 0;
    MATERIALIZE_DEPS(ls);
    if(ls->timestamps_below) {
      struct tm _tm, *tm;
      char tempbuf[32];
      time_t s = (time_t)now->tv_sec;
      tm = localtime_r(&s, &_tm);
      strftime(tempbuf, sizeof(tempbuf), "%Y-%m-%d %H:%M:%S", tm);
      snprintf(tbuf, sizeof(tbuf), "[%s.%06d] ", tempbuf, (int)now->tv_usec);
      tbuflen = strlen(tbuf);
    }
    else tbuf[0] = '\0';
    if(ls->debug_below) {
      snprintf(dbuf, sizeof(dbuf), "[%s:%d] ", file, line);
      dbuflen = strlen(dbuf);
    }
    else dbuf[0] = '\0';
#ifdef va_copy
    va_copy(copy, arg);
    len = vsnprintf(buffer, sizeof(buffer), format, copy);
    va_end(copy);
#else
    len = vsnprintf(buffer, sizeof(buffer), format, arg);
#endif
    if(len > sizeof(buffer)) {
      allocd = sizeof(buffer);
      while(len > allocd) { /* guaranteed true the first time */
        while(len > allocd) allocd <<= 2;
        if(dynbuff) free(dynbuff);
        dynbuff = malloc(allocd);
        assert(dynbuff);
#ifdef va_copy
        va_copy(copy, arg);
        len = vsnprintf(dynbuff, allocd, format, copy);
        va_end(copy);
#else
        len = vsnprintf(dynbuff, allocd, format, arg);
#endif
      }
      NOIT_LOG_LOG(ls->name, (char *)file, line, dynbuff);
      if(ls->enabled)
        rv = noit_log_line(ls, tbuf, tbuflen, dbuf, dbuflen, dynbuff, len);
      free(dynbuff);
    }
    else {
      NOIT_LOG_LOG(ls->name, (char *)file, line, buffer);
      if(ls->enabled)
        rv = noit_log_line(ls, tbuf, tbuflen, dbuf, dbuflen, buffer, len);
    }
    if(rv == len) return 0;
    return -1;
  }
  return 0;
}