Commit e7debaac authored by gabime's avatar gabime

astyle

parent bdbe9086
......@@ -134,7 +134,8 @@ void user_defined_example()
void err_handler_example()
{
//can be set globaly or per logger(logger->set_error_handler(..))
spdlog::set_error_handler([](const std::string& msg) {
spdlog::set_error_handler([](const std::string& msg)
{
std::cerr << "my err handler: " << msg << std::endl;
});
spd::get("console")->info("some invalid message to trigger an error {}{}{}{}", 3);
......
......@@ -261,10 +261,12 @@ inline void spdlog::details::async_log_helper::worker_loop()
while(process_next_msg(last_pop, last_flush));
if (_worker_teardown_cb) _worker_teardown_cb();
}
catch (const std::exception &ex) {
catch (const std::exception &ex)
{
_err_handler(ex.what());
}
catch (...) {
catch (...)
{
_err_handler("Unknown exception");
}
}
......
......@@ -77,10 +77,12 @@ inline void spdlog::async_logger::_sink_it(details::log_msg& msg)
{
_async_log_helper->log(msg);
}
catch (const std::exception &ex) {
catch (const std::exception &ex)
{
_err_handler(ex.what());
}
catch (...) {
catch (...)
{
_err_handler("Unknown exception");
}
}
......@@ -23,7 +23,10 @@ inline spdlog::logger::logger(const std::string& logger_name, const It& begin, c
_level = level::info;
_flush_level = level::off;
_last_err_time = 0;
_err_handler = [this](const std::string &msg) { this->_default_err_handler(msg);};
_err_handler = [this](const std::string &msg)
{
this->_default_err_handler(msg);
};
}
// ctor with sinks as init list
......@@ -35,9 +38,9 @@ inline spdlog::logger::logger(const std::string& logger_name, sinks_init_list si
// ctor with single sink
inline spdlog::logger::logger(const std::string& logger_name, spdlog::sink_ptr single_sink):
logger(logger_name,
{
{
single_sink
})
})
{}
......@@ -60,15 +63,18 @@ inline void spdlog::logger::log(level::level_enum lvl, const char* fmt, const Ar
{
if (!should_log(lvl)) return;
try {
try
{
details::log_msg log_msg(&_name, lvl);
log_msg.raw.write(fmt, args...);
_sink_it(log_msg);
}
catch (const std::exception &ex) {
catch (const std::exception &ex)
{
_err_handler(ex.what());
}
catch (...) {
catch (...)
{
_err_handler("Unknown exception");
}
}
......@@ -77,15 +83,18 @@ template <typename... Args>
inline void spdlog::logger::log(level::level_enum lvl, const char* msg)
{
if (!should_log(lvl)) return;
try {
try
{
details::log_msg log_msg(&_name, lvl);
log_msg.raw << msg;
_sink_it(log_msg);
}
catch (const std::exception &ex) {
catch (const std::exception &ex)
{
_err_handler(ex.what());
}
catch (...) {
catch (...)
{
_err_handler("Unknown exception");
}
......@@ -95,15 +104,18 @@ template<typename T>
inline void spdlog::logger::log(level::level_enum lvl, const T& msg)
{
if (!should_log(lvl)) return;
try {
try
{
details::log_msg log_msg(&_name, lvl);
log_msg.raw << msg;
_sink_it(log_msg);
}
catch (const std::exception &ex) {
catch (const std::exception &ex)
{
_err_handler(ex.what());
}
catch (...) {
catch (...)
{
_err_handler("Unknown exception");
}
}
......
......@@ -210,7 +210,7 @@ inline size_t filesize(FILE *f)
#else // unix
int fd = fileno(f);
//64 bits(but not in osx, where fstat64 is deprecated)
#if !defined(__FreeBSD__) && !defined(__APPLE__) && (defined(__x86_64__) || defined(__ppc64__))
#if !defined(__FreeBSD__) && !defined(__APPLE__) && (defined(__x86_64__) || defined(__ppc64__))
struct stat64 st;
if (fstat64(fd, &st) == 0)
return st.st_size;
......
......@@ -22,13 +22,14 @@ TEST_CASE("default_error_handler", "[errors]]")
}
struct custom_ex{};
struct custom_ex {};
TEST_CASE("custom_error_handler", "[errors]]")
{
prepare_logdir();
std::string filename = "logs/simple_log.txt";
auto logger = spdlog::create<spdlog::sinks::simple_file_sink_mt>("logger", filename, true);
logger->set_error_handler([=](const std::string& msg) {
logger->set_error_handler([=](const std::string& msg)
{
throw custom_ex();
});
logger->info("Good message #1");
......@@ -45,7 +46,8 @@ TEST_CASE("async_error_handler", "[errors]]")
std::string filename = "logs/simple_async_log.txt";
{
auto logger = spdlog::create<spdlog::sinks::simple_file_sink_mt>("logger", filename, true);
logger->set_error_handler([=](const std::string& msg) {
logger->set_error_handler([=](const std::string& msg)
{
std::ofstream ofs("logs/custom_err.txt");
if (!ofs) throw std::runtime_error("Failed open logs/custom_err.txt");
ofs << err_msg;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment