Remove printf-like logging.

GitOrigin-RevId: 359e29aea05ee57eff7ab1feec134cbd9cbdabc9
This commit is contained in:
levlam 2018-02-11 18:37:30 +03:00
parent a7e9fb5e62
commit 14edf49084
4 changed files with 20 additions and 67 deletions

View File

@ -98,27 +98,4 @@ StringBuilder &StringBuilder::operator<<(const void *ptr) {
return *this; 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 } // namespace td

View File

@ -10,7 +10,6 @@
#include "td/utils/Slice-decl.h" #include "td/utils/Slice-decl.h"
#include "td/utils/StackAllocator.h" #include "td/utils/StackAllocator.h"
#include <cstdarg>
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
#include <type_traits> #include <type_traits>
@ -114,10 +113,6 @@ class StringBuilder {
return *this << static_cast<const void *>(ptr); return *this << static_cast<const void *>(ptr);
} }
void vprintf(const char *fmt, va_list list);
void printf(const char *fmt, ...) TD_ATTRIBUTE_FORMAT_PRINTF(2, 3);
private: private:
char *begin_ptr_; char *begin_ptr_;
char *current_ptr_; char *current_ptr_;

View File

@ -13,7 +13,6 @@
#include "td/utils/Time.h" #include "td/utils/Time.h"
#include <atomic> #include <atomic>
#include <cstdarg>
#include <cstdlib> #include <cstdlib>
#if TD_ANDROID #if TD_ANDROID
@ -62,12 +61,12 @@ Logger::Logger(LogInterface &log, int log_level, Slice file_name, int line_num,
if (log_level < 10) { if (log_level < 10) {
(*this) << ' '; (*this) << ' ';
} }
(*this) << log_level << '][t'; (*this) << log_level << "][t";
if (thread_id < 10) { if (thread_id < 10) {
(*this) << ' '; (*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_) { if (tag_ != nullptr && *tag_) {
(*this) << "[#" << Slice(tag_) << "]"; (*this) << "[#" << Slice(tag_) << "]";
} }
@ -80,17 +79,6 @@ Logger::Logger(LogInterface &log, int log_level, Slice file_name, int line_num,
(*this) << "\t"; (*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() { Logger::~Logger() {
if (!simple_mode_) { if (!simple_mode_) {
sb_ << '\n'; sb_ << '\n';

View File

@ -32,11 +32,11 @@
#include <atomic> #include <atomic>
#include <type_traits> #include <type_traits>
#define PSTR_IMPL(...) ::td::Logger(::td::NullLog().ref(), 0, true).printf(__VA_ARGS__) #define PSTR_IMPL() ::td::Logger(::td::NullLog().ref(), 0, true)
#define PSLICE(...) ::td::detail::Slicify() & PSTR_IMPL(__VA_ARGS__) #define PSLICE() ::td::detail::Slicify() & PSTR_IMPL()
#define PSTRING(...) ::td::detail::Stringify() & PSTR_IMPL(__VA_ARGS__) #define PSTRING() ::td::detail::Stringify() & PSTR_IMPL()
#define PSLICE_SAFE(...) ::td::detail::SlicifySafe() & PSTR_IMPL(__VA_ARGS__) #define PSLICE_SAFE() ::td::detail::SlicifySafe() & PSTR_IMPL()
#define PSTRING_SAFE(...) ::td::detail::StringifySafe() & PSTR_IMPL(__VA_ARGS__) #define PSTRING_SAFE() ::td::detail::StringifySafe() & PSTR_IMPL()
#define VERBOSITY_NAME(x) verbosity_##x #define VERBOSITY_NAME(x) verbosity_##x
@ -53,17 +53,16 @@
::td::Logger(*::td::log_interface, VERBOSITY_NAME(level), __FILE__, __LINE__, comment, \ ::td::Logger(*::td::log_interface, VERBOSITY_NAME(level), __FILE__, __LINE__, comment, \
VERBOSITY_NAME(level) == VERBOSITY_NAME(PLAIN)) 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) \ LOG_IS_STRIPPED(strip_level) || VERBOSITY_NAME(level) > GET_VERBOSITY_LEVEL() || !(condition) \
? (void)0 \ ? (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(level) LOG_IMPL(level, level, true, ::td::Slice())
#define LOG_IF(level, condition, ...) LOG_IMPL(level, level, condition, #condition, __VA_ARGS__) #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(level) LOG_IMPL(DEBUG, level, true, TD_DEFINE_STR(level))
#define VLOG_IF(level, condition, ...) \ #define VLOG_IF(level, condition) LOG_IMPL(DEBUG, level, condition, TD_DEFINE_STR(level) " " #condition)
LOG_IMPL(DEBUG, level, condition, TD_DEFINE_STR(level) " " #condition, __VA_ARGS__)
#define LOG_ROTATE() ::td::log_interface->rotate() #define LOG_ROTATE() ::td::log_interface->rotate()
@ -84,19 +83,19 @@ inline bool no_return_func() {
#endif #endif
#ifdef TD_DEBUG #ifdef TD_DEBUG
#if TD_MSVC #if TD_MSVC
#define CHECK(condition, ...) \ #define CHECK(condition) \
__analysis_assume(!!(condition)); \ __analysis_assume(!!(condition)); \
LOG_IMPL(FATAL, FATAL, !(condition), #condition, __VA_ARGS__) LOG_IMPL(FATAL, FATAL, !(condition), #condition)
#else #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 #endif
#else #else
#define CHECK(condition, ...) LOG_IF(NEVER, !(condition), __VA_ARGS__) #define CHECK(condition) LOG_IF(NEVER, !(condition))
#endif #endif
// clang-format on // clang-format on
#define UNREACHABLE(...) \ #define UNREACHABLE() \
LOG(FATAL, __VA_ARGS__); \ LOG(FATAL); \
::td::process_fatal_error("Unreachable in " __FILE__ " at " TD_DEFINE_STR(__LINE__)) ::td::process_fatal_error("Unreachable in " __FILE__ " at " TD_DEFINE_STR(__LINE__))
constexpr int VERBOSITY_NAME(PLAIN) = -1; constexpr int VERBOSITY_NAME(PLAIN) = -1;
@ -197,12 +196,6 @@ class Logger {
return *this; return *this;
} }
Logger &printf() {
return *this;
}
Logger &printf(const char *fmt, ...) TD_ATTRIBUTE_FORMAT_PRINTF(2, 3);
MutableCSlice as_cslice() { MutableCSlice as_cslice() {
return sb_.as_cslice(); return sb_.as_cslice();
} }