예제 #1
0
static int
noit_log_line(noit_log_stream_t ls,
              const char *timebuf, int timebuflen,
              const char *debugbuf, int debugbuflen,
              const char *buffer, size_t len) {
  int rv = 0;
  struct _noit_log_stream_outlet_list *node;
  if(ls->ops) {
    int iovcnt = 0;
    struct iovec iov[3];
    if(ls->timestamps) {
      iov[iovcnt].iov_base = (void *)timebuf;
      iov[iovcnt].iov_len = timebuflen;
      iovcnt++;
    }
    if(ls->debug) {
      iov[iovcnt].iov_base = (void *)debugbuf;
      iov[iovcnt].iov_len = debugbuflen;
      iovcnt++;
    }
    iov[iovcnt].iov_base = (void *)buffer;
    iov[iovcnt].iov_len = len;
    iovcnt++;
    rv = noit_log_writev(ls, iov, iovcnt);
  }
  for(node = ls->outlets; node; node = node->next) {
    int srv = 0;
    debug_printf(" %s -> %s\n", ls->name, node->outlet->name);
    srv = noit_log_line(node->outlet, timebuf, timebuflen, debugbuf, debugbuflen, buffer, len);
    if(srv) rv = srv;
  }
  return rv;
}
예제 #2
0
static int
noit_log_line(noit_log_stream_t ls, noit_log_stream_t bitor,
              struct timeval *whence,
              const char *timebuf, int timebuflen,
              const char *debugbuf, int debugbuflen,
              const char *buffer, size_t len) {
  int rv = 0;
  struct _noit_log_stream_outlet_list *node;
  struct _noit_log_stream bitor_onstack;
  memcpy(&bitor_onstack, ls, sizeof(bitor_onstack));
  if(bitor) {
    bitor_onstack.name = bitor->name;
    bitor_onstack.flags |= bitor->flags & NOIT_LOG_STREAM_FACILITY;
  }
  bitor = &bitor_onstack;
  if(ls->ops) {
    int iovcnt = 0;
    struct iovec iov[6];
    if(IS_TIMESTAMPS_ON(bitor)) {
      iov[iovcnt].iov_base = (void *)timebuf;
      iov[iovcnt].iov_len = timebuflen;
      iovcnt++;
    }
    if(IS_FACILITY_ON(bitor)) {
      iov[iovcnt].iov_base = (void *)"[";
      iov[iovcnt].iov_len = 1;
      iovcnt++;
      iov[iovcnt].iov_base = (void *)bitor->name;
      iov[iovcnt].iov_len = strlen(bitor->name);
      iovcnt++;
      iov[iovcnt].iov_base = (void *)"] ";
      iov[iovcnt].iov_len = 2;
      iovcnt++;
    }
    if(IS_DEBUG_ON(bitor)) {
      iov[iovcnt].iov_base = (void *)debugbuf;
      iov[iovcnt].iov_len = debugbuflen;
      iovcnt++;
    }
    iov[iovcnt].iov_base = (void *)buffer;
    iov[iovcnt].iov_len = len;
    iovcnt++;
    rv = noit_log_writev(ls, whence, iov, iovcnt);
  }
  for(node = ls->outlets; node; node = node->next) {
    int srv = 0;
    debug_printf(" %s -> %s\n", ls->name, node->outlet->name);
    srv = noit_log_line(node->outlet, bitor, whence, timebuf,
                        timebuflen, debugbuf, debugbuflen, buffer, len);
    if(srv) rv = srv;
  }
  return rv;
}