|
|
|
@ -82,7 +82,7 @@ void async_sink::send_message_(async_log_msg::type msg_type, const details::log_
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void async_sink::backend_loop_() const {
|
|
|
|
|
void async_sink::backend_loop_() {
|
|
|
|
|
details::async_log_msg incoming_msg;
|
|
|
|
|
for (;;) {
|
|
|
|
|
q_->dequeue(incoming_msg);
|
|
|
|
@ -101,19 +101,41 @@ void async_sink::backend_loop_() const {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void async_sink::backend_log_(const details::log_msg &msg) const {
|
|
|
|
|
void async_sink::backend_log_(const details::log_msg &msg) {
|
|
|
|
|
for (const auto &sink : config_.sinks) {
|
|
|
|
|
if (sink->should_log(msg.log_level)) {
|
|
|
|
|
sink->log(msg);
|
|
|
|
|
try {
|
|
|
|
|
sink->log(msg);
|
|
|
|
|
} catch (const std::exception &ex) {
|
|
|
|
|
err_handler_(std::string("async log failed: ") + ex.what());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void async_sink::backend_flush_() const {
|
|
|
|
|
void async_sink::backend_flush_() {
|
|
|
|
|
for (const auto &sink : config_.sinks) {
|
|
|
|
|
sink->flush();
|
|
|
|
|
try {
|
|
|
|
|
sink->flush();
|
|
|
|
|
} catch (const std::exception &ex) {
|
|
|
|
|
err_handler_(std::string("async flush failed: ") + ex.what());
|
|
|
|
|
} catch (...) {
|
|
|
|
|
err_handler_("Async flush failed with unknown exception");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void async_sink::err_handler_(const std::string &message) {
|
|
|
|
|
using std::chrono::system_clock;
|
|
|
|
|
const auto now = system_clock::now();
|
|
|
|
|
const auto tm_time = details::os::localtime(system_clock::to_time_t(now));
|
|
|
|
|
char date_buf[64];
|
|
|
|
|
std::strftime(date_buf, sizeof(date_buf), "%Y-%m-%d %H:%M:%S", &tm_time);
|
|
|
|
|
#if defined(USING_R) && defined(R_R_H) // if in R environment
|
|
|
|
|
REprintf("[*** LOG ERROR ***] [%s] [%s] %s\n", date_buf, name().c_str(), message.c_str());
|
|
|
|
|
#else
|
|
|
|
|
std::fprintf(stderr, "[*** LOG ERROR ***] [%s] %s\n", date_buf, message.c_str());
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace sinks
|
|
|
|
|
} // namespace spdlog
|
|
|
|
|