{"action":"created","comment":{"url":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/comments/28682072","id":28682072,"diff_hunk":"@@ -0,0 +1,127 @@\n+module std.experimental.logger.asynclogger;\n+\n+import std.experimental.logger.core;\n+import std.concurrency;\n+\n+/** The $(D AsyncLogger) processes logs asynchronously by using another $(D Logger) implementation\n+as a backend. Every data logged to this $(D AsyncLogger) will be send to separate logging thread\n+in order to be logged there. It can help to improve logging performance for $(D log) caller,\n+for example by removing waiting for flushing logs to a file.\n+Example:\n+-------------\n+void main()\n+{\n+    import std.algorithm;\n+    import std.conv;\n+    import std.stdio;\n+    import std.datetime;\n+    import std.experimental.logger;\n+\n+    auto fl = new FileLogger(\"defaultFileLogger.log\", LogLevel.all);\n+    void logFileDefault()\n+    {\n+        fl.log(\"test message\");\n+    }\n+\n+    auto afl = new AsyncLogger(new FileLogger(\"asyncFileLogger.log\", LogLevel.all));\n+    void logFileAsync()\n+    {\n+        afl.log(\"test message\");\n+    }\n+\n+    auto r = benchmark!(logFileDefault, logFileAsync)(100_000);\n+    writeln(map!(a => to!string(to!Duration(a)))(r[]));\n+}\n+-------------\n+*/\n+final class AsyncLogger : Logger\n+{\n+    /// Shuntdown message\n+    struct ShutdownMsg {}\n+\n+    private static void spawnedFunc(shared Logger ptr) @trusted\n+    {\n+        auto l = cast(Logger)(ptr);\n+        bool isRunning = true;\n+        while (isRunning)\n+        {\n+            receive(\n+                (LogEntryBase e)\n+                {\n+                    LogEntry tmp = e;\n+                    tmp.threadId = ownerTid;\n+                    tmp.logger = l;\n+                    l.forwardMsg(tmp);\n+                },\n+                (ShutdownMsg msg) { isRunning = false; },\n+                (OwnerTerminated ex) { isRunning = false; },\n+                (Variant v) { throw new Error(\"unhandled message\"); }\n+            );\n+        }\n+    }\n+\n+    /** This constructor sets a LogLevel and starts a new logging thread\n+    that logs every entry asynchronously by using Logger. Because logger writes down\n+    all entries into special logging thread, logger should not be used further\n+    (without confidence that logger is not being used at the moment).\n+    */\n+    this(Logger logger, LogLevel lv = LogLevel.all) @trusted\n+    {\n+        super(lv);\n+        this.logger_ = cast(shared Logger)(logger);\n+        this.tid_ = spawn(&spawnedFunc, this.logger_);\n+    }\n+\n+    override void writeLogMsg(ref LogEntry payload) @trusted\n+    {\n+        LogEntryBase msg = payload;\n+        send(this.tid_, msg);\n+    }\n+\n+    /// Stops logging thread by sending ShutdownMsg to it.\n+    ~this() @trusted\n+    {\n+        send(this.tid_, ShutdownMsg());\n+    }\n+\n+    Tid tid_;","path":"std/experimental/logger/asynclogger.d","position":87,"original_position":87,"commit_id":"06c5285dbaea5c764623d6e7328fbbfc55ef5168","original_commit_id":"06c5285dbaea5c764623d6e7328fbbfc55ef5168","user":{"login":"MartinNowak","id":288976,"avatar_url":"https://avatars.githubusercontent.com/u/288976?v=3","gravatar_id":"","url":"https://api.github.com/users/MartinNowak","html_url":"https://github.com/MartinNowak","followers_url":"https://api.github.com/users/MartinNowak/followers","following_url":"https://api.github.com/users/MartinNowak/following{/other_user}","gists_url":"https://api.github.com/users/MartinNowak/gists{/gist_id}","starred_url":"https://api.github.com/users/MartinNowak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MartinNowak/subscriptions","organizations_url":"https://api.github.com/users/MartinNowak/orgs","repos_url":"https://api.github.com/users/MartinNowak/repos","events_url":"https://api.github.com/users/MartinNowak/events{/privacy}","received_events_url":"https://api.github.com/users/MartinNowak/received_events","type":"User","site_admin":false},"body":"> There should be a comment on how to use this Tid to stop the thread and/or restart it\r\n\r\nHorrible idea, an active object [[¹]](www.drdobbs.com/parallel/prefer-using-active-objects-instead-of-n/225700095) doesn't leak it's threading details. I'm not sure what you mean with restart. The only question is how to deal with exceptions of the underlying logger. You could rethrow them on the next call to AsyncLogger.","created_at":"2015-04-20T11:48:55Z","updated_at":"2015-04-20T11:48:55Z","html_url":"https://github.com/D-Programming-Language/phobos/pull/3194#discussion_r28682072","pull_request_url":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/3194","_links":{"self":{"href":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/comments/28682072"},"html":{"href":"https://github.com/D-Programming-Language/phobos/pull/3194#discussion_r28682072"},"pull_request":{"href":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/3194"}}},"pull_request":{"url":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/3194","id":33520468,"html_url":"https://github.com/D-Programming-Language/phobos/pull/3194","diff_url":"https://github.com/D-Programming-Language/phobos/pull/3194.diff","patch_url":"https://github.com/D-Programming-Language/phobos/pull/3194.patch","issue_url":"https://api.github.com/repos/D-Programming-Language/phobos/issues/3194","number":3194,"state":"open","locked":false,"title":"Add std.experimental.logger.asynclogger","user":{"login":"Groterik","id":4642962,"avatar_url":"https://avatars.githubusercontent.com/u/4642962?v=3","gravatar_id":"","url":"https://api.github.com/users/Groterik","html_url":"https://github.com/Groterik","followers_url":"https://api.github.com/users/Groterik/followers","following_url":"https://api.github.com/users/Groterik/following{/other_user}","gists_url":"https://api.github.com/users/Groterik/gists{/gist_id}","starred_url":"https://api.github.com/users/Groterik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Groterik/subscriptions","organizations_url":"https://api.github.com/users/Groterik/orgs","repos_url":"https://api.github.com/users/Groterik/repos","events_url":"https://api.github.com/users/Groterik/events{/privacy}","received_events_url":"https://api.github.com/users/Groterik/received_events","type":"User","site_admin":false},"body":"Asynchronous wrapper for std.experimental.logger. It sends log-message to special logging thread where the message is logged finally.\r\nDiscussion: http://forum.dlang.org/thread/lcsjtxorbbagmbvbllns@forum.dlang.org","created_at":"2015-04-17T07:31:30Z","updated_at":"2015-04-20T11:48:55Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9fc8301797e59802a141739eb38da344029ab906","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/3194/commits","review_comments_url":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/3194/comments","review_comment_url":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/comments{/number}","comments_url":"https://api.github.com/repos/D-Programming-Language/phobos/issues/3194/comments","statuses_url":"https://api.github.com/repos/D-Programming-Language/phobos/statuses/06c5285dbaea5c764623d6e7328fbbfc55ef5168","head":{"label":"Groterik:asynclogger","ref":"asynclogger","sha":"06c5285dbaea5c764623d6e7328fbbfc55ef5168","user":{"login":"Groterik","id":4642962,"avatar_url":"https://avatars.githubusercontent.com/u/4642962?v=3","gravatar_id":"","url":"https://api.github.com/users/Groterik","html_url":"https://github.com/Groterik","followers_url":"https://api.github.com/users/Groterik/followers","following_url":"https://api.github.com/users/Groterik/following{/other_user}","gists_url":"https://api.github.com/users/Groterik/gists{/gist_id}","starred_url":"https://api.github.com/users/Groterik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Groterik/subscriptions","organizations_url":"https://api.github.com/users/Groterik/orgs","repos_url":"https://api.github.com/users/Groterik/repos","events_url":"https://api.github.com/users/Groterik/events{/privacy}","received_events_url":"https://api.github.com/users/Groterik/received_events","type":"User","site_admin":false},"repo":{"id":33986522,"name":"phobos","full_name":"Groterik/phobos","owner":{"login":"Groterik","id":4642962,"avatar_url":"https://avatars.githubusercontent.com/u/4642962?v=3","gravatar_id":"","url":"https://api.github.com/users/Groterik","html_url":"https://github.com/Groterik","followers_url":"https://api.github.com/users/Groterik/followers","following_url":"https://api.github.com/users/Groterik/following{/other_user}","gists_url":"https://api.github.com/users/Groterik/gists{/gist_id}","starred_url":"https://api.github.com/users/Groterik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Groterik/subscriptions","organizations_url":"https://api.github.com/users/Groterik/orgs","repos_url":"https://api.github.com/users/Groterik/repos","events_url":"https://api.github.com/users/Groterik/events{/privacy}","received_events_url":"https://api.github.com/users/Groterik/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Groterik/phobos","description":"The standard library of the D programming language","fork":true,"url":"https://api.github.com/repos/Groterik/phobos","forks_url":"https://api.github.com/repos/Groterik/phobos/forks","keys_url":"https://api.github.com/repos/Groterik/phobos/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Groterik/phobos/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Groterik/phobos/teams","hooks_url":"https://api.github.com/repos/Groterik/phobos/hooks","issue_events_url":"https://api.github.com/repos/Groterik/phobos/issues/events{/number}","events_url":"https://api.github.com/repos/Groterik/phobos/events","assignees_url":"https://api.github.com/repos/Groterik/phobos/assignees{/user}","branches_url":"https://api.github.com/repos/Groterik/phobos/branches{/branch}","tags_url":"https://api.github.com/repos/Groterik/phobos/tags","blobs_url":"https://api.github.com/repos/Groterik/phobos/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Groterik/phobos/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Groterik/phobos/git/refs{/sha}","trees_url":"https://api.github.com/repos/Groterik/phobos/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Groterik/phobos/statuses/{sha}","languages_url":"https://api.github.com/repos/Groterik/phobos/languages","stargazers_url":"https://api.github.com/repos/Groterik/phobos/stargazers","contributors_url":"https://api.github.com/repos/Groterik/phobos/contributors","subscribers_url":"https://api.github.com/repos/Groterik/phobos/subscribers","subscription_url":"https://api.github.com/repos/Groterik/phobos/subscription","commits_url":"https://api.github.com/repos/Groterik/phobos/commits{/sha}","git_commits_url":"https://api.github.com/repos/Groterik/phobos/git/commits{/sha}","comments_url":"https://api.github.com/repos/Groterik/phobos/comments{/number}","issue_comment_url":"https://api.github.com/repos/Groterik/phobos/issues/comments{/number}","contents_url":"https://api.github.com/repos/Groterik/phobos/contents/{+path}","compare_url":"https://api.github.com/repos/Groterik/phobos/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Groterik/phobos/merges","archive_url":"https://api.github.com/repos/Groterik/phobos/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Groterik/phobos/downloads","issues_url":"https://api.github.com/repos/Groterik/phobos/issues{/number}","pulls_url":"https://api.github.com/repos/Groterik/phobos/pulls{/number}","milestones_url":"https://api.github.com/repos/Groterik/phobos/milestones{/number}","notifications_url":"https://api.github.com/repos/Groterik/phobos/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Groterik/phobos/labels{/name}","releases_url":"https://api.github.com/repos/Groterik/phobos/releases{/id}","created_at":"2015-04-15T09:59:59Z","updated_at":"2015-04-15T10:00:02Z","pushed_at":"2015-04-20T09:16:33Z","git_url":"git://github.com/Groterik/phobos.git","ssh_url":"git@github.com:Groterik/phobos.git","clone_url":"https://github.com/Groterik/phobos.git","svn_url":"https://github.com/Groterik/phobos","homepage":"dlang.org/phobos","size":39417,"stargazers_count":0,"watchers_count":0,"language":"D","has_issues":false,"has_downloads":true,"has_wiki":false,"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":"D-Programming-Language:master","ref":"master","sha":"41d1162619039e8e535060b920ff54cc2c44ebbb","user":{"login":"D-Programming-Language","id":565913,"avatar_url":"https://avatars.githubusercontent.com/u/565913?v=3","gravatar_id":"","url":"https://api.github.com/users/D-Programming-Language","html_url":"https://github.com/D-Programming-Language","followers_url":"https://api.github.com/users/D-Programming-Language/followers","following_url":"https://api.github.com/users/D-Programming-Language/following{/other_user}","gists_url":"https://api.github.com/users/D-Programming-Language/gists{/gist_id}","starred_url":"https://api.github.com/users/D-Programming-Language/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/D-Programming-Language/subscriptions","organizations_url":"https://api.github.com/users/D-Programming-Language/orgs","repos_url":"https://api.github.com/users/D-Programming-Language/repos","events_url":"https://api.github.com/users/D-Programming-Language/events{/privacy}","received_events_url":"https://api.github.com/users/D-Programming-Language/received_events","type":"Organization","site_admin":false},"repo":{"id":1257084,"name":"phobos","full_name":"D-Programming-Language/phobos","owner":{"login":"D-Programming-Language","id":565913,"avatar_url":"https://avatars.githubusercontent.com/u/565913?v=3","gravatar_id":"","url":"https://api.github.com/users/D-Programming-Language","html_url":"https://github.com/D-Programming-Language","followers_url":"https://api.github.com/users/D-Programming-Language/followers","following_url":"https://api.github.com/users/D-Programming-Language/following{/other_user}","gists_url":"https://api.github.com/users/D-Programming-Language/gists{/gist_id}","starred_url":"https://api.github.com/users/D-Programming-Language/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/D-Programming-Language/subscriptions","organizations_url":"https://api.github.com/users/D-Programming-Language/orgs","repos_url":"https://api.github.com/users/D-Programming-Language/repos","events_url":"https://api.github.com/users/D-Programming-Language/events{/privacy}","received_events_url":"https://api.github.com/users/D-Programming-Language/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/D-Programming-Language/phobos","description":"The standard library of the D programming language","fork":false,"url":"https://api.github.com/repos/D-Programming-Language/phobos","forks_url":"https://api.github.com/repos/D-Programming-Language/phobos/forks","keys_url":"https://api.github.com/repos/D-Programming-Language/phobos/keys{/key_id}","collaborators_url":"https://api.github.com/repos/D-Programming-Language/phobos/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/D-Programming-Language/phobos/teams","hooks_url":"https://api.github.com/repos/D-Programming-Language/phobos/hooks","issue_events_url":"https://api.github.com/repos/D-Programming-Language/phobos/issues/events{/number}","events_url":"https://api.github.com/repos/D-Programming-Language/phobos/events","assignees_url":"https://api.github.com/repos/D-Programming-Language/phobos/assignees{/user}","branches_url":"https://api.github.com/repos/D-Programming-Language/phobos/branches{/branch}","tags_url":"https://api.github.com/repos/D-Programming-Language/phobos/tags","blobs_url":"https://api.github.com/repos/D-Programming-Language/phobos/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/D-Programming-Language/phobos/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/D-Programming-Language/phobos/git/refs{/sha}","trees_url":"https://api.github.com/repos/D-Programming-Language/phobos/git/trees{/sha}","statuses_url":"https://api.github.com/repos/D-Programming-Language/phobos/statuses/{sha}","languages_url":"https://api.github.com/repos/D-Programming-Language/phobos/languages","stargazers_url":"https://api.github.com/repos/D-Programming-Language/phobos/stargazers","contributors_url":"https://api.github.com/repos/D-Programming-Language/phobos/contributors","subscribers_url":"https://api.github.com/repos/D-Programming-Language/phobos/subscribers","subscription_url":"https://api.github.com/repos/D-Programming-Language/phobos/subscription","commits_url":"https://api.github.com/repos/D-Programming-Language/phobos/commits{/sha}","git_commits_url":"https://api.github.com/repos/D-Programming-Language/phobos/git/commits{/sha}","comments_url":"https://api.github.com/repos/D-Programming-Language/phobos/comments{/number}","issue_comment_url":"https://api.github.com/repos/D-Programming-Language/phobos/issues/comments{/number}","contents_url":"https://api.github.com/repos/D-Programming-Language/phobos/contents/{+path}","compare_url":"https://api.github.com/repos/D-Programming-Language/phobos/compare/{base}...{head}","merges_url":"https://api.github.com/repos/D-Programming-Language/phobos/merges","archive_url":"https://api.github.com/repos/D-Programming-Language/phobos/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/D-Programming-Language/phobos/downloads","issues_url":"https://api.github.com/repos/D-Programming-Language/phobos/issues{/number}","pulls_url":"https://api.github.com/repos/D-Programming-Language/phobos/pulls{/number}","milestones_url":"https://api.github.com/repos/D-Programming-Language/phobos/milestones{/number}","notifications_url":"https://api.github.com/repos/D-Programming-Language/phobos/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/D-Programming-Language/phobos/labels{/name}","releases_url":"https://api.github.com/repos/D-Programming-Language/phobos/releases{/id}","created_at":"2011-01-15T07:00:06Z","updated_at":"2015-04-19T20:04:43Z","pushed_at":"2015-04-20T09:16:35Z","git_url":"git://github.com/D-Programming-Language/phobos.git","ssh_url":"git@github.com:D-Programming-Language/phobos.git","clone_url":"https://github.com/D-Programming-Language/phobos.git","svn_url":"https://github.com/D-Programming-Language/phobos","homepage":"dlang.org/phobos","size":72394,"stargazers_count":592,"watchers_count":592,"language":"D","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":395,"mirror_url":null,"open_issues_count":68,"forks":395,"open_issues":68,"watchers":592,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/3194"},"html":{"href":"https://github.com/D-Programming-Language/phobos/pull/3194"},"issue":{"href":"https://api.github.com/repos/D-Programming-Language/phobos/issues/3194"},"comments":{"href":"https://api.github.com/repos/D-Programming-Language/phobos/issues/3194/comments"},"review_comments":{"href":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/3194/comments"},"review_comment":{"href":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/D-Programming-Language/phobos/pulls/3194/commits"},"statuses":{"href":"https://api.github.com/repos/D-Programming-Language/phobos/statuses/06c5285dbaea5c764623d6e7328fbbfc55ef5168"}}}}