// // c_logger.cxx // logging // // Created by Sam Jaffe on 4/1/19. // #include "logger/c_logger.h" #include "common.h" #include "logger_impl.h" #include "logger/logpacket.h" using namespace logging; c_logger::c_logger(std::string const & name, std::shared_ptr impl) : logger_name_(name), impl_(impl) { } c_logger::~c_logger() { if (impl_) impl_->flush(); } void c_logger::vlognf(level level, size_t num_bytes, char const* fmt, va_list args) { if (!impl_->should_log(level)) return; const std::unique_ptr data(new char[num_bytes]); int n = vsnprintf(data.get(), num_bytes, fmt, args); if (n >= 0) { data[num_bytes-1] = '\0'; impl_->write({ now(), level, {}, logger_name_, {data.get()} }); } } void c_logger::log(level level, std::string const& msg) { impl_->write({ now(), level, {}, logger_name_, msg }); } void c_logger::flush() { impl_->flush(); }