diff --git a/include/spdlog/details/pattern_formatter_impl.h b/include/spdlog/details/pattern_formatter_impl.h index a5b2d21f..137037ec 100644 --- a/include/spdlog/details/pattern_formatter_impl.h +++ b/include/spdlog/details/pattern_formatter_impl.h @@ -265,6 +265,17 @@ class f_formatter :public flag_formatter } }; +// nanoseconds +class F_formatter :public flag_formatter +{ + void format(details::log_msg& msg, const std::tm&) override + { + auto duration = msg.time.time_since_epoch(); + auto ns = std::chrono::duration_cast(duration).count() % 1000000000; + msg.formatted << fmt::pad(static_cast(ns), 9, '0'); + } +}; + // AM/PM class p_formatter :public flag_formatter { @@ -575,6 +586,9 @@ inline void spdlog::pattern_formatter::handle_flag(char flag) case('f') : _formatters.push_back(std::unique_ptr(new details::f_formatter())); break; + case('F') : + _formatters.push_back(std::unique_ptr(new details::F_formatter())); + break; case('p') : _formatters.push_back(std::unique_ptr(new details::p_formatter()));