This source file includes following definitions.
- LogSeverityToString
- ClearLog
- Log
- GetLogHistory
#include "chrome/browser/sync_file_system/logger.h"
#include "base/file_util.h"
#include "base/lazy_instance.h"
#include "base/location.h"
#include "base/strings/stringprintf.h"
#include "chrome/browser/drive/event_logger.h"
namespace sync_file_system {
namespace util {
namespace {
static base::LazyInstance<drive::EventLogger> g_logger =
LAZY_INSTANCE_INITIALIZER;
const char* LogSeverityToString(logging::LogSeverity level) {
switch (level) {
case logging::LOG_ERROR:
return "ERROR";
case logging::LOG_WARNING:
return "WARNING";
case logging::LOG_INFO:
return "INFO";
case logging::LOG_VERBOSE:
return "VERBOSE";
}
NOTREACHED();
return "Unknown Log Severity";
}
}
void ClearLog() {
g_logger.Pointer()->SetHistorySize(drive::kDefaultHistorySize);
}
void Log(logging::LogSeverity severity,
const tracked_objects::Location& location,
const char* format,
...) {
std::string what;
va_list args;
va_start(args, format);
base::StringAppendV(&what, format, args);
va_end(args);
drive::EventLogger* ptr = g_logger.Pointer();
ptr->LogRawString(severity, base::StringPrintf("[%s] %s",
LogSeverityToString(severity),
what.c_str()));
if (severity < logging::GetMinLogLevel() && !VLOG_IS_ON(1))
return;
logging::LogMessage(location.file_name(), location.line_number(), severity)
.stream() << what;
}
std::vector<drive::EventLogger::Event> GetLogHistory() {
drive::EventLogger* ptr = g_logger.Pointer();
return ptr->GetHistory();
}
}
}