{"action":"created","comment":{"url":"https://api.github.com/repos/ponylang/ponyc/pulls/comments/57948614","id":57948614,"diff_hunk":"@@ -0,0 +1,196 @@\n+\"\"\"\n+# Logger package\n+\n+Provides basic logging facilities. For most use cases, the `StringLogger` class\n+will be used. On construction, it takes 2 parameters and a 3rd optional\n+parameter:\n+\n+* LogLevel below which no output will be logged\n+* OutStream to log to\n+* Optional LogFormatter\n+\n+If you need to log arbitrary objects, take a look at `ObjectLogger[A]` which\n+can log arbitrary objects so long as you provide it a lambda to covert from A\n+to String.\n+\n+## API Philosophy\n+\n+The API for using Logger is an attempt to abide by the Pony philosophy of first,\n+be correct and secondly, aim for performance. One of the ways that logging can\n+slow your system down is by having to evaluate expressions to be logged\n+whether they will be logged or not (based on the level of logging). For example:\n+\n+logger.log(Warn, name + \": \" + reason)\n+\n+will construct a new String regardless of whether we will end up logging the\n+message or not.\n+\n+The Logger API uses boolean short circuiting to avoid this.\n+\n+logger(Warn) and logger.log(name + \": \" + reason)\n+\n+will not evaluate the expression to be logged unless the log level Warn is at\n+or above the overall log level for our logging. This is as close as we can get\n+to zero cost for items that aren't going to end up being logged.\n+\n+## Example programs\n+\n+### String Logger\n+\n+The following program will output 'my warn message' and 'my error message' to\n+STDOUT in the standard default log format.\n+\n+```pony\n+use \"logger\"\n+\n+actor Main\n+  new create(env: Env) =>\n+    let logger = StringLogger(\n+      Warn,\n+      env.out)\n+\n+    logger(Fine) and logger.log(\"my fine message\")\n+    logger(Info) and logger.log(\"my info message\")\n+    logger(Warn) and logger.log(\"my warn message\")\n+    logger(Error) and logger.log(\"my error message\")\n+```\n+\n+### ObjectLogger[A]\n+\n+The following program will output '42' to STDOUT in the standard default log\n+format.\n+\n+```pony\n+use \"logger\"\n+\n+actor Main\n+  new create(env: Env) =>\n+    let logger = ObjectLogger[U64](Fine,\n+    env.out,\n+    lambda(a: U64): String => a.string() end)\n+\n+    logger(Error) and logger.log(U64(42))\n+```\n+\n+## Custom formatting your logs\n+\n+The Logger package provides an interface for formatting logs. If you wish to\n+override the standard formatting, you can create an object that implements:\n+\n+```pony\n+interface LogFormatter\n+  fun apply(\n+    msg: String,\n+    file_name: String,\n+    file_linenum: String,\n+    file_linepos: String): String\n+```\n+\n+This can either be a class or because the interface only has a single apply\n+method, can also be a lambda.\n+\"\"\"\n+\n+type LogLevel is\n+  ( Fine\n+  | Info\n+  | Warn\n+  | Error\n+  )\n+\n+primitive Fine\n+  fun apply(): U32 => 0\n+\n+primitive Info\n+  fun apply(): U32 => 1\n+\n+primitive Warn\n+  fun apply(): U32 => 2\n+\n+primitive Error\n+  fun apply(): U32 => 3\n+\n+trait val Logger[A]\n+  fun apply(level: LogLevel): Bool\n+  fun log(value: A, loc: SourceLoc = __loc): Bool\n+","path":"packages/logger/logger.pony","position":115,"original_position":115,"commit_id":"8c62eb747686677ef60118587c899f4d58b04160","original_commit_id":"8c62eb747686677ef60118587c899f4d58b04160","user":{"login":"sylvanc","id":2785007,"avatar_url":"https://avatars.githubusercontent.com/u/2785007?v=3","gravatar_id":"","url":"https://api.github.com/users/sylvanc","html_url":"https://github.com/sylvanc","followers_url":"https://api.github.com/users/sylvanc/followers","following_url":"https://api.github.com/users/sylvanc/following{/other_user}","gists_url":"https://api.github.com/users/sylvanc/gists{/gist_id}","starred_url":"https://api.github.com/users/sylvanc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sylvanc/subscriptions","organizations_url":"https://api.github.com/users/sylvanc/orgs","repos_url":"https://api.github.com/users/sylvanc/repos","events_url":"https://api.github.com/users/sylvanc/events{/privacy}","received_events_url":"https://api.github.com/users/sylvanc/received_events","type":"User","site_admin":false},"body":"Why not a single logger, and a convenience type like this:\r\n\r\n```pony\r\nprimitive StringLogger\r\n  fun apply(level: LogLevel, out: OutStream): Logger[String] =>\r\n    Logger[String](level, out, lambda(s: String): String => s end)\r\n```\r\n","created_at":"2016-03-30T19:29:07Z","updated_at":"2016-03-30T19:29:07Z","html_url":"https://github.com/ponylang/ponyc/pull/657#discussion_r57948614","pull_request_url":"https://api.github.com/repos/ponylang/ponyc/pulls/657","_links":{"self":{"href":"https://api.github.com/repos/ponylang/ponyc/pulls/comments/57948614"},"html":{"href":"https://github.com/ponylang/ponyc/pull/657#discussion_r57948614"},"pull_request":{"href":"https://api.github.com/repos/ponylang/ponyc/pulls/657"}}},"pull_request":{"url":"https://api.github.com/repos/ponylang/ponyc/pulls/657","id":64361289,"html_url":"https://github.com/ponylang/ponyc/pull/657","diff_url":"https://github.com/ponylang/ponyc/pull/657.diff","patch_url":"https://github.com/ponylang/ponyc/pull/657.patch","issue_url":"https://api.github.com/repos/ponylang/ponyc/issues/657","number":657,"state":"open","locked":false,"title":"Simple logger","user":{"login":"SeanTAllen","id":193596,"avatar_url":"https://avatars.githubusercontent.com/u/193596?v=3","gravatar_id":"","url":"https://api.github.com/users/SeanTAllen","html_url":"https://github.com/SeanTAllen","followers_url":"https://api.github.com/users/SeanTAllen/followers","following_url":"https://api.github.com/users/SeanTAllen/following{/other_user}","gists_url":"https://api.github.com/users/SeanTAllen/gists{/gist_id}","starred_url":"https://api.github.com/users/SeanTAllen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SeanTAllen/subscriptions","organizations_url":"https://api.github.com/users/SeanTAllen/orgs","repos_url":"https://api.github.com/users/SeanTAllen/repos","events_url":"https://api.github.com/users/SeanTAllen/events{/privacy}","received_events_url":"https://api.github.com/users/SeanTAllen/received_events","type":"User","site_admin":false},"body":"@sylvanc this is mostly your code. anything here that should change, code or docs wise?\r\n\r\ndon't merge this, I need to add tests. opening now for early review that I can update.\r\n","created_at":"2016-03-28T19:16:07Z","updated_at":"2016-03-30T19:29:07Z","closed_at":null,"merged_at":null,"merge_commit_sha":"656a6b1ccc8f36085380282269df0f639d8dacde","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ponylang/ponyc/pulls/657/commits","review_comments_url":"https://api.github.com/repos/ponylang/ponyc/pulls/657/comments","review_comment_url":"https://api.github.com/repos/ponylang/ponyc/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ponylang/ponyc/issues/657/comments","statuses_url":"https://api.github.com/repos/ponylang/ponyc/statuses/8c62eb747686677ef60118587c899f4d58b04160","head":{"label":"ponylang:simple-logger-redux","ref":"simple-logger-redux","sha":"8c62eb747686677ef60118587c899f4d58b04160","user":{"login":"ponylang","id":12997238,"avatar_url":"https://avatars.githubusercontent.com/u/12997238?v=3","gravatar_id":"","url":"https://api.github.com/users/ponylang","html_url":"https://github.com/ponylang","followers_url":"https://api.github.com/users/ponylang/followers","following_url":"https://api.github.com/users/ponylang/following{/other_user}","gists_url":"https://api.github.com/users/ponylang/gists{/gist_id}","starred_url":"https://api.github.com/users/ponylang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ponylang/subscriptions","organizations_url":"https://api.github.com/users/ponylang/orgs","repos_url":"https://api.github.com/users/ponylang/repos","events_url":"https://api.github.com/users/ponylang/events{/privacy}","received_events_url":"https://api.github.com/users/ponylang/received_events","type":"Organization","site_admin":false},"repo":{"id":6667084,"name":"ponyc","full_name":"ponylang/ponyc","owner":{"login":"ponylang","id":12997238,"avatar_url":"https://avatars.githubusercontent.com/u/12997238?v=3","gravatar_id":"","url":"https://api.github.com/users/ponylang","html_url":"https://github.com/ponylang","followers_url":"https://api.github.com/users/ponylang/followers","following_url":"https://api.github.com/users/ponylang/following{/other_user}","gists_url":"https://api.github.com/users/ponylang/gists{/gist_id}","starred_url":"https://api.github.com/users/ponylang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ponylang/subscriptions","organizations_url":"https://api.github.com/users/ponylang/orgs","repos_url":"https://api.github.com/users/ponylang/repos","events_url":"https://api.github.com/users/ponylang/events{/privacy}","received_events_url":"https://api.github.com/users/ponylang/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ponylang/ponyc","description":"Pony Compiler","fork":false,"url":"https://api.github.com/repos/ponylang/ponyc","forks_url":"https://api.github.com/repos/ponylang/ponyc/forks","keys_url":"https://api.github.com/repos/ponylang/ponyc/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ponylang/ponyc/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ponylang/ponyc/teams","hooks_url":"https://api.github.com/repos/ponylang/ponyc/hooks","issue_events_url":"https://api.github.com/repos/ponylang/ponyc/issues/events{/number}","events_url":"https://api.github.com/repos/ponylang/ponyc/events","assignees_url":"https://api.github.com/repos/ponylang/ponyc/assignees{/user}","branches_url":"https://api.github.com/repos/ponylang/ponyc/branches{/branch}","tags_url":"https://api.github.com/repos/ponylang/ponyc/tags","blobs_url":"https://api.github.com/repos/ponylang/ponyc/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ponylang/ponyc/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ponylang/ponyc/git/refs{/sha}","trees_url":"https://api.github.com/repos/ponylang/ponyc/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ponylang/ponyc/statuses/{sha}","languages_url":"https://api.github.com/repos/ponylang/ponyc/languages","stargazers_url":"https://api.github.com/repos/ponylang/ponyc/stargazers","contributors_url":"https://api.github.com/repos/ponylang/ponyc/contributors","subscribers_url":"https://api.github.com/repos/ponylang/ponyc/subscribers","subscription_url":"https://api.github.com/repos/ponylang/ponyc/subscription","commits_url":"https://api.github.com/repos/ponylang/ponyc/commits{/sha}","git_commits_url":"https://api.github.com/repos/ponylang/ponyc/git/commits{/sha}","comments_url":"https://api.github.com/repos/ponylang/ponyc/comments{/number}","issue_comment_url":"https://api.github.com/repos/ponylang/ponyc/issues/comments{/number}","contents_url":"https://api.github.com/repos/ponylang/ponyc/contents/{+path}","compare_url":"https://api.github.com/repos/ponylang/ponyc/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ponylang/ponyc/merges","archive_url":"https://api.github.com/repos/ponylang/ponyc/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ponylang/ponyc/downloads","issues_url":"https://api.github.com/repos/ponylang/ponyc/issues{/number}","pulls_url":"https://api.github.com/repos/ponylang/ponyc/pulls{/number}","milestones_url":"https://api.github.com/repos/ponylang/ponyc/milestones{/number}","notifications_url":"https://api.github.com/repos/ponylang/ponyc/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ponylang/ponyc/labels{/name}","releases_url":"https://api.github.com/repos/ponylang/ponyc/releases{/id}","deployments_url":"https://api.github.com/repos/ponylang/ponyc/deployments","created_at":"2012-11-13T07:38:25Z","updated_at":"2016-03-30T15:10:08Z","pushed_at":"2016-03-30T19:14:38Z","git_url":"git://github.com/ponylang/ponyc.git","ssh_url":"git@github.com:ponylang/ponyc.git","clone_url":"https://github.com/ponylang/ponyc.git","svn_url":"https://github.com/ponylang/ponyc","homepage":"http://www.ponylang.org","size":23526,"stargazers_count":1350,"watchers_count":1350,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":92,"mirror_url":null,"open_issues_count":72,"forks":92,"open_issues":72,"watchers":1350,"default_branch":"master"}},"base":{"label":"ponylang:master","ref":"master","sha":"db54a681a6c49bebffc628a66782e00250d37025","user":{"login":"ponylang","id":12997238,"avatar_url":"https://avatars.githubusercontent.com/u/12997238?v=3","gravatar_id":"","url":"https://api.github.com/users/ponylang","html_url":"https://github.com/ponylang","followers_url":"https://api.github.com/users/ponylang/followers","following_url":"https://api.github.com/users/ponylang/following{/other_user}","gists_url":"https://api.github.com/users/ponylang/gists{/gist_id}","starred_url":"https://api.github.com/users/ponylang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ponylang/subscriptions","organizations_url":"https://api.github.com/users/ponylang/orgs","repos_url":"https://api.github.com/users/ponylang/repos","events_url":"https://api.github.com/users/ponylang/events{/privacy}","received_events_url":"https://api.github.com/users/ponylang/received_events","type":"Organization","site_admin":false},"repo":{"id":6667084,"name":"ponyc","full_name":"ponylang/ponyc","owner":{"login":"ponylang","id":12997238,"avatar_url":"https://avatars.githubusercontent.com/u/12997238?v=3","gravatar_id":"","url":"https://api.github.com/users/ponylang","html_url":"https://github.com/ponylang","followers_url":"https://api.github.com/users/ponylang/followers","following_url":"https://api.github.com/users/ponylang/following{/other_user}","gists_url":"https://api.github.com/users/ponylang/gists{/gist_id}","starred_url":"https://api.github.com/users/ponylang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ponylang/subscriptions","organizations_url":"https://api.github.com/users/ponylang/orgs","repos_url":"https://api.github.com/users/ponylang/repos","events_url":"https://api.github.com/users/ponylang/events{/privacy}","received_events_url":"https://api.github.com/users/ponylang/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ponylang/ponyc","description":"Pony Compiler","fork":false,"url":"https://api.github.com/repos/ponylang/ponyc","forks_url":"https://api.github.com/repos/ponylang/ponyc/forks","keys_url":"https://api.github.com/repos/ponylang/ponyc/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ponylang/ponyc/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ponylang/ponyc/teams","hooks_url":"https://api.github.com/repos/ponylang/ponyc/hooks","issue_events_url":"https://api.github.com/repos/ponylang/ponyc/issues/events{/number}","events_url":"https://api.github.com/repos/ponylang/ponyc/events","assignees_url":"https://api.github.com/repos/ponylang/ponyc/assignees{/user}","branches_url":"https://api.github.com/repos/ponylang/ponyc/branches{/branch}","tags_url":"https://api.github.com/repos/ponylang/ponyc/tags","blobs_url":"https://api.github.com/repos/ponylang/ponyc/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ponylang/ponyc/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ponylang/ponyc/git/refs{/sha}","trees_url":"https://api.github.com/repos/ponylang/ponyc/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ponylang/ponyc/statuses/{sha}","languages_url":"https://api.github.com/repos/ponylang/ponyc/languages","stargazers_url":"https://api.github.com/repos/ponylang/ponyc/stargazers","contributors_url":"https://api.github.com/repos/ponylang/ponyc/contributors","subscribers_url":"https://api.github.com/repos/ponylang/ponyc/subscribers","subscription_url":"https://api.github.com/repos/ponylang/ponyc/subscription","commits_url":"https://api.github.com/repos/ponylang/ponyc/commits{/sha}","git_commits_url":"https://api.github.com/repos/ponylang/ponyc/git/commits{/sha}","comments_url":"https://api.github.com/repos/ponylang/ponyc/comments{/number}","issue_comment_url":"https://api.github.com/repos/ponylang/ponyc/issues/comments{/number}","contents_url":"https://api.github.com/repos/ponylang/ponyc/contents/{+path}","compare_url":"https://api.github.com/repos/ponylang/ponyc/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ponylang/ponyc/merges","archive_url":"https://api.github.com/repos/ponylang/ponyc/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ponylang/ponyc/downloads","issues_url":"https://api.github.com/repos/ponylang/ponyc/issues{/number}","pulls_url":"https://api.github.com/repos/ponylang/ponyc/pulls{/number}","milestones_url":"https://api.github.com/repos/ponylang/ponyc/milestones{/number}","notifications_url":"https://api.github.com/repos/ponylang/ponyc/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ponylang/ponyc/labels{/name}","releases_url":"https://api.github.com/repos/ponylang/ponyc/releases{/id}","deployments_url":"https://api.github.com/repos/ponylang/ponyc/deployments","created_at":"2012-11-13T07:38:25Z","updated_at":"2016-03-30T15:10:08Z","pushed_at":"2016-03-30T19:14:38Z","git_url":"git://github.com/ponylang/ponyc.git","ssh_url":"git@github.com:ponylang/ponyc.git","clone_url":"https://github.com/ponylang/ponyc.git","svn_url":"https://github.com/ponylang/ponyc","homepage":"http://www.ponylang.org","size":23526,"stargazers_count":1350,"watchers_count":1350,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":92,"mirror_url":null,"open_issues_count":72,"forks":92,"open_issues":72,"watchers":1350,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ponylang/ponyc/pulls/657"},"html":{"href":"https://github.com/ponylang/ponyc/pull/657"},"issue":{"href":"https://api.github.com/repos/ponylang/ponyc/issues/657"},"comments":{"href":"https://api.github.com/repos/ponylang/ponyc/issues/657/comments"},"review_comments":{"href":"https://api.github.com/repos/ponylang/ponyc/pulls/657/comments"},"review_comment":{"href":"https://api.github.com/repos/ponylang/ponyc/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ponylang/ponyc/pulls/657/commits"},"statuses":{"href":"https://api.github.com/repos/ponylang/ponyc/statuses/8c62eb747686677ef60118587c899f4d58b04160"}}}}