mirror of
https://github.com/gabime/spdlog.git
synced 2025-02-05 04:06:46 +08:00
Removed state from default error handler
This commit is contained in:
parent
b05d9362ea
commit
286218aeeb
@ -85,29 +85,22 @@ bool logger::should_flush_(const details::log_msg &msg) {
|
|||||||
return (msg.log_level >= flush_level) && (msg.log_level != level::off);
|
return (msg.log_level >= flush_level) && (msg.log_level != level::off);
|
||||||
}
|
}
|
||||||
|
|
||||||
void logger::err_handler_(const std::string &msg) {
|
void logger::err_handler_(const std::string &msg) {
|
||||||
if (custom_err_handler_) {
|
if (custom_err_handler_) {
|
||||||
custom_err_handler_(msg);
|
custom_err_handler_(msg);
|
||||||
} else {
|
} else {
|
||||||
using std::chrono::system_clock;
|
using std::chrono::system_clock;
|
||||||
static std::mutex mutex;
|
auto now = system_clock::now();
|
||||||
static std::chrono::system_clock::time_point last_report_time;
|
auto tm_time = details::os::localtime(system_clock::to_time_t(now));
|
||||||
static size_t err_counter = 0;
|
char date_buf[64];
|
||||||
std::lock_guard<std::mutex> lk{mutex};
|
std::strftime(date_buf, sizeof(date_buf), "%Y-%m-%d %H:%M:%S", &tm_time);
|
||||||
auto now = system_clock::now();
|
|
||||||
err_counter++;
|
|
||||||
if (now - last_report_time < std::chrono::seconds(1)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
last_report_time = now;
|
|
||||||
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
|
#if defined(USING_R) && defined(R_R_H) // if in R environment
|
||||||
REprintf("[*** LOG ERROR #%04zu ***] [%s] [%s] %s\n", err_counter, date_buf, name().c_str(), msg.c_str());
|
REprintf("[*** LOG ERROR ***] [%s] [%s] %s\n", date_buf, name().c_str(),
|
||||||
|
msg.c_str());
|
||||||
#else
|
#else
|
||||||
std::fprintf(stderr, "[*** LOG ERROR #%04zu ***] [%s] [%s] %s\n", err_counter, date_buf, name().c_str(), msg.c_str());
|
std::fprintf(stderr, "[*** LOG ERROR ***] [%s] [%s] %s\n", date_buf,
|
||||||
|
name().c_str(), msg.c_str());
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} // namespace spdlog
|
} // namespace spdlog
|
||||||
|
Loading…
Reference in New Issue
Block a user