Ejemplo n.º 1
0
void CSFLogV(CSFLogLevel priority, const char* sourceFile, int sourceLine, const char* tag , const char* format, va_list args)
{
#ifdef STDOUT_LOGGING
  printf("%s\n:",tag);
  vprintf(format, args);
#else

  mozilla::LogLevel level = static_cast<mozilla::LogLevel>(priority);

  GetSignalingLogInfo();

  // Skip doing any of this work if we're not logging the indicated level...
  if (!MOZ_LOG_TEST(gLogModuleInfo,level)) {
    return;
  }

  // Trim the path component from the filename
  const char *lastSlash = sourceFile;
  while (*sourceFile) {
    if (*sourceFile == '/' || *sourceFile == '\\') {
      lastSlash = sourceFile;
    }
    sourceFile++;
  }
  sourceFile = lastSlash;
  if (*sourceFile == '/' || *sourceFile == '\\') {
    sourceFile++;
  }

#define MAX_MESSAGE_LENGTH 1024
  char message[MAX_MESSAGE_LENGTH];

  const char *threadName = NULL;

  // Check if we're the main thread...
  if (NS_IsMainThread()) {
    threadName = "main";
  } else {
    threadName = PR_GetThreadName(PR_GetCurrentThread());
  }

  // If we can't find it anywhere, use a blank string
  if (!threadName) {
    threadName = "";
  }

  VsprintfLiteral(message, format, args);
  MOZ_LOG(gLogModuleInfo, level, ("[%s|%s] %s:%d: %s",
                                  threadName, tag, sourceFile, sourceLine,
                                  message));
#endif

}
Ejemplo n.º 2
0
void CSFLogV(CSFLogLevel priority, const char* sourceFile, int sourceLine, const char* tag , const char* format, va_list args)
{
#ifdef STDOUT_LOGGING
  printf("%s\n:",tag);
  vprintf(format, args);
#else

  PRLogModuleLevel level = static_cast<PRLogModuleLevel>(priority);

  GetSignalingLogInfo();

  // Skip doing any of this work if we're not logging the indicated level...
  if (!PR_LOG_TEST(gLogModuleInfo,level)) {
    return;
  }

  // Trim the path component from the filename
  const char *lastSlash = sourceFile;
  while (*sourceFile) {
    if (*sourceFile == '/' || *sourceFile == '\\') {
      lastSlash = sourceFile;
    }
    sourceFile++;
  }
  sourceFile = lastSlash;
  if (*sourceFile == '/' || *sourceFile == '\\') {
    sourceFile++;
  }

#define MAX_MESSAGE_LENGTH 1024
  char message[MAX_MESSAGE_LENGTH];
  char buffer[64] = "";

  const char *threadName = CSFCurrentThreadName();

  // Check if we're the main thread...
  if (!threadName && NS_IsMainThread()) {
    threadName = "main";
  }

  // If null, the name wasn't set up by CPR -- try NSPR
  if (!threadName) {
    threadName = PR_GetThreadName(PR_GetCurrentThread());
  }

  // If not NSPR, it might be from some other imported library that uses
  // one of the variety of non-portable means of naming threads.
#ifdef OS_LINUX
  if (!threadName &&
    !prctl(PR_GET_NAME,reinterpret_cast<uintptr_t>(buffer),0,0,0)) {
    buffer[16]='\0';
    if (buffer[0] != '\0') {
      threadName = buffer;
    }
  }
#endif
#ifdef OS_MACOSX
  if (!threadName && have_pthread_getname_np) {
    dynamic_pthread_getname_np(pthread_self(), buffer, sizeof(buffer));
    if (buffer[0] != '\0') {
      threadName = buffer;
    }
  }
#endif

  // If we can't find it anywhere, use a blank string
  if (!threadName) {
    threadName = "";
  }

  vsnprintf(message, MAX_MESSAGE_LENGTH, format, args);
  PR_LOG(gLogModuleInfo, level, ("[%s|%s] %s:%d: %s",
                                  threadName, tag, sourceFile, sourceLine,
                                  message));
#endif

}