Merge raw and shared pointer log method impls
Summary: Calling rocksdb::Log, rocksdb::Info, etc with a `shared_ptr<Logger>` should behave the same as calling those functions with a `Logger *`. This PR achieves it by making the `shared_ptr<Logger>` versions delegate to the `Logger *` versions. Closes #3689 Closes https://github.com/facebook/rocksdb/pull/3710 Differential Revision: D7595557 Pulled By: ajkr fbshipit-source-id: 64dd7f20fd42dc821bac7b8032705c35b483e00d
This commit is contained in:
parent
c81b0abedd
commit
1f5457ef21
203
env/env.cc
vendored
203
env/env.cc
vendored
@ -95,15 +95,19 @@ void LogFlush(Logger *info_log) {
|
||||
}
|
||||
}
|
||||
|
||||
void Log(Logger* info_log, const char* format, ...) {
|
||||
static void Logv(Logger *info_log, const char* format, va_list ap) {
|
||||
if (info_log && info_log->GetInfoLogLevel() <= InfoLogLevel::INFO_LEVEL) {
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
info_log->Logv(InfoLogLevel::INFO_LEVEL, format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
}
|
||||
|
||||
void Log(Logger* info_log, const char* format, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
Logv(info_log, format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void Logger::Logv(const InfoLogLevel log_level, const char* format, va_list ap) {
|
||||
static const char* kInfoLogLevelNames[5] = { "DEBUG", "INFO", "WARN",
|
||||
"ERROR", "FATAL" };
|
||||
@ -126,152 +130,161 @@ void Logger::Logv(const InfoLogLevel log_level, const char* format, va_list ap)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Log(const InfoLogLevel log_level, Logger* info_log, const char* format,
|
||||
...) {
|
||||
static void Logv(const InfoLogLevel log_level, Logger *info_log, const char *format, va_list ap) {
|
||||
if (info_log && info_log->GetInfoLogLevel() <= log_level) {
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
|
||||
if (log_level == InfoLogLevel::HEADER_LEVEL) {
|
||||
info_log->LogHeader(format, ap);
|
||||
} else {
|
||||
info_log->Logv(log_level, format, ap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
va_end(ap);
|
||||
void Log(const InfoLogLevel log_level, Logger* info_log, const char* format,
|
||||
...) {
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
Logv(log_level, info_log, format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
static void Headerv(Logger *info_log, const char *format, va_list ap) {
|
||||
if (info_log) {
|
||||
info_log->LogHeader(format, ap);
|
||||
}
|
||||
}
|
||||
|
||||
void Header(Logger* info_log, const char* format, ...) {
|
||||
if (info_log) {
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
info_log->LogHeader(format, ap);
|
||||
va_end(ap);
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
Headerv(info_log, format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
static void Debugv(Logger* info_log, const char* format, va_list ap) {
|
||||
if (info_log && info_log->GetInfoLogLevel() <= InfoLogLevel::DEBUG_LEVEL) {
|
||||
info_log->Logv(InfoLogLevel::DEBUG_LEVEL, format, ap);
|
||||
}
|
||||
}
|
||||
|
||||
void Debug(Logger* info_log, const char* format, ...) {
|
||||
if (info_log && info_log->GetInfoLogLevel() <= InfoLogLevel::DEBUG_LEVEL) {
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
info_log->Logv(InfoLogLevel::DEBUG_LEVEL, format, ap);
|
||||
va_end(ap);
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
Debugv(info_log, format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
static void Infov(Logger* info_log, const char* format, va_list ap) {
|
||||
if (info_log && info_log->GetInfoLogLevel() <= InfoLogLevel::INFO_LEVEL) {
|
||||
info_log->Logv(InfoLogLevel::INFO_LEVEL, format, ap);
|
||||
}
|
||||
}
|
||||
|
||||
void Info(Logger* info_log, const char* format, ...) {
|
||||
if (info_log && info_log->GetInfoLogLevel() <= InfoLogLevel::INFO_LEVEL) {
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
info_log->Logv(InfoLogLevel::INFO_LEVEL, format, ap);
|
||||
va_end(ap);
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
Infov(info_log, format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
static void Warnv(Logger* info_log, const char* format, va_list ap) {
|
||||
if (info_log && info_log->GetInfoLogLevel() <= InfoLogLevel::WARN_LEVEL) {
|
||||
info_log->Logv(InfoLogLevel::WARN_LEVEL, format, ap);
|
||||
}
|
||||
}
|
||||
|
||||
void Warn(Logger* info_log, const char* format, ...) {
|
||||
if (info_log && info_log->GetInfoLogLevel() <= InfoLogLevel::WARN_LEVEL) {
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
info_log->Logv(InfoLogLevel::WARN_LEVEL, format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
Warnv(info_log, format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
void Error(Logger* info_log, const char* format, ...) {
|
||||
|
||||
static void Errorv(Logger* info_log, const char* format, va_list ap) {
|
||||
if (info_log && info_log->GetInfoLogLevel() <= InfoLogLevel::ERROR_LEVEL) {
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
info_log->Logv(InfoLogLevel::ERROR_LEVEL, format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
}
|
||||
void Fatal(Logger* info_log, const char* format, ...) {
|
||||
if (info_log && info_log->GetInfoLogLevel() <= InfoLogLevel::FATAL_LEVEL) {
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
info_log->Logv(InfoLogLevel::FATAL_LEVEL, format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
}
|
||||
|
||||
void LogFlush(const shared_ptr<Logger>& info_log) {
|
||||
if (info_log) {
|
||||
info_log->Flush();
|
||||
void Error(Logger* info_log, const char* format, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
Errorv(info_log, format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
static void Fatalv(Logger* info_log, const char* format, va_list ap) {
|
||||
if (info_log && info_log->GetInfoLogLevel() <= InfoLogLevel::FATAL_LEVEL) {
|
||||
info_log->Logv(InfoLogLevel::FATAL_LEVEL, format, ap);
|
||||
}
|
||||
}
|
||||
|
||||
void Fatal(Logger* info_log, const char* format, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
Fatalv(info_log, format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void LogFlush(const shared_ptr<Logger>& info_log) {
|
||||
LogFlush(info_log.get());
|
||||
}
|
||||
|
||||
void Log(const InfoLogLevel log_level, const shared_ptr<Logger>& info_log,
|
||||
const char* format, ...) {
|
||||
if (info_log) {
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
info_log->Logv(log_level, format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
Logv(log_level, info_log.get(), format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void Header(const shared_ptr<Logger>& info_log, const char* format, ...) {
|
||||
if (info_log) {
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
info_log->LogHeader(format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
Headerv(info_log.get(), format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void Debug(const shared_ptr<Logger>& info_log, const char* format, ...) {
|
||||
if (info_log) {
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
info_log->Logv(InfoLogLevel::DEBUG_LEVEL, format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
Debugv(info_log.get(), format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void Info(const shared_ptr<Logger>& info_log, const char* format, ...) {
|
||||
if (info_log) {
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
info_log->Logv(InfoLogLevel::INFO_LEVEL, format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
Infov(info_log.get(), format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void Warn(const shared_ptr<Logger>& info_log, const char* format, ...) {
|
||||
if (info_log) {
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
info_log->Logv(InfoLogLevel::WARN_LEVEL, format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
Warnv(info_log.get(), format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void Error(const shared_ptr<Logger>& info_log, const char* format, ...) {
|
||||
if (info_log) {
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
info_log->Logv(InfoLogLevel::ERROR_LEVEL, format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
Errorv(info_log.get(), format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void Fatal(const shared_ptr<Logger>& info_log, const char* format, ...) {
|
||||
if (info_log) {
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
info_log->Logv(InfoLogLevel::FATAL_LEVEL, format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
Fatalv(info_log.get(), format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void Log(const shared_ptr<Logger>& info_log, const char* format, ...) {
|
||||
if (info_log) {
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
info_log->Logv(InfoLogLevel::INFO_LEVEL, format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
Logv(info_log.get(), format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
Status WriteStringToFile(Env* env, const Slice& data, const std::string& fname,
|
||||
|
Loading…
Reference in New Issue
Block a user