Files
ce_cdm/linux/src/log.cpp
Joey Parrish 66794025d4 Initial source release: v2.0.8-0-679
Change-Id: Idf6316a8faf4b4fdc54265aad12084e5aa60707a
2014-05-20 11:08:09 -07:00

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