{"action":"created","issue":{"url":"https://api.github.com/repos/gabime/spdlog/issues/115","labels_url":"https://api.github.com/repos/gabime/spdlog/issues/115/labels{/name}","comments_url":"https://api.github.com/repos/gabime/spdlog/issues/115/comments","events_url":"https://api.github.com/repos/gabime/spdlog/issues/115/events","html_url":"https://github.com/gabime/spdlog/issues/115","id":98764573,"number":115,"title":"Nanosecond resolution timestamps","user":{"login":"rpopescu","id":41022,"avatar_url":"https://avatars.githubusercontent.com/u/41022?v=3","gravatar_id":"","url":"https://api.github.com/users/rpopescu","html_url":"https://github.com/rpopescu","followers_url":"https://api.github.com/users/rpopescu/followers","following_url":"https://api.github.com/users/rpopescu/following{/other_user}","gists_url":"https://api.github.com/users/rpopescu/gists{/gist_id}","starred_url":"https://api.github.com/users/rpopescu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rpopescu/subscriptions","organizations_url":"https://api.github.com/users/rpopescu/orgs","repos_url":"https://api.github.com/users/rpopescu/repos","events_url":"https://api.github.com/users/rpopescu/events{/privacy}","received_events_url":"https://api.github.com/users/rpopescu/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-08-03T15:05:44Z","updated_at":"2015-08-04T10:05:14Z","closed_at":null,"body":"Hi Gabi,\r\n\r\nWould be great to get nanosecond resolution timestamp capability in the log messages.\r\nI've added this by creating a new flag_formatter for \"%F\" which does a similar job as the microsecond one (\"%f\").\r\n\r\nHere's the code patch, tested on OSX and Linux:\r\n```\r\nIndex: include/spdlog/details/pattern_formatter_impl.h\r\n===================================================================\r\n--- include/spdlog/details/pattern_formatter_impl.h\t(revision 754)\r\n+++ include/spdlog/details/pattern_formatter_impl.h\t(working copy)\r\n@@ -265,6 +265,17 @@\r\n     }\r\n };\r\n \r\n+// nanoseconds\r\n+class F_formatter :public flag_formatter\r\n+{\r\n+    void format(details::log_msg& msg, const std::tm&) override\r\n+    {\r\n+        auto duration = msg.time.time_since_epoch();\r\n+        auto ns = std::chrono::duration_cast<std::chrono::nanoseconds>(duration).count() % 1000000000;\r\n+        msg.formatted << fmt::pad(static_cast<int>(ns), 9, '0');\r\n+    }\r\n+};\r\n+\r\n // AM/PM\r\n class p_formatter :public flag_formatter\r\n {\r\n@@ -575,6 +586,9 @@\r\n     case('f') :\r\n         _formatters.push_back(std::unique_ptr<details::flag_formatter>(new details::f_formatter()));\r\n         break;\r\n+    case('F') :\r\n+        _formatters.push_back(std::unique_ptr<details::flag_formatter>(new details::F_formatter()));\r\n+        break;\r\n \r\n     case('p') :\r\n         _formatters.push_back(std::unique_ptr<details::flag_formatter>(new details::p_formatter()));\r\n\r\n```"},"comment":{"url":"https://api.github.com/repos/gabime/spdlog/issues/comments/127553513","html_url":"https://github.com/gabime/spdlog/issues/115#issuecomment-127553513","issue_url":"https://api.github.com/repos/gabime/spdlog/issues/115","id":127553513,"user":{"login":"rpopescu","id":41022,"avatar_url":"https://avatars.githubusercontent.com/u/41022?v=3","gravatar_id":"","url":"https://api.github.com/users/rpopescu","html_url":"https://github.com/rpopescu","followers_url":"https://api.github.com/users/rpopescu/followers","following_url":"https://api.github.com/users/rpopescu/following{/other_user}","gists_url":"https://api.github.com/users/rpopescu/gists{/gist_id}","starred_url":"https://api.github.com/users/rpopescu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rpopescu/subscriptions","organizations_url":"https://api.github.com/users/rpopescu/orgs","repos_url":"https://api.github.com/users/rpopescu/repos","events_url":"https://api.github.com/users/rpopescu/events{/privacy}","received_events_url":"https://api.github.com/users/rpopescu/received_events","type":"User","site_admin":false},"created_at":"2015-08-04T10:05:13Z","updated_at":"2015-08-04T10:05:13Z","body":"Thanks Gabi! Forked, fixed and pull request sent."}}