| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- //
- // 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<logger_impl> 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<char[]> 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();
- }
|