Commit 16ee72da authored by gabime's avatar gabime

clang format

parent d409e536
...@@ -32,7 +32,6 @@ void bench_mt(int howmany, std::shared_ptr<spdlog::logger> log, int thread_count ...@@ -32,7 +32,6 @@ void bench_mt(int howmany, std::shared_ptr<spdlog::logger> log, int thread_count
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int howmany = 1000000; int howmany = 1000000;
int queue_size = howmany + 2; int queue_size = howmany + 2;
int threads = 10; int threads = 10;
...@@ -76,7 +75,7 @@ int main(int argc, char *argv[]) ...@@ -76,7 +75,7 @@ int main(int argc, char *argv[])
auto daily_mt = spdlog::daily_logger_mt("daily_mt", "logs/daily_mt.log"); auto daily_mt = spdlog::daily_logger_mt("daily_mt", "logs/daily_mt.log");
bench_mt(howmany, daily_mt, threads); bench_mt(howmany, daily_mt, threads);
bench_mt(howmany, spdlog::create<null_sink_mt>("null_mt"), threads); bench_mt(howmany, spdlog::create<null_sink_mt>("null_mt"), threads);
cout << "\n*******************************************************************************\n"; cout << "\n*******************************************************************************\n";
cout << "async logging.. " << threads << " threads sharing same logger, " << format(howmany) << " iterations " << endl; cout << "async logging.. " << threads << " threads sharing same logger, " << format(howmany) << " iterations " << endl;
...@@ -112,7 +111,7 @@ void bench(int howmany, std::shared_ptr<spdlog::logger> log) ...@@ -112,7 +111,7 @@ void bench(int howmany, std::shared_ptr<spdlog::logger> log)
auto delta = high_resolution_clock::now() - start; auto delta = high_resolution_clock::now() - start;
auto delta_d = duration_cast<duration<double>>(delta).count(); auto delta_d = duration_cast<duration<double>>(delta).count();
cout << "Elapsed: " << delta_d << "\t" << format(int(howmany / delta_d)) << "/sec" << endl; cout << "Elapsed: " << delta_d << "\t" << format(int(howmany / delta_d)) << "/sec" << endl;
spdlog::drop(log->name()); spdlog::drop(log->name());
} }
void bench_mt(int howmany, std::shared_ptr<spdlog::logger> log, int thread_count) void bench_mt(int howmany, std::shared_ptr<spdlog::logger> log, int thread_count)
......
...@@ -29,9 +29,9 @@ using namespace utils; ...@@ -29,9 +29,9 @@ using namespace utils;
void bench(int howmany, std::shared_ptr<spdlog::logger> log); void bench(int howmany, std::shared_ptr<spdlog::logger> log);
void bench_mt(int howmany, std::shared_ptr<spdlog::logger> log, int thread_count); void bench_mt(int howmany, std::shared_ptr<spdlog::logger> log, int thread_count);
int main(int , char *[]) int main(int, char *[])
{ {
std::srand(static_cast<unsigned>(std::time(nullptr))); // use current time as seed for random generator std::srand(static_cast<unsigned>(std::time(nullptr))); // use current time as seed for random generator
int howmany = 1000000; int howmany = 1000000;
int queue_size = howmany + 2; int queue_size = howmany + 2;
int threads = 10; int threads = 10;
...@@ -91,7 +91,6 @@ int main(int , char *[]) ...@@ -91,7 +91,6 @@ int main(int , char *[])
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
void bench(int howmany, std::shared_ptr<spdlog::logger> log) void bench(int howmany, std::shared_ptr<spdlog::logger> log)
{ {
using namespace std::chrono; using namespace std::chrono;
...@@ -106,10 +105,10 @@ void bench(int howmany, std::shared_ptr<spdlog::logger> log) ...@@ -106,10 +105,10 @@ void bench(int howmany, std::shared_ptr<spdlog::logger> log)
auto start = high_resolution_clock::now(); auto start = high_resolution_clock::now();
log->info("Hello logger: msg number {}", i); log->info("Hello logger: msg number {}", i);
auto delta_nanos = chrono::duration_cast<nanoseconds>(high_resolution_clock::now() - start); auto delta_nanos = chrono::duration_cast<nanoseconds>(high_resolution_clock::now() - start);
total_nanos+= delta_nanos; total_nanos += delta_nanos;
} }
auto avg = total_nanos.count()/howmany; auto avg = total_nanos.count() / howmany;
cout << format(avg) << " ns/call" << endl; cout << format(avg) << " ns/call" << endl;
} }
...@@ -131,7 +130,7 @@ void bench_mt(int howmany, std::shared_ptr<spdlog::logger> log, int thread_count ...@@ -131,7 +130,7 @@ void bench_mt(int howmany, std::shared_ptr<spdlog::logger> log, int thread_count
auto start = high_resolution_clock::now(); auto start = high_resolution_clock::now();
log->info("Hello logger: msg number {}", j); log->info("Hello logger: msg number {}", j);
auto delta_nanos = chrono::duration_cast<nanoseconds>(high_resolution_clock::now() - start); auto delta_nanos = chrono::duration_cast<nanoseconds>(high_resolution_clock::now() - start);
total_nanos+= delta_nanos.count(); total_nanos += delta_nanos.count();
} }
})); }));
} }
...@@ -141,9 +140,6 @@ void bench_mt(int howmany, std::shared_ptr<spdlog::logger> log, int thread_count ...@@ -141,9 +140,6 @@ void bench_mt(int howmany, std::shared_ptr<spdlog::logger> log, int thread_count
t.join(); t.join();
}; };
auto avg = total_nanos/howmany; auto avg = total_nanos / howmany;
cout << format(avg) << " ns/call" << endl; cout << format(avg) << " ns/call" << endl;
} }
...@@ -9,14 +9,14 @@ namespace spdlog { ...@@ -9,14 +9,14 @@ namespace spdlog {
namespace details { namespace details {
namespace fmt_helper { namespace fmt_helper {
template <size_t Buffer_Size> template<size_t Buffer_Size>
inline void append_str(const std::string &str, fmt::basic_memory_buffer<char, Buffer_Size> &dest) inline void append_str(const std::string &str, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
{ {
auto *str_ptr = str.data(); auto *str_ptr = str.data();
dest.append(str_ptr, str_ptr + str.size()); dest.append(str_ptr, str_ptr + str.size());
} }
template <size_t Buffer_Size> template<size_t Buffer_Size>
inline void append_c_str(const char *c_str, fmt::basic_memory_buffer<char, Buffer_Size> &dest) inline void append_c_str(const char *c_str, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
{ {
char ch; char ch;
...@@ -41,7 +41,7 @@ inline void append_int(T n, fmt::basic_memory_buffer<char, Buffer_Size> &dest) ...@@ -41,7 +41,7 @@ inline void append_int(T n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
dest.append(i.data(), i.data() + i.size()); dest.append(i.data(), i.data() + i.size());
} }
template <size_t Buffer_Size> template<size_t Buffer_Size>
inline void pad2(int n, fmt::basic_memory_buffer<char, Buffer_Size> &dest) inline void pad2(int n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
{ {
if (n > 99) if (n > 99)
...@@ -65,7 +65,7 @@ inline void pad2(int n, fmt::basic_memory_buffer<char, Buffer_Size> &dest) ...@@ -65,7 +65,7 @@ inline void pad2(int n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
fmt::format_to(dest, "{:02}", n); fmt::format_to(dest, "{:02}", n);
} }
template <size_t Buffer_Size> template<size_t Buffer_Size>
inline void pad3(int n, fmt::basic_memory_buffer<char, Buffer_Size> &dest) inline void pad3(int n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
{ {
if (n > 99) if (n > 99)
...@@ -91,7 +91,7 @@ inline void pad3(int n, fmt::basic_memory_buffer<char, Buffer_Size> &dest) ...@@ -91,7 +91,7 @@ inline void pad3(int n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
fmt::format_to(dest, "{:03}", n); fmt::format_to(dest, "{:03}", n);
} }
template <size_t Buffer_Size> template<size_t Buffer_Size>
inline void pad6(size_t n, fmt::basic_memory_buffer<char, Buffer_Size> &dest) inline void pad6(size_t n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
{ {
// todo: maybe replace this implementation with // todo: maybe replace this implementation with
......
...@@ -175,23 +175,23 @@ inline void spdlog::logger::critical(const T &msg) ...@@ -175,23 +175,23 @@ inline void spdlog::logger::critical(const T &msg)
#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT #ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
template<typename... Args> template<typename... Args>
inline void spdlog::logger::log(level::level_enum lvl, const wchar_t *fmt, const Args &... args) inline void spdlog::logger::log(level::level_enum lvl, const wchar_t *fmt, const Args &... args)
{ {
if (!should_log(lvl)) if (!should_log(lvl))
{ {
return; return;
} }
decltype(wstring_converter_)::byte_string utf8_string; decltype(wstring_converter_)::byte_string utf8_string;
try try
{ {
{ {
std::lock_guard<std::mutex> lock(wstring_converter_mutex_); std::lock_guard<std::mutex> lock(wstring_converter_mutex_);
utf8_string = wstring_converter_.to_bytes(fmt); utf8_string = wstring_converter_.to_bytes(fmt);
} }
log(lvl, utf8_string.c_str(), args...); log(lvl, utf8_string.c_str(), args...);
} }
SPDLOG_CATCH_AND_HANDLE SPDLOG_CATCH_AND_HANDLE
} }
template<typename... Args> template<typename... Args>
......
...@@ -120,7 +120,7 @@ class c_formatter SPDLOG_FINAL : public flag_formatter ...@@ -120,7 +120,7 @@ class c_formatter SPDLOG_FINAL : public flag_formatter
{ {
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
{ {
//fmt::format_to(dest, "{} {} {} ", days[tm_time.tm_wday], months[tm_time.tm_mon], tm_time.tm_mday); // fmt::format_to(dest, "{} {} {} ", days[tm_time.tm_wday], months[tm_time.tm_mon], tm_time.tm_mday);
// date // date
fmt_helper::append_str(days[tm_time.tm_wday], dest); fmt_helper::append_str(days[tm_time.tm_wday], dest);
dest.push_back(' '); dest.push_back(' ');
...@@ -496,7 +496,7 @@ class full_formatter SPDLOG_FINAL : public flag_formatter ...@@ -496,7 +496,7 @@ class full_formatter SPDLOG_FINAL : public flag_formatter
// cache the millis part for the next milli. // cache the millis part for the next milli.
auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count() % 1000; auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count() % 1000;
if(millis != millis_cache_timestamp_ || cached_millis_.size() == 0) if (millis != millis_cache_timestamp_ || cached_millis_.size() == 0)
{ {
cached_millis_.resize(0); cached_millis_.resize(0);
fmt_helper::pad3(static_cast<int>(millis), cached_millis_); fmt_helper::pad3(static_cast<int>(millis), cached_millis_);
...@@ -528,8 +528,8 @@ class full_formatter SPDLOG_FINAL : public flag_formatter ...@@ -528,8 +528,8 @@ class full_formatter SPDLOG_FINAL : public flag_formatter
} }
private: private:
std::chrono::seconds cache_timestamp_ {0}; std::chrono::seconds cache_timestamp_{0};
std::chrono::milliseconds::rep millis_cache_timestamp_ {0}; std::chrono::milliseconds::rep millis_cache_timestamp_{0};
fmt::basic_memory_buffer<char, 128> cached_datetime_; fmt::basic_memory_buffer<char, 128> cached_datetime_;
fmt::basic_memory_buffer<char, 8> cached_millis_; fmt::basic_memory_buffer<char, 8> cached_millis_;
}; };
......
This diff is collapsed.
...@@ -63,7 +63,7 @@ public: ...@@ -63,7 +63,7 @@ public:
template<typename... Args> template<typename... Args>
void critical(const char *fmt, const Args &... args); void critical(const char *fmt, const Args &... args);
#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT #ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
template<typename... Args> template<typename... Args>
void log(level::level_enum lvl, const wchar_t *fmt, const Args &... args); void log(level::level_enum lvl, const wchar_t *fmt, const Args &... args);
...@@ -151,8 +151,8 @@ protected: ...@@ -151,8 +151,8 @@ protected:
std::atomic<size_t> msg_counter_; std::atomic<size_t> msg_counter_;
#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT #ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
std::wstring_convert<std::codecvt_utf8<wchar_t>> wstring_converter_; std::wstring_convert<std::codecvt_utf8<wchar_t>> wstring_converter_;
std::mutex wstring_converter_mutex_; std::mutex wstring_converter_mutex_;
#endif #endif
}; };
} // namespace spdlog } // namespace spdlog
......
...@@ -95,14 +95,15 @@ private: ...@@ -95,14 +95,15 @@ private:
} }
if (details::file_helper::file_exists(src) && details::os::rename(src, target) != 0) if (details::file_helper::file_exists(src) && details::os::rename(src, target) != 0)
{ {
// if failed try again after small delay. // if failed try again after small delay.
// this is a workaround to a windows issue, where very high rotation rates sometimes fail (because of antivirus?). // this is a workaround to a windows issue, where very high rotation rates sometimes fail (because of antivirus?).
details::os::sleep_for_millis(20); details::os::sleep_for_millis(20);
details::os::remove(target); details::os::remove(target);
if (details::os::rename(src, target) != 0) if (details::os::rename(src, target) != 0)
{ {
throw spdlog_ex("rotating_file_sink: failed renaming " + filename_to_str(src) + " to " + filename_to_str(target), errno); throw spdlog_ex(
} "rotating_file_sink: failed renaming " + filename_to_str(src) + " to " + filename_to_str(target), errno);
}
} }
} }
file_helper_.reopen(true); file_helper_.reopen(true);
......
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