From 14edf49084edcc2c749c9275eb99d2a5bd52197d Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 11 Feb 2018 18:37:30 +0300 Subject: [PATCH] Remove printf-like logging. GitOrigin-RevId: 359e29aea05ee57eff7ab1feec134cbd9cbdabc9 --- tdutils/td/utils/StringBuilder.cpp | 23 ----------------- tdutils/td/utils/StringBuilder.h | 5 ---- tdutils/td/utils/logging.cpp | 18 +++---------- tdutils/td/utils/logging.h | 41 +++++++++++++----------------- 4 files changed, 20 insertions(+), 67 deletions(-) diff --git a/tdutils/td/utils/StringBuilder.cpp b/tdutils/td/utils/StringBuilder.cpp index 92131503..7b8681ef 100644 --- a/tdutils/td/utils/StringBuilder.cpp +++ b/tdutils/td/utils/StringBuilder.cpp @@ -98,27 +98,4 @@ StringBuilder &StringBuilder::operator<<(const void *ptr) { return *this; } -void StringBuilder::vprintf(const char *fmt, va_list list) { - if (unlikely(end_ptr_ < current_ptr_)) { - on_error(); - return; - } - - auto left = end_ptr_ + reserved_size - current_ptr_; - int len = std::vsnprintf(current_ptr_, left, fmt, list); - if (unlikely(len >= left)) { - error_flag_ = true; - current_ptr_ += left - 1; - } else { - current_ptr_ += len; - } -} - -void StringBuilder::printf(const char *fmt, ...) { - va_list list; - va_start(list, fmt); - vprintf(fmt, list); - va_end(list); -} - } // namespace td diff --git a/tdutils/td/utils/StringBuilder.h b/tdutils/td/utils/StringBuilder.h index ac4508a5..a6345a92 100644 --- a/tdutils/td/utils/StringBuilder.h +++ b/tdutils/td/utils/StringBuilder.h @@ -10,7 +10,6 @@ #include "td/utils/Slice-decl.h" #include "td/utils/StackAllocator.h" -#include #include #include #include @@ -114,10 +113,6 @@ class StringBuilder { return *this << static_cast(ptr); } - void vprintf(const char *fmt, va_list list); - - void printf(const char *fmt, ...) TD_ATTRIBUTE_FORMAT_PRINTF(2, 3); - private: char *begin_ptr_; char *current_ptr_; diff --git a/tdutils/td/utils/logging.cpp b/tdutils/td/utils/logging.cpp index 9a488825..f0e2927a 100644 --- a/tdutils/td/utils/logging.cpp +++ b/tdutils/td/utils/logging.cpp @@ -13,7 +13,6 @@ #include "td/utils/Time.h" #include -#include #include #if TD_ANDROID @@ -62,12 +61,12 @@ Logger::Logger(LogInterface &log, int log_level, Slice file_name, int line_num, if (log_level < 10) { (*this) << ' '; } - (*this) << log_level << '][t'; + (*this) << log_level << "][t"; if (thread_id < 10) { (*this) << ' '; } - (*this) << thread_id << ']' << StringBuilder::FixedDouble(Clocks::system(), 9) << "[" << file_name << ":" << line_num - << "]"; + (*this) << thread_id << "][" << StringBuilder::FixedDouble(Clocks::system(), 9) << "][" << file_name << ':' + << line_num << ']'; if (tag_ != nullptr && *tag_) { (*this) << "[#" << Slice(tag_) << "]"; } @@ -80,17 +79,6 @@ Logger::Logger(LogInterface &log, int log_level, Slice file_name, int line_num, (*this) << "\t"; } -Logger &Logger::printf(const char *fmt, ...) { - if (!*fmt) { - return *this; - } - va_list list; - va_start(list, fmt); - sb_.vprintf(fmt, list); - va_end(list); - return *this; -} - Logger::~Logger() { if (!simple_mode_) { sb_ << '\n'; diff --git a/tdutils/td/utils/logging.h b/tdutils/td/utils/logging.h index e677f448..5334abd5 100644 --- a/tdutils/td/utils/logging.h +++ b/tdutils/td/utils/logging.h @@ -32,11 +32,11 @@ #include #include -#define PSTR_IMPL(...) ::td::Logger(::td::NullLog().ref(), 0, true).printf(__VA_ARGS__) -#define PSLICE(...) ::td::detail::Slicify() & PSTR_IMPL(__VA_ARGS__) -#define PSTRING(...) ::td::detail::Stringify() & PSTR_IMPL(__VA_ARGS__) -#define PSLICE_SAFE(...) ::td::detail::SlicifySafe() & PSTR_IMPL(__VA_ARGS__) -#define PSTRING_SAFE(...) ::td::detail::StringifySafe() & PSTR_IMPL(__VA_ARGS__) +#define PSTR_IMPL() ::td::Logger(::td::NullLog().ref(), 0, true) +#define PSLICE() ::td::detail::Slicify() & PSTR_IMPL() +#define PSTRING() ::td::detail::Stringify() & PSTR_IMPL() +#define PSLICE_SAFE() ::td::detail::SlicifySafe() & PSTR_IMPL() +#define PSTRING_SAFE() ::td::detail::StringifySafe() & PSTR_IMPL() #define VERBOSITY_NAME(x) verbosity_##x @@ -53,17 +53,16 @@ ::td::Logger(*::td::log_interface, VERBOSITY_NAME(level), __FILE__, __LINE__, comment, \ VERBOSITY_NAME(level) == VERBOSITY_NAME(PLAIN)) -#define LOG_IMPL(strip_level, level, condition, comment, ...) \ +#define LOG_IMPL(strip_level, level, condition, comment) \ LOG_IS_STRIPPED(strip_level) || VERBOSITY_NAME(level) > GET_VERBOSITY_LEVEL() || !(condition) \ ? (void)0 \ - : ::td::detail::Voidify() & LOGGER(level, comment).printf(__VA_ARGS__) + : ::td::detail::Voidify() & LOGGER(level, comment) -#define LOG(level, ...) LOG_IMPL(level, level, true, ::td::Slice(), __VA_ARGS__) -#define LOG_IF(level, condition, ...) LOG_IMPL(level, level, condition, #condition, __VA_ARGS__) +#define LOG(level) LOG_IMPL(level, level, true, ::td::Slice()) +#define LOG_IF(level, condition) LOG_IMPL(level, level, condition, #condition) -#define VLOG(level, ...) LOG_IMPL(DEBUG, level, true, TD_DEFINE_STR(level), __VA_ARGS__) -#define VLOG_IF(level, condition, ...) \ - LOG_IMPL(DEBUG, level, condition, TD_DEFINE_STR(level) " " #condition, __VA_ARGS__) +#define VLOG(level) LOG_IMPL(DEBUG, level, true, TD_DEFINE_STR(level)) +#define VLOG_IF(level, condition) LOG_IMPL(DEBUG, level, condition, TD_DEFINE_STR(level) " " #condition) #define LOG_ROTATE() ::td::log_interface->rotate() @@ -84,19 +83,19 @@ inline bool no_return_func() { #endif #ifdef TD_DEBUG #if TD_MSVC - #define CHECK(condition, ...) \ + #define CHECK(condition) \ __analysis_assume(!!(condition)); \ - LOG_IMPL(FATAL, FATAL, !(condition), #condition, __VA_ARGS__) + LOG_IMPL(FATAL, FATAL, !(condition), #condition) #else - #define CHECK(condition, ...) LOG_IMPL(FATAL, FATAL, !(condition) && no_return_func(), #condition, __VA_ARGS__) + #define CHECK(condition) LOG_IMPL(FATAL, FATAL, !(condition) && no_return_func(), #condition) #endif #else - #define CHECK(condition, ...) LOG_IF(NEVER, !(condition), __VA_ARGS__) + #define CHECK(condition) LOG_IF(NEVER, !(condition)) #endif // clang-format on -#define UNREACHABLE(...) \ - LOG(FATAL, __VA_ARGS__); \ +#define UNREACHABLE() \ + LOG(FATAL); \ ::td::process_fatal_error("Unreachable in " __FILE__ " at " TD_DEFINE_STR(__LINE__)) constexpr int VERBOSITY_NAME(PLAIN) = -1; @@ -197,12 +196,6 @@ class Logger { return *this; } - Logger &printf() { - return *this; - } - - Logger &printf(const char *fmt, ...) TD_ATTRIBUTE_FORMAT_PRINTF(2, 3); - MutableCSlice as_cslice() { return sb_.as_cslice(); }