{"action":"created","comment":{"url":"https://api.github.com/repos/KjellKod/g3log/pulls/comments/68705959","id":68705959,"diff_hunk":"@@ -69,6 +72,51 @@ namespace g3 {\n    /// * format string must conform to std::put_time\n    /// This is similar to std::put_time(std::localtime(std::time_t*), time_format.c_str());\n \n+   namespace {\n+      std::string kIdentifier = \"%f\";\n+      ushort      kZeroes[]   = {3, 6, 9};\n+   }\n+\n+   std::string localtime_formatted(const timespec &time_snapshot, const std::string &time_format) {\n+\n+      // copying format string to a separate buffer\n+      auto format_buffer = time_format;\n+\n+      // creating an array of sec fractional parts\n+      std::string value_str[] = {\n+         // TODO: there should be a way computing pow(kZeroes[2] - kZeroes[0], 10) using integers\n+         std::to_string((long)std::round((long double)time_snapshot.tv_nsec / 1000000)),\n+         std::to_string((long)std::round((long double)time_snapshot.tv_nsec / 1000)),\n+         std::to_string(time_snapshot.tv_nsec)\n+      };\n+\n+      // adding leading zeros to sec fractional parts\n+      for (ushort i = 0; i < sizeof(kZeroes)/sizeof(*kZeroes); i++) {\n+         value_str[i] = std::string(kZeroes[i] - value_str[i].length(), '0') + value_str[i];\n+      }\n+\n+      // replacing %f[3|6|9] with actual sec fractional value\n+      for(size_t pos = 0; (pos = format_buffer.find(kIdentifier, pos)) != std::string::npos; pos += kIdentifier.size()) {\n+\n+         // figuring out whether this is nano, micro or milli identifier\n+         ushort index = 2;\n+         char ch = (format_buffer.size() > pos + kIdentifier.size() ? format_buffer.at(pos + kIdentifier.size()) : '\\0');\n+         switch (ch) {\n+            case '3': index = 0;    break;\n+            case '6': index = 1;    break;\n+            case '9': index = 2;    break;\n+\t    default : ch    = '\\0'; break;\n+         }\n+\n+         // replacing %f with sec fractional part value\n+         format_buffer.replace(pos, kIdentifier.size() + (ch == '\\0' ? 0 : 1), value_str[index]);","path":"src/time.cpp","position":58,"original_position":58,"commit_id":"73947c363e7e10bd42786e34dfd129f1adffeff8","original_commit_id":"73947c363e7e10bd42786e34dfd129f1adffeff8","user":{"login":"KjellKod","id":331742,"avatar_url":"https://avatars.githubusercontent.com/u/331742?v=3","gravatar_id":"","url":"https://api.github.com/users/KjellKod","html_url":"https://github.com/KjellKod","followers_url":"https://api.github.com/users/KjellKod/followers","following_url":"https://api.github.com/users/KjellKod/following{/other_user}","gists_url":"https://api.github.com/users/KjellKod/gists{/gist_id}","starred_url":"https://api.github.com/users/KjellKod/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/KjellKod/subscriptions","organizations_url":"https://api.github.com/users/KjellKod/orgs","repos_url":"https://api.github.com/users/KjellKod/repos","events_url":"https://api.github.com/users/KjellKod/events{/privacy}","received_events_url":"https://api.github.com/users/KjellKod/received_events","type":"User","site_admin":false},"body":"I think it overall looks good. \r\n\r\nI would advice on having the cost for the string creation only be done if it is needed. I.e now each log entry pays the penalty for creating the three fractional strings even if it's not needed. \r\n\r\nThe more remote chance that someone wants all fractions of a second should be considered the exceptional case and in that case that use case can pay for the extra overhead.\r\n\r\nI.e.  som pseudo code\r\n\r\n```\r\nenum class TimeFractions {Milli, Micro, Nano};\r\n```\r\nsomething like ```\r\n         switch (ch) {\r\n             case '3': fraction = TimeFractions::Milli;    break;\r\n             case '6': fraction = TimeFractions::Micro;    break;\r\n             case '9': fraction = TimeFractions::Nano;    break;\r\n \t    default : ch    = '\\0'; break;\r\n          }\r\n```\r\n\r\nThen\r\n```\r\nif (fraction != TimeFractions::Ignored) {\r\n   format_buffer.replace(pos,  fraction_identifier_size(fraction), fraction_tostring(fraction,  time_snapshot));\r\n}\r\n```\r\n\r\nAnd \r\nstd::string  fraction_tostring(TimeFractions fraction,  const timespec& time_snapshot) {\r\n   switch (fraction) {\r\n     case TimeFractions::Milli: return /*....*/\r\n .... \r\n}\r\n```\r\n\r\n","created_at":"2016-06-28T06:58:53Z","updated_at":"2016-06-28T06:58:53Z","html_url":"https://github.com/KjellKod/g3log/pull/90#discussion_r68705959","pull_request_url":"https://api.github.com/repos/KjellKod/g3log/pulls/90","_links":{"self":{"href":"https://api.github.com/repos/KjellKod/g3log/pulls/comments/68705959"},"html":{"href":"https://github.com/KjellKod/g3log/pull/90#discussion_r68705959"},"pull_request":{"href":"https://api.github.com/repos/KjellKod/g3log/pulls/90"}}},"pull_request":{"url":"https://api.github.com/repos/KjellKod/g3log/pulls/90","id":69277010,"html_url":"https://github.com/KjellKod/g3log/pull/90","diff_url":"https://github.com/KjellKod/g3log/pull/90.diff","patch_url":"https://github.com/KjellKod/g3log/pull/90.patch","issue_url":"https://api.github.com/repos/KjellKod/g3log/issues/90","number":90,"state":"open","locked":false,"title":"Added TimestampProvider API Enabling Milli / Micro Second Support in Timestamps","user":{"login":"gimesketvirtadieni","id":7950278,"avatar_url":"https://avatars.githubusercontent.com/u/7950278?v=3","gravatar_id":"","url":"https://api.github.com/users/gimesketvirtadieni","html_url":"https://github.com/gimesketvirtadieni","followers_url":"https://api.github.com/users/gimesketvirtadieni/followers","following_url":"https://api.github.com/users/gimesketvirtadieni/following{/other_user}","gists_url":"https://api.github.com/users/gimesketvirtadieni/gists{/gist_id}","starred_url":"https://api.github.com/users/gimesketvirtadieni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gimesketvirtadieni/subscriptions","organizations_url":"https://api.github.com/users/gimesketvirtadieni/orgs","repos_url":"https://api.github.com/users/gimesketvirtadieni/repos","events_url":"https://api.github.com/users/gimesketvirtadieni/events{/privacy}","received_events_url":"https://api.github.com/users/gimesketvirtadieni/received_events","type":"User","site_admin":false},"body":"This is a pull request for a functionality for dynamic sink removal","created_at":"2016-05-08T19:27:26Z","updated_at":"2016-06-28T06:58:53Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9389bd9d540a1c12976149ae1ab88a65c54aa6aa","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/KjellKod/g3log/pulls/90/commits","review_comments_url":"https://api.github.com/repos/KjellKod/g3log/pulls/90/comments","review_comment_url":"https://api.github.com/repos/KjellKod/g3log/pulls/comments{/number}","comments_url":"https://api.github.com/repos/KjellKod/g3log/issues/90/comments","statuses_url":"https://api.github.com/repos/KjellKod/g3log/statuses/73947c363e7e10bd42786e34dfd129f1adffeff8","head":{"label":"gimesketvirtadieni:upstream","ref":"upstream","sha":"73947c363e7e10bd42786e34dfd129f1adffeff8","user":{"login":"gimesketvirtadieni","id":7950278,"avatar_url":"https://avatars.githubusercontent.com/u/7950278?v=3","gravatar_id":"","url":"https://api.github.com/users/gimesketvirtadieni","html_url":"https://github.com/gimesketvirtadieni","followers_url":"https://api.github.com/users/gimesketvirtadieni/followers","following_url":"https://api.github.com/users/gimesketvirtadieni/following{/other_user}","gists_url":"https://api.github.com/users/gimesketvirtadieni/gists{/gist_id}","starred_url":"https://api.github.com/users/gimesketvirtadieni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gimesketvirtadieni/subscriptions","organizations_url":"https://api.github.com/users/gimesketvirtadieni/orgs","repos_url":"https://api.github.com/users/gimesketvirtadieni/repos","events_url":"https://api.github.com/users/gimesketvirtadieni/events{/privacy}","received_events_url":"https://api.github.com/users/gimesketvirtadieni/received_events","type":"User","site_admin":false},"repo":{"id":58325214,"name":"g3log","full_name":"gimesketvirtadieni/g3log","owner":{"login":"gimesketvirtadieni","id":7950278,"avatar_url":"https://avatars.githubusercontent.com/u/7950278?v=3","gravatar_id":"","url":"https://api.github.com/users/gimesketvirtadieni","html_url":"https://github.com/gimesketvirtadieni","followers_url":"https://api.github.com/users/gimesketvirtadieni/followers","following_url":"https://api.github.com/users/gimesketvirtadieni/following{/other_user}","gists_url":"https://api.github.com/users/gimesketvirtadieni/gists{/gist_id}","starred_url":"https://api.github.com/users/gimesketvirtadieni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gimesketvirtadieni/subscriptions","organizations_url":"https://api.github.com/users/gimesketvirtadieni/orgs","repos_url":"https://api.github.com/users/gimesketvirtadieni/repos","events_url":"https://api.github.com/users/gimesketvirtadieni/events{/privacy}","received_events_url":"https://api.github.com/users/gimesketvirtadieni/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/gimesketvirtadieni/g3log","description":"G3log is  an asynchronous, \"crash safe\", logger that is easy to use with default logging sinks or you can add your own.  G3log is made with plain C++11 with no external libraries (except gtest used for unit tests). G3log is made to be cross-platform, currently running on OSX, Windows and several Linux distros.  See Readme below for details of usage.","fork":true,"url":"https://api.github.com/repos/gimesketvirtadieni/g3log","forks_url":"https://api.github.com/repos/gimesketvirtadieni/g3log/forks","keys_url":"https://api.github.com/repos/gimesketvirtadieni/g3log/keys{/key_id}","collaborators_url":"https://api.github.com/repos/gimesketvirtadieni/g3log/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/gimesketvirtadieni/g3log/teams","hooks_url":"https://api.github.com/repos/gimesketvirtadieni/g3log/hooks","issue_events_url":"https://api.github.com/repos/gimesketvirtadieni/g3log/issues/events{/number}","events_url":"https://api.github.com/repos/gimesketvirtadieni/g3log/events","assignees_url":"https://api.github.com/repos/gimesketvirtadieni/g3log/assignees{/user}","branches_url":"https://api.github.com/repos/gimesketvirtadieni/g3log/branches{/branch}","tags_url":"https://api.github.com/repos/gimesketvirtadieni/g3log/tags","blobs_url":"https://api.github.com/repos/gimesketvirtadieni/g3log/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/gimesketvirtadieni/g3log/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/gimesketvirtadieni/g3log/git/refs{/sha}","trees_url":"https://api.github.com/repos/gimesketvirtadieni/g3log/git/trees{/sha}","statuses_url":"https://api.github.com/repos/gimesketvirtadieni/g3log/statuses/{sha}","languages_url":"https://api.github.com/repos/gimesketvirtadieni/g3log/languages","stargazers_url":"https://api.github.com/repos/gimesketvirtadieni/g3log/stargazers","contributors_url":"https://api.github.com/repos/gimesketvirtadieni/g3log/contributors","subscribers_url":"https://api.github.com/repos/gimesketvirtadieni/g3log/subscribers","subscription_url":"https://api.github.com/repos/gimesketvirtadieni/g3log/subscription","commits_url":"https://api.github.com/repos/gimesketvirtadieni/g3log/commits{/sha}","git_commits_url":"https://api.github.com/repos/gimesketvirtadieni/g3log/git/commits{/sha}","comments_url":"https://api.github.com/repos/gimesketvirtadieni/g3log/comments{/number}","issue_comment_url":"https://api.github.com/repos/gimesketvirtadieni/g3log/issues/comments{/number}","contents_url":"https://api.github.com/repos/gimesketvirtadieni/g3log/contents/{+path}","compare_url":"https://api.github.com/repos/gimesketvirtadieni/g3log/compare/{base}...{head}","merges_url":"https://api.github.com/repos/gimesketvirtadieni/g3log/merges","archive_url":"https://api.github.com/repos/gimesketvirtadieni/g3log/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/gimesketvirtadieni/g3log/downloads","issues_url":"https://api.github.com/repos/gimesketvirtadieni/g3log/issues{/number}","pulls_url":"https://api.github.com/repos/gimesketvirtadieni/g3log/pulls{/number}","milestones_url":"https://api.github.com/repos/gimesketvirtadieni/g3log/milestones{/number}","notifications_url":"https://api.github.com/repos/gimesketvirtadieni/g3log/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/gimesketvirtadieni/g3log/labels{/name}","releases_url":"https://api.github.com/repos/gimesketvirtadieni/g3log/releases{/id}","deployments_url":"https://api.github.com/repos/gimesketvirtadieni/g3log/deployments","created_at":"2016-05-08T18:23:48Z","updated_at":"2016-05-08T18:23:51Z","pushed_at":"2016-06-27T20:03:56Z","git_url":"git://github.com/gimesketvirtadieni/g3log.git","ssh_url":"git@github.com:gimesketvirtadieni/g3log.git","clone_url":"https://github.com/gimesketvirtadieni/g3log.git","svn_url":"https://github.com/gimesketvirtadieni/g3log","homepage":"http://github.com/KjellKod/g3log","size":4253,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"KjellKod:master","ref":"master","sha":"6c1698c4f7db6b9e4246ead38051f9866ea3ac06","user":{"login":"KjellKod","id":331742,"avatar_url":"https://avatars.githubusercontent.com/u/331742?v=3","gravatar_id":"","url":"https://api.github.com/users/KjellKod","html_url":"https://github.com/KjellKod","followers_url":"https://api.github.com/users/KjellKod/followers","following_url":"https://api.github.com/users/KjellKod/following{/other_user}","gists_url":"https://api.github.com/users/KjellKod/gists{/gist_id}","starred_url":"https://api.github.com/users/KjellKod/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/KjellKod/subscriptions","organizations_url":"https://api.github.com/users/KjellKod/orgs","repos_url":"https://api.github.com/users/KjellKod/repos","events_url":"https://api.github.com/users/KjellKod/events{/privacy}","received_events_url":"https://api.github.com/users/KjellKod/received_events","type":"User","site_admin":false},"repo":{"id":25021151,"name":"g3log","full_name":"KjellKod/g3log","owner":{"login":"KjellKod","id":331742,"avatar_url":"https://avatars.githubusercontent.com/u/331742?v=3","gravatar_id":"","url":"https://api.github.com/users/KjellKod","html_url":"https://github.com/KjellKod","followers_url":"https://api.github.com/users/KjellKod/followers","following_url":"https://api.github.com/users/KjellKod/following{/other_user}","gists_url":"https://api.github.com/users/KjellKod/gists{/gist_id}","starred_url":"https://api.github.com/users/KjellKod/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/KjellKod/subscriptions","organizations_url":"https://api.github.com/users/KjellKod/orgs","repos_url":"https://api.github.com/users/KjellKod/repos","events_url":"https://api.github.com/users/KjellKod/events{/privacy}","received_events_url":"https://api.github.com/users/KjellKod/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/KjellKod/g3log","description":"G3log is  an asynchronous, \"crash safe\", logger that is easy to use with default logging sinks or you can add your own.  G3log is made with plain C++11 with no external libraries (except gtest used for unit tests). G3log is made to be cross-platform, currently running on OSX, Windows and several Linux distros.  See Readme below for details of usage.","fork":false,"url":"https://api.github.com/repos/KjellKod/g3log","forks_url":"https://api.github.com/repos/KjellKod/g3log/forks","keys_url":"https://api.github.com/repos/KjellKod/g3log/keys{/key_id}","collaborators_url":"https://api.github.com/repos/KjellKod/g3log/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/KjellKod/g3log/teams","hooks_url":"https://api.github.com/repos/KjellKod/g3log/hooks","issue_events_url":"https://api.github.com/repos/KjellKod/g3log/issues/events{/number}","events_url":"https://api.github.com/repos/KjellKod/g3log/events","assignees_url":"https://api.github.com/repos/KjellKod/g3log/assignees{/user}","branches_url":"https://api.github.com/repos/KjellKod/g3log/branches{/branch}","tags_url":"https://api.github.com/repos/KjellKod/g3log/tags","blobs_url":"https://api.github.com/repos/KjellKod/g3log/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/KjellKod/g3log/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/KjellKod/g3log/git/refs{/sha}","trees_url":"https://api.github.com/repos/KjellKod/g3log/git/trees{/sha}","statuses_url":"https://api.github.com/repos/KjellKod/g3log/statuses/{sha}","languages_url":"https://api.github.com/repos/KjellKod/g3log/languages","stargazers_url":"https://api.github.com/repos/KjellKod/g3log/stargazers","contributors_url":"https://api.github.com/repos/KjellKod/g3log/contributors","subscribers_url":"https://api.github.com/repos/KjellKod/g3log/subscribers","subscription_url":"https://api.github.com/repos/KjellKod/g3log/subscription","commits_url":"https://api.github.com/repos/KjellKod/g3log/commits{/sha}","git_commits_url":"https://api.github.com/repos/KjellKod/g3log/git/commits{/sha}","comments_url":"https://api.github.com/repos/KjellKod/g3log/comments{/number}","issue_comment_url":"https://api.github.com/repos/KjellKod/g3log/issues/comments{/number}","contents_url":"https://api.github.com/repos/KjellKod/g3log/contents/{+path}","compare_url":"https://api.github.com/repos/KjellKod/g3log/compare/{base}...{head}","merges_url":"https://api.github.com/repos/KjellKod/g3log/merges","archive_url":"https://api.github.com/repos/KjellKod/g3log/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/KjellKod/g3log/downloads","issues_url":"https://api.github.com/repos/KjellKod/g3log/issues{/number}","pulls_url":"https://api.github.com/repos/KjellKod/g3log/pulls{/number}","milestones_url":"https://api.github.com/repos/KjellKod/g3log/milestones{/number}","notifications_url":"https://api.github.com/repos/KjellKod/g3log/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/KjellKod/g3log/labels{/name}","releases_url":"https://api.github.com/repos/KjellKod/g3log/releases{/id}","deployments_url":"https://api.github.com/repos/KjellKod/g3log/deployments","created_at":"2014-10-10T05:06:00Z","updated_at":"2016-06-27T14:58:26Z","pushed_at":"2016-06-27T20:03:56Z","git_url":"git://github.com/KjellKod/g3log.git","ssh_url":"git@github.com:KjellKod/g3log.git","clone_url":"https://github.com/KjellKod/g3log.git","svn_url":"https://github.com/KjellKod/g3log","homepage":"http://github.com/KjellKod/g3log","size":4486,"stargazers_count":149,"watchers_count":149,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":53,"mirror_url":null,"open_issues_count":6,"forks":53,"open_issues":6,"watchers":149,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/KjellKod/g3log/pulls/90"},"html":{"href":"https://github.com/KjellKod/g3log/pull/90"},"issue":{"href":"https://api.github.com/repos/KjellKod/g3log/issues/90"},"comments":{"href":"https://api.github.com/repos/KjellKod/g3log/issues/90/comments"},"review_comments":{"href":"https://api.github.com/repos/KjellKod/g3log/pulls/90/comments"},"review_comment":{"href":"https://api.github.com/repos/KjellKod/g3log/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/KjellKod/g3log/pulls/90/commits"},"statuses":{"href":"https://api.github.com/repos/KjellKod/g3log/statuses/73947c363e7e10bd42786e34dfd129f1adffeff8"}}}}
{"actor":{"display_login":"KjellKod"}}