Initial source release: v2.0.8-0-679
Change-Id: Idf6316a8faf4b4fdc54265aad12084e5aa60707a
This commit is contained in:
43
linux/src/log.cpp
Normal file
43
linux/src/log.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
// 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
|
||||
Reference in New Issue
Block a user