Source release v2.2.0-0-903 + third_party libs

Change-Id: I03f670eaeb052bc741abb347be06f8ddc58418e7
This commit is contained in:
Joey Parrish
2014-12-15 10:35:08 -08:00
parent 5318232d46
commit 1955c9c2c9
85 changed files with 5594 additions and 2830 deletions

View File

@@ -9,16 +9,35 @@
#include "log.h"
namespace {
FILE* output_file = stdout;
} // namespace
namespace wvcdm {
LogPriority g_cutoff = LOG_WARN;
void InitLogging(int argc, const char* const* argv) {
// default to stdout if no arguments set it otherwise.
output_file = stdout;
for (int i = 1; i < argc; i++) {
if (strncmp(argv[i], "-v", 2) == 0) {
if (!strcmp(argv[i], "-v")) {
g_cutoff = LOG_VERBOSE;
} else if (!strcmp(argv[i], "-")) {
// default above is stdout, so keep that.
} else {
// open a file for output.
output_file = fopen(argv[i], "a");
if (!output_file) {
output_file = stdout;
printf("Could not open log file \"%s\"\n", argv[i]);
}
}
}
const char *verbose_env = getenv("VERBOSE_LOG");
if (verbose_env && ! strncmp(verbose_env, "yes", 3) ) {
g_cutoff = LOG_VERBOSE;
@@ -28,20 +47,21 @@ void InitLogging(int argc, const char* const* argv) {
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);
fprintf(output_file, "[FATAL:%s(%d)] Invalid log priority level: %d\n",
file, line, level);
return;
}
if (level > g_cutoff) return;
printf("[%s:%s(%d)] ", severities[level], file, line);
fprintf(output_file, "[%s:%s(%d)] ", severities[level], file, line);
va_list ap;
va_start(ap, fmt);
vprintf(fmt, ap);
vfprintf(output_file, fmt, ap);
va_end(ap);
putc('\n', stdout);
putc('\n', output_file);
fflush(output_file);
}
}; // namespace wvcdm