From 6e3cbf42dc05ce5416790849d291aecc9985d9b7 Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 11 Feb 2018 17:07:16 +0300 Subject: [PATCH] Remove calls to Logger.printf. GitOrigin-RevId: 3b5452fc4bd705ce5cf98d360247ec0146923e2d --- benchmark/bench_log.cpp | 2 +- td/telegram/SequenceDispatcher.cpp | 2 +- td/telegram/Td.cpp | 2 +- tdutils/td/utils/format.h | 3 ++- tdutils/td/utils/logging.cpp | 16 +++++++++++----- tdutils/td/utils/logging.h | 4 ++-- tdutils/td/utils/port/Stat.cpp | 2 +- tdutils/td/utils/port/detail/KQueue.cpp | 2 +- 8 files changed, 20 insertions(+), 13 deletions(-) diff --git a/benchmark/bench_log.cpp b/benchmark/bench_log.cpp index 724186cca..a57b1b9b4 100644 --- a/benchmark/bench_log.cpp +++ b/benchmark/bench_log.cpp @@ -75,7 +75,7 @@ class FILEWriteBench : public td::Benchmark { public: std::string get_description() const override { - return "fprintf (to file, no buf, no flush)"; + return "std::fprintf (to file, no buf, no flush)"; } void start_up() override { diff --git a/td/telegram/SequenceDispatcher.cpp b/td/telegram/SequenceDispatcher.cpp index d8b35c200..004d23676 100644 --- a/td/telegram/SequenceDispatcher.cpp +++ b/td/telegram/SequenceDispatcher.cpp @@ -201,7 +201,7 @@ void SequenceDispatcher::timeout_expired() { } CHECK(!parent_.empty()); set_timeout_in(1); - VLOG(DEBUG) << "SequenceDispatcher ready to close"; + LOG(DEBUG) << "SequenceDispatcher ready to close"; send_closure(parent_, &Parent::ready_to_close); } diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 0d3c07c58..92743fc43 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -3928,7 +3928,7 @@ void Td::hangup_shared() { } else if (type == ActorIdType) { dec_actor_refcnt(); } else { - LOG(FATAL, "Unknown hangup_shared ") << tag("type", type); + LOG(FATAL) << "Unknown hangup_shared of type " << type; } } diff --git a/tdutils/td/utils/format.h b/tdutils/td/utils/format.h index 316b2c910..745ad0d8a 100644 --- a/tdutils/td/utils/format.h +++ b/tdutils/td/utils/format.h @@ -147,7 +147,8 @@ inline StringBuilder &operator<<(StringBuilder &builder, const Escaped &escaped) if (c > 31 && c < 127 && c != '"' && c != '\\') { builder << static_cast(c); } else { - builder.printf("\\%03o", c); + const char *oct = "01234567"; + builder << "\\0" << oct[c >> 6] << oct[(c >> 3) & 7] << oct[c & 7]; } } return builder; diff --git a/tdutils/td/utils/logging.cpp b/tdutils/td/utils/logging.cpp index 321dde02a..9a488825b 100644 --- a/tdutils/td/utils/logging.cpp +++ b/tdutils/td/utils/logging.cpp @@ -56,12 +56,18 @@ Logger::Logger(LogInterface &log, int log_level, Slice file_name, int line_num, } file_name = file_name.substr(last_slash_ + 1); - printf("[%2d]", log_level); - auto tid = get_thread_id(); - if (tid != -1) { - printf("[t%2d]", tid); + auto thread_id = get_thread_id(); + + (*this) << '['; + if (log_level < 10) { + (*this) << ' '; } - (*this) << StringBuilder::FixedDouble(Clocks::system(), 9) << "[" << file_name << ":" << line_num << "]"; + (*this) << log_level << '][t'; + if (thread_id < 10) { + (*this) << ' '; + } + (*this) << thread_id << ']' << StringBuilder::FixedDouble(Clocks::system(), 9) << "[" << file_name << ":" << line_num + << "]"; if (tag_ != nullptr && *tag_) { (*this) << "[#" << Slice(tag_) << "]"; } diff --git a/tdutils/td/utils/logging.h b/tdutils/td/utils/logging.h index 3ed4f48f8..e677f4481 100644 --- a/tdutils/td/utils/logging.h +++ b/tdutils/td/utils/logging.h @@ -12,14 +12,14 @@ * Predefined log levels: FATAL, ERROR, WARNING, INFO, DEBUG * * LOG(WARNING) << "Hello world!"; - * LOG(INFO, "Hello %d", 1234) << " world!"; + * LOG(INFO) << "Hello " << 1234 << " world!"; * LOG_IF(INFO, condition) << "Hello world if condition!"; * * Custom log levels may be defined and used using VLOG: * int VERBOSITY_NAME(custom) = VERBOSITY_NAME(WARNING); * VLOG(custom) << "Hello custom world!" * - * LOG(FATAL, "power is off"); + * LOG(FATAL) << "Power is off"; * CHECK(condition) <===> LOG_IF(FATAL, !(condition)) */ diff --git a/tdutils/td/utils/port/Stat.cpp b/tdutils/td/utils/port/Stat.cpp index 54fb05d77..27de23092 100644 --- a/tdutils/td/utils/port/Stat.cpp +++ b/tdutils/td/utils/port/Stat.cpp @@ -64,7 +64,7 @@ Stat fstat(int native_fd) { struct ::stat buf; int err = fstat(native_fd, &buf); auto fstat_errno = errno; - LOG_IF(FATAL, err < 0) << Status::PosixError(fstat_errno, PSLICE() << "stat of fd " << native_fd << " failed"); + LOG_IF(FATAL, err < 0) << Status::PosixError(fstat_errno, PSLICE() << "stat for fd " << native_fd << " failed"); return detail::from_native_stat(buf); } diff --git a/tdutils/td/utils/port/detail/KQueue.cpp b/tdutils/td/utils/port/detail/KQueue.cpp index 1376fe961..351f8d7d6 100644 --- a/tdutils/td/utils/port/detail/KQueue.cpp +++ b/tdutils/td/utils/port/detail/KQueue.cpp @@ -147,7 +147,7 @@ void KQueue::run(int timeout_ms) { flags |= Fd::Close; } if (event->fflags & EV_ERROR) { - LOG(FATAL, "EV_ERROR in kqueue is not supported"); + LOG(FATAL) << "EV_ERROR in kqueue is not supported"; } VLOG(fd) << "Event [fd:" << event->ident << "] [filter:" << event->filter << "] [udata: " << event->udata << "]"; // LOG(WARNING) << "event->ident = " << event->ident << "event->filter = " << event->filter;