44 lines
1.0 KiB
C++
44 lines
1.0 KiB
C++
// Copyright 2013 Google Inc. All Rights Reserved.
|
|
//
|
|
// Log - implemented using stdout.
|
|
//
|
|
#define LOG_BUF_SIZE 4096
|
|
|
|
#include <stdarg.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include "log.h"
|
|
|
|
namespace wvcdm {
|
|
|
|
static LogPriority g_cutoff = LOG_WARN;
|
|
|
|
void InitLogging(int argc, const char* const* argv) {
|
|
for (int i = 1; i < argc; i++) {
|
|
if (strncmp(argv[i], "-v", 2) == 0) {
|
|
g_cutoff = LOG_VERBOSE;
|
|
}
|
|
}
|
|
}
|
|
|
|
void Log(const char* file, int line, LogPriority level, const char* fmt, ...) {
|
|
const char* severities[] = { "ERROR", "WARN", "INFO", "DEBUG", "VERBOSE" };
|
|
if (level >= sizeof(severities) / sizeof(*severities)) {
|
|
printf("[FATAL:%s(%d)] Invalid log priority level: %d\n", file, line,
|
|
level);
|
|
return;
|
|
}
|
|
if (level > g_cutoff) return;
|
|
|
|
va_list ap;
|
|
char buf[LOG_BUF_SIZE];
|
|
va_start(ap, fmt);
|
|
vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
|
|
va_end(ap);
|
|
printf("[%s:%s(%d)] ", severities[level], file, line);
|
|
fputs(buf, stdout);
|
|
putc('\n', stdout);
|
|
}
|
|
|
|
}; // namespace wvcdm
|