Remove printf-like logging.
GitOrigin-RevId: 359e29aea05ee57eff7ab1feec134cbd9cbdabc9
This commit is contained in:
parent
a7e9fb5e62
commit
14edf49084
@ -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
|
||||
|
@ -10,7 +10,6 @@
|
||||
#include "td/utils/Slice-decl.h"
|
||||
#include "td/utils/StackAllocator.h"
|
||||
|
||||
#include <cstdarg>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <type_traits>
|
||||
@ -114,10 +113,6 @@ class StringBuilder {
|
||||
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:
|
||||
char *begin_ptr_;
|
||||
char *current_ptr_;
|
||||
|
@ -13,7 +13,6 @@
|
||||
#include "td/utils/Time.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <cstdarg>
|
||||
#include <cstdlib>
|
||||
|
||||
#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';
|
||||
|
@ -32,11 +32,11 @@
|
||||
#include <atomic>
|
||||
#include <type_traits>
|
||||
|
||||
#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();
|
||||
}
|
||||
|
Reference in New Issue
Block a user