This source file includes following definitions.
- initializeLogFileOnce
- initializeLogFile
- dataFile
- dataLogFV
- dataLogF
- dataLogFString
#include "config.h"
#include "DataLog.h"
#if OS(POSIX)
#include <pthread.h>
#include <unistd.h>
#endif
#define DATA_LOG_TO_FILE 0
#define DATA_LOG_FILENAME "/tmp/WTFLog"
namespace WTF {
#if USE(PTHREADS)
static pthread_once_t initializeLogFileOnceKey = PTHREAD_ONCE_INIT;
#endif
static FilePrintStream* file;
static void initializeLogFileOnce()
{
#if DATA_LOG_TO_FILE
#ifdef DATA_LOG_FILENAME
const char* filename = DATA_LOG_FILENAME;
#else
const char* filename = getenv("WTF_DATA_LOG_FILENAME");
#endif
char actualFilename[1024];
snprintf(actualFilename, sizeof(actualFilename), "%s.%d.txt", filename, getpid());
if (filename) {
file = FilePrintStream::open(actualFilename, "w").leakPtr();
if (!file)
fprintf(stderr, "Warning: Could not open log file %s for writing.\n", actualFilename);
}
#endif
if (!file)
file = new FilePrintStream(stderr, FilePrintStream::Borrow);
setvbuf(file->file(), 0, _IONBF, 0);
}
static void initializeLogFile()
{
#if USE(PTHREADS)
pthread_once(&initializeLogFileOnceKey, initializeLogFileOnce);
#else
if (!file)
initializeLogFileOnce();
#endif
}
FilePrintStream& dataFile()
{
initializeLogFile();
return *file;
}
void dataLogFV(const char* format, va_list argList)
{
dataFile().vprintf(format, argList);
}
void dataLogF(const char* format, ...)
{
va_list argList;
va_start(argList, format);
dataLogFV(format, argList);
va_end(argList);
}
void dataLogFString(const char* str)
{
dataFile().printf("%s", str);
}
}