// Copyright 2013 Google Inc. All Rights Reserved. // // Log - implemented using stdout. #include "log.h" #include #include #include #include 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) == 0) { 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 < 0 || static_cast(level) >= sizeof(severities) / sizeof(severities[0])) { 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 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