This commit is contained in:
gabime 2017-12-22 18:55:19 +02:00
parent 813dcbcf63
commit 4ca6991828
4 changed files with 57 additions and 57 deletions

View File

@ -282,7 +282,7 @@ inline void spdlog::details::async_log_helper::worker_loop()
} }
catch(...) catch(...)
{ {
_err_handler("Unknown exeption in async logger worker loop."); _err_handler("Unknown exeption in async logger worker loop.");
} }
} }
if (_worker_teardown_cb) _worker_teardown_cb(); if (_worker_teardown_cb) _worker_teardown_cb();

View File

@ -113,31 +113,31 @@ public:
// //
// "mylog.txt" => ("mylog", ".txt") // "mylog.txt" => ("mylog", ".txt")
// "mylog" => ("mylog", "") // "mylog" => ("mylog", "")
// "mylog." => ("mylog.", "") // "mylog." => ("mylog.", "")
// "/dir1/dir2/mylog.txt" => ("/dir1/dir2/mylog", ".txt") // "/dir1/dir2/mylog.txt" => ("/dir1/dir2/mylog", ".txt")
// //
// the starting dot in filenames is ignored (hidden files): // the starting dot in filenames is ignored (hidden files):
// //
// ".mylog" => (".mylog". "") // ".mylog" => (".mylog". "")
// "my_folder/.mylog" => ("my_folder/.mylog", "") // "my_folder/.mylog" => ("my_folder/.mylog", "")
// "my_folder/.mylog.txt" => ("my_folder/.mylog", ".txt") // "my_folder/.mylog.txt" => ("my_folder/.mylog", ".txt")
static std::tuple<filename_t, filename_t> split_by_extenstion(const spdlog::filename_t& fname) static std::tuple<filename_t, filename_t> split_by_extenstion(const spdlog::filename_t& fname)
{ {
auto ext_index = fname.rfind('.'); auto ext_index = fname.rfind('.');
// no valid extension found - return whole path and empty string as extension // no valid extension found - return whole path and empty string as extension
if (ext_index == filename_t::npos || ext_index == 0 || ext_index == fname.size() - 1) if (ext_index == filename_t::npos || ext_index == 0 || ext_index == fname.size() - 1)
return std::make_tuple(fname, spdlog::filename_t()); return std::make_tuple(fname, spdlog::filename_t());
// treat casese like "/etc/rc.d/somelogfile or "/abc/.hiddenfile" // treat casese like "/etc/rc.d/somelogfile or "/abc/.hiddenfile"
//auto folder_index = fname.find('\\', ext_index); //auto folder_index = fname.find('\\', ext_index);
auto folder_index = fname.rfind(details::os::folder_sep); auto folder_index = fname.rfind(details::os::folder_sep);
if (folder_index != fname.npos && folder_index >= ext_index - 1) if (folder_index != fname.npos && folder_index >= ext_index - 1)
return std::make_tuple(fname, spdlog::filename_t()); return std::make_tuple(fname, spdlog::filename_t());
// finally - return a valid base and extnetion tuple // finally - return a valid base and extnetion tuple
return std::make_tuple(fname.substr(0, ext_index), fname.substr(ext_index)); return std::make_tuple(fname.substr(0, ext_index), fname.substr(ext_index));
} }
private: private:
FILE* _fd; FILE* _fd;
filename_t _filename; filename_t _filename;

View File

@ -98,11 +98,11 @@ inline void spdlog::logger::log(level::level_enum lvl, const char* msg)
{ {
_err_handler(ex.what()); _err_handler(ex.what());
} }
catch (...) catch (...)
{ {
_err_handler("Unknown exception in logger " + _name); _err_handler("Unknown exception in logger " + _name);
throw; throw;
} }
} }
template<typename T> template<typename T>
@ -119,11 +119,11 @@ inline void spdlog::logger::log(level::level_enum lvl, const T& msg)
{ {
_err_handler(ex.what()); _err_handler(ex.what());
} }
catch (...) catch (...)
{ {
_err_handler("Unknown exception in logger " + _name); _err_handler("Unknown exception in logger " + _name);
throw; throw;
} }
} }

View File

@ -76,42 +76,42 @@ TEST_CASE("file_helper_reopen2", "[file_helper::reopen(false)]]")
static void test_split_ext(const char* fname, const char* expect_base, const char* expect_ext) static void test_split_ext(const char* fname, const char* expect_base, const char* expect_ext)
{ {
spdlog::filename_t filename(fname); spdlog::filename_t filename(fname);
spdlog::filename_t expected_base(expect_base); spdlog::filename_t expected_base(expect_base);
spdlog::filename_t expected_ext(expect_ext); spdlog::filename_t expected_ext(expect_ext);
#ifdef _WIN32 // replace folder sep #ifdef _WIN32 // replace folder sep
std::replace(filename.begin(), filename.end(), '/', '\\'); std::replace(filename.begin(), filename.end(), '/', '\\');
std::replace(expected_base.begin(), expected_base.end(), '/', '\\'); std::replace(expected_base.begin(), expected_base.end(), '/', '\\');
#endif #endif
spdlog::filename_t basename, ext; spdlog::filename_t basename, ext;
std::tie(basename, ext) = file_helper::split_by_extenstion(filename); std::tie(basename, ext) = file_helper::split_by_extenstion(filename);
REQUIRE(basename == expected_base); REQUIRE(basename == expected_base);
REQUIRE(ext == expected_ext); REQUIRE(ext == expected_ext);
} }
TEST_CASE("file_helper_split_by_extenstion", "[file_helper::split_by_extenstion()]]") TEST_CASE("file_helper_split_by_extenstion", "[file_helper::split_by_extenstion()]]")
{ {
test_split_ext("mylog.txt", "mylog", ".txt"); test_split_ext("mylog.txt", "mylog", ".txt");
test_split_ext(".mylog.txt", ".mylog", ".txt"); test_split_ext(".mylog.txt", ".mylog", ".txt");
test_split_ext(".mylog", ".mylog", ""); test_split_ext(".mylog", ".mylog", "");
test_split_ext("/aaa/bb.d/mylog", "/aaa/bb.d/mylog", ""); test_split_ext("/aaa/bb.d/mylog", "/aaa/bb.d/mylog", "");
test_split_ext("/aaa/bb.d/mylog.txt", "/aaa/bb.d/mylog", ".txt"); test_split_ext("/aaa/bb.d/mylog.txt", "/aaa/bb.d/mylog", ".txt");
test_split_ext("aaa/bbb/ccc/mylog.txt", "aaa/bbb/ccc/mylog", ".txt"); test_split_ext("aaa/bbb/ccc/mylog.txt", "aaa/bbb/ccc/mylog", ".txt");
test_split_ext("aaa/bbb/ccc/mylog.", "aaa/bbb/ccc/mylog.", ""); test_split_ext("aaa/bbb/ccc/mylog.", "aaa/bbb/ccc/mylog.", "");
test_split_ext("aaa/bbb/ccc/.mylog.txt", "aaa/bbb/ccc/.mylog", ".txt"); test_split_ext("aaa/bbb/ccc/.mylog.txt", "aaa/bbb/ccc/.mylog", ".txt");
test_split_ext("/aaa/bbb/ccc/mylog.txt", "/aaa/bbb/ccc/mylog", ".txt"); test_split_ext("/aaa/bbb/ccc/mylog.txt", "/aaa/bbb/ccc/mylog", ".txt");
test_split_ext("/aaa/bbb/ccc/.mylog", "/aaa/bbb/ccc/.mylog", ""); test_split_ext("/aaa/bbb/ccc/.mylog", "/aaa/bbb/ccc/.mylog", "");
test_split_ext("../mylog.txt", "../mylog", ".txt"); test_split_ext("../mylog.txt", "../mylog", ".txt");
test_split_ext(".././mylog.txt", ".././mylog", ".txt"); test_split_ext(".././mylog.txt", ".././mylog", ".txt");
test_split_ext(".././mylog.txt/xxx", ".././mylog.txt/xxx", ""); test_split_ext(".././mylog.txt/xxx", ".././mylog.txt/xxx", "");
test_split_ext("/mylog.txt", "/mylog", ".txt"); test_split_ext("/mylog.txt", "/mylog", ".txt");
test_split_ext("//mylog.txt", "//mylog", ".txt"); test_split_ext("//mylog.txt", "//mylog", ".txt");
test_split_ext("", "", ""); test_split_ext("", "", "");
test_split_ext(".", ".", ""); test_split_ext(".", ".", "");
test_split_ext("..txt", ".", ".txt"); test_split_ext("..txt", ".", ".txt");
} }