Version 17 plus test updates and OPK v17
This is the first public release of OPK v17. See the file CHANGELOG.md for details.
This commit is contained in:
62
linux/src/log.cpp
Normal file
62
linux/src/log.cpp
Normal file
@@ -0,0 +1,62 @@
|
||||
// Copyright 2013 Google Inc. All Rights Reserved.
|
||||
//
|
||||
// Log - implemented using stdout.
|
||||
|
||||
#include "log.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
namespace {
|
||||
|
||||
FILE* const kOutputFile = stdout;
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace wvutil {
|
||||
|
||||
LogPriority g_cutoff = CDM_LOG_WARN;
|
||||
|
||||
void InitLogging() {
|
||||
// Note: The default log level is CDM_LOG_WARN, above. If you set the
|
||||
// environment variable VERBOSE_LOG, you will get verbose logging. This is
|
||||
// set by jenkins (http://go/wvbuild), so that we have more details when the
|
||||
// build breaks.
|
||||
const char* verbose_env = getenv("VERBOSE_LOG");
|
||||
if (verbose_env && !strncmp(verbose_env, "yes", 3) ) {
|
||||
g_cutoff = CDM_LOG_VERBOSE;
|
||||
}
|
||||
}
|
||||
|
||||
void Log(const char* file, const char* function, int line, LogPriority level,
|
||||
const char* fmt, ...) {
|
||||
const char* severities[] = { "ERROR", "WARN", "INFO", "DEBUG", "VERBOSE" };
|
||||
if (level >=
|
||||
static_cast<LogPriority>(sizeof(severities) / sizeof(*severities))) {
|
||||
fprintf(kOutputFile, "[FATAL:%s(%d):%s] Invalid log priority level: %d\n",
|
||||
file, line, function, level);
|
||||
return;
|
||||
}
|
||||
if (level > g_cutoff) return;
|
||||
|
||||
// Strip off the the leading "../" that clutters the logs.
|
||||
const char * up_dir = "../";
|
||||
const size_t up_dir_size = strlen(up_dir);
|
||||
while (strncmp(up_dir, file, up_dir_size) == 0) file += up_dir_size;
|
||||
|
||||
|
||||
fprintf(kOutputFile, "[%s:%s(%d):%s] ", severities[level], file, line,
|
||||
function);
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
vfprintf(kOutputFile, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
putc('\n', kOutputFile);
|
||||
fflush(kOutputFile);
|
||||
}
|
||||
|
||||
} // namespace wvutil
|
||||
Reference in New Issue
Block a user