예제 #1
0
파일: log_win32.c 프로젝트: larsonmpdx/grpc
void gpr_log(const char *file, int line, gpr_log_severity severity,
             const char *format, ...) {
    char *message = NULL;
    va_list args;
    int ret;

    /* Determine the length. */
    va_start(args, format);
    ret = _vscprintf(format, args);
    va_end(args);
    if (ret < 0) {
        message = NULL;
    } else {
        /* Allocate a new buffer, with space for the NUL terminator. */
        size_t strp_buflen = (size_t)ret + 1;
        message = gpr_malloc(strp_buflen);

        /* Print to the buffer. */
        va_start(args, format);
        ret = vsnprintf_s(message, strp_buflen, _TRUNCATE, format, args);
        va_end(args);
        if ((size_t)ret != strp_buflen - 1) {
            /* This should never happen. */
            gpr_free(message);
            message = NULL;
        }
    }

    gpr_log_message(file, line, severity, message);
    gpr_free(message);
}
예제 #2
0
void gpr_log(const char *file, int line, gpr_log_severity severity,
             const char *format, ...) {
  char *message = NULL;
  va_list args;
  va_start(args, format);
  vasprintf(&message, format, args);
  va_end(args);
  gpr_log_message(file, line, severity, message);
  free(message);
}
예제 #3
0
파일: log_test.c 프로젝트: Abioy/kythe
int main(int argc, char **argv) {
  grpc_test_init(argc, argv);
  /* test logging at various verbosity levels */
  gpr_log(GPR_DEBUG, "%s", "hello world");
  gpr_log(GPR_INFO, "%s", "hello world");
  gpr_log(GPR_ERROR, "%s", "hello world");
  /* should succeed */
  GPR_ASSERT(1);
  gpr_set_log_function(test_callback);
  gpr_log_message(GPR_INFO, "hello 1 2 3");
  gpr_log(GPR_INFO, "hello %d %d %d", 1, 2, 3);
  /* TODO(ctiller): should we add a GPR_ASSERT failure test here */
  return 0;
}
예제 #4
0
void gpr_log(const char *file, int line, gpr_log_severity severity,
             const char *format, ...) {
  char *message = NULL;
  va_list args;
  va_start(args, format);
  if (vasprintf(&message, format, args) == -1) {
    va_end(args);
    return;
  }
  va_end(args);
  gpr_log_message(file, line, severity, message);
  /* message has been allocated by vasprintf above, and needs free */
  free(message);
}
예제 #5
0
파일: log_posix.c 프로젝트: Indifer/grpc
void gpr_log(const char *file, int line, gpr_log_severity severity,
             const char *format, ...) {
  char buf[64];
  char *allocated = NULL;
  char *message = NULL;
  int ret;
  va_list args;
  va_start(args, format);
  ret = vsnprintf(buf, sizeof(buf), format, args);
  va_end(args);
  if (ret < 0) {
    message = NULL;
  } else if ((size_t)ret <= sizeof(buf) - 1) {
    message = buf;
  } else {
    message = allocated = gpr_malloc((size_t)ret + 1);
    va_start(args, format);
    vsnprintf(message, (size_t)(ret + 1), format, args);
    va_end(args);
  }
  gpr_log_message(file, line, severity, message);
  gpr_free(allocated);
}