From 1f5457ef2119ed2ef63984ab75552dbbf6c4a3f2 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Fri, 13 Apr 2018 10:58:25 -0700 Subject: [PATCH] Merge raw and shared pointer log method impls Summary: Calling rocksdb::Log, rocksdb::Info, etc with a `shared_ptr` should behave the same as calling those functions with a `Logger *`. This PR achieves it by making the `shared_ptr` 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 --- env/env.cc | 187 ++++++++++++++++++++++++++++------------------------- 1 file changed, 100 insertions(+), 87 deletions(-) diff --git a/env/env.cc b/env/env.cc index 9f165d6d1..56c0bd893 100644 --- a/env/env.cc +++ b/env/env.cc @@ -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 Header(Logger* info_log, const char* format, ...) { +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) { - va_list ap; - va_start(ap, format); info_log->LogHeader(format, ap); - va_end(ap); } } -void Debug(Logger* info_log, const char* format, ...) { +void Header(Logger* info_log, const char* format, ...) { + 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) { - va_list ap; - va_start(ap, format); info_log->Logv(InfoLogLevel::DEBUG_LEVEL, format, ap); - va_end(ap); } } -void Info(Logger* info_log, const char* format, ...) { +void Debug(Logger* info_log, const char* format, ...) { + 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) { - va_list ap; - va_start(ap, format); info_log->Logv(InfoLogLevel::INFO_LEVEL, format, ap); - va_end(ap); } } -void Warn(Logger* info_log, const char* format, ...) { +void Info(Logger* info_log, const char* format, ...) { + 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) { - va_list ap; - va_start(ap, format); info_log->Logv(InfoLogLevel::WARN_LEVEL, format, ap); - va_end(ap); } } -void Error(Logger* info_log, const char* format, ...) { + +void Warn(Logger* info_log, const char* format, ...) { + va_list ap; + va_start(ap, format); + Warnv(info_log, format, ap); + va_end(ap); +} + +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, ...) { + +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) { - va_list ap; - va_start(ap, format); info_log->Logv(InfoLogLevel::FATAL_LEVEL, format, ap); - va_end(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& info_log) { - if (info_log) { - info_log->Flush(); - } + LogFlush(info_log.get()); } void Log(const InfoLogLevel log_level, const shared_ptr& 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& 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& 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& 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& 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& 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& 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& 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,