{"action":"created","comment":{"url":"https://api.github.com/repos/getlantern/flashlight-build/pulls/comments/25079403","id":25079403,"diff_hunk":"@@ -0,0 +1,102 @@\n+package main\n+\n+import (\n+\t\"fmt\"\n+\t\"io\"\n+\t\"os\"\n+\t\"path/filepath\"\n+\t\"runtime\"\n+\t\"time\"\n+\n+\t\"github.com/dogenzaka/rotator\"\n+\t\"github.com/getlantern/appdir\"\n+\t\"github.com/getlantern/golog\"\n+\t\"github.com/getlantern/wfilter\"\n+\t\"github.com/segmentio/go-loggly\"\n+)\n+\n+var (\n+\tLogTimestampFormat = \"Jan 02 15:04:05.000\"\n+\tlogglyToken        = \"469973d5-6eaf-445a-be71-cf27141316a1\"\n+\tlog                = golog.LoggerFor(\"flashlight\")\n+)\n+\n+func configureLogging() *rotator.SizeRotator {\n+\tlogdir := appdir.Logs(\"Lantern\")\n+\tlog.Debugf(\"Placing logs in %v\", logdir)\n+\tif _, err := os.Stat(logdir); err != nil {\n+\t\tif os.IsNotExist(err) {\n+\t\t\t// Create log dir\n+\t\t\tif err := os.MkdirAll(logdir, 0755); err != nil {\n+\t\t\t\tlog.Fatalf(\"Unable to create logdir at %s: %s\", logdir, err)\n+\t\t\t}\n+\t\t}\n+\t}\n+\tfile := rotator.NewSizeRotator(filepath.Join(logdir, \"lantern.log\"))\n+\t// Set log files to 1 MB\n+\tfile.RotationSize = 1 * 1024 * 1024\n+\t// Keep up to 20 log files\n+\tfile.MaxRotation = 20\n+\n+\tremoteWriter := logglyErrorWriter{loggly.New(logglyToken)}\n+\terrorOut := timestamped(NonStopWriter(os.Stderr, file, remoteWriter))\n+\tdebugOut := timestamped(NonStopWriter(os.Stdout, file))\n+\tgolog.SetOutputs(errorOut, debugOut)\n+\treturn file\n+}\n+\n+// timestamped adds a timestamp to the beginning of log lines\n+func timestamped(orig io.Writer) io.Writer {\n+\treturn wfilter.LinePrepender(orig, func(w io.Writer) (int, error) {\n+\t\treturn fmt.Fprintf(w, \"%s - \", time.Now().In(time.UTC).Format(LogTimestampFormat))\n+\t})\n+}\n+\n+type logglyErrorWriter struct {\n+\tl *loggly.Client\n+}\n+\n+func (w logglyErrorWriter) Write(b []byte) (int, error) {\n+\treturn writeToLoggly(w.l, \"ERROR\", string(b))","path":"src/github.com/getlantern/flashlight/logging.go","position":60,"original_position":60,"commit_id":"69878a3ba96b2b70e109402d92658117835ded2c","original_commit_id":"7e425234a36a29aa7e26ff62cb6c340783d3eeb1","user":{"login":"fffw","id":10410437,"avatar_url":"https://avatars.githubusercontent.com/u/10410437?v=3","gravatar_id":"","url":"https://api.github.com/users/fffw","html_url":"https://github.com/fffw","followers_url":"https://api.github.com/users/fffw/followers","following_url":"https://api.github.com/users/fffw/following{/other_user}","gists_url":"https://api.github.com/users/fffw/gists{/gist_id}","starred_url":"https://api.github.com/users/fffw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fffw/subscriptions","organizations_url":"https://api.github.com/users/fffw/orgs","repos_url":"https://api.github.com/users/fffw/repos","events_url":"https://api.github.com/users/fffw/events{/privacy}","received_events_url":"https://api.github.com/users/fffw/received_events","type":"User","site_admin":false},"body":"This again is caused by mixing different layer of abstraction. I think the correct way is to make sure each log entry is written in whole, rather than patch at an inappropriate byte stream layer. \r\n\r\nAs I'm planing a more reliable way to write to Loggly, is it ok to leave it as is if we do need it in Valencia release?","created_at":"2015-02-20T15:59:59Z","updated_at":"2015-02-20T15:59:59Z","html_url":"https://github.com/getlantern/flashlight-build/pull/64#discussion_r25079403","pull_request_url":"https://api.github.com/repos/getlantern/flashlight-build/pulls/64","_links":{"self":{"href":"https://api.github.com/repos/getlantern/flashlight-build/pulls/comments/25079403"},"html":{"href":"https://github.com/getlantern/flashlight-build/pull/64#discussion_r25079403"},"pull_request":{"href":"https://api.github.com/repos/getlantern/flashlight-build/pulls/64"}}},"pull_request":{"url":"https://api.github.com/repos/getlantern/flashlight-build/pulls/64","id":29692061,"html_url":"https://github.com/getlantern/flashlight-build/pull/64","diff_url":"https://github.com/getlantern/flashlight-build/pull/64.diff","patch_url":"https://github.com/getlantern/flashlight-build/pull/64.patch","issue_url":"https://api.github.com/repos/getlantern/flashlight-build/issues/64","number":64,"state":"open","locked":false,"title":"send error logs to loggly","user":{"login":"fffw","id":10410437,"avatar_url":"https://avatars.githubusercontent.com/u/10410437?v=3","gravatar_id":"","url":"https://api.github.com/users/fffw","html_url":"https://github.com/fffw","followers_url":"https://api.github.com/users/fffw/followers","following_url":"https://api.github.com/users/fffw/following{/other_user}","gists_url":"https://api.github.com/users/fffw/gists{/gist_id}","starred_url":"https://api.github.com/users/fffw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fffw/subscriptions","organizations_url":"https://api.github.com/users/fffw/orgs","repos_url":"https://api.github.com/users/fffw/repos","events_url":"https://api.github.com/users/fffw/events{/privacy}","received_events_url":"https://api.github.com/users/fffw/received_events","type":"User","site_admin":false},"body":"I drafted simple remote logging and tested on Mac, you can see them by filter osName as \"darwin\" at https://lantern.loggly.com. Log didn't get written on Windows, even to local files. I'm checking.\r\n\r\nIt's modeled after [Lantern java](https://github.com/getlantern/lantern/blob/devel/src/main/java/org/lantern/loggly/LogglyAppender.java#L57) but left some fields empty or removed.\r\n\r\nThis resolves https://github.com/getlantern/lantern/issues/2232","created_at":"2015-02-20T12:25:20Z","updated_at":"2015-02-20T15:59:59Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a56ce1e34e0740897a50a825dfa1d0a6ab3b7209","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/getlantern/flashlight-build/pulls/64/commits","review_comments_url":"https://api.github.com/repos/getlantern/flashlight-build/pulls/64/comments","review_comment_url":"https://api.github.com/repos/getlantern/flashlight-build/pulls/comments/{number}","comments_url":"https://api.github.com/repos/getlantern/flashlight-build/issues/64/comments","statuses_url":"https://api.github.com/repos/getlantern/flashlight-build/statuses/69878a3ba96b2b70e109402d92658117835ded2c","head":{"label":"issue2232","ref":"issue2232","sha":"69878a3ba96b2b70e109402d92658117835ded2c","user":{"login":"getlantern","id":624178,"avatar_url":"https://avatars.githubusercontent.com/u/624178?v=3","gravatar_id":"","url":"https://api.github.com/users/getlantern","html_url":"https://github.com/getlantern","followers_url":"https://api.github.com/users/getlantern/followers","following_url":"https://api.github.com/users/getlantern/following{/other_user}","gists_url":"https://api.github.com/users/getlantern/gists{/gist_id}","starred_url":"https://api.github.com/users/getlantern/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/getlantern/subscriptions","organizations_url":"https://api.github.com/users/getlantern/orgs","repos_url":"https://api.github.com/users/getlantern/repos","events_url":"https://api.github.com/users/getlantern/events{/privacy}","received_events_url":"https://api.github.com/users/getlantern/received_events","type":"Organization","site_admin":false},"repo":{"id":27652771,"name":"flashlight-build","full_name":"getlantern/flashlight-build","owner":{"login":"getlantern","id":624178,"avatar_url":"https://avatars.githubusercontent.com/u/624178?v=3","gravatar_id":"","url":"https://api.github.com/users/getlantern","html_url":"https://github.com/getlantern","followers_url":"https://api.github.com/users/getlantern/followers","following_url":"https://api.github.com/users/getlantern/following{/other_user}","gists_url":"https://api.github.com/users/getlantern/gists{/gist_id}","starred_url":"https://api.github.com/users/getlantern/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/getlantern/subscriptions","organizations_url":"https://api.github.com/users/getlantern/orgs","repos_url":"https://api.github.com/users/getlantern/repos","events_url":"https://api.github.com/users/getlantern/events{/privacy}","received_events_url":"https://api.github.com/users/getlantern/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/getlantern/flashlight-build","description":"Repeatable builds for flashlight, using gox","fork":false,"url":"https://api.github.com/repos/getlantern/flashlight-build","forks_url":"https://api.github.com/repos/getlantern/flashlight-build/forks","keys_url":"https://api.github.com/repos/getlantern/flashlight-build/keys{/key_id}","collaborators_url":"https://api.github.com/repos/getlantern/flashlight-build/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/getlantern/flashlight-build/teams","hooks_url":"https://api.github.com/repos/getlantern/flashlight-build/hooks","issue_events_url":"https://api.github.com/repos/getlantern/flashlight-build/issues/events{/number}","events_url":"https://api.github.com/repos/getlantern/flashlight-build/events","assignees_url":"https://api.github.com/repos/getlantern/flashlight-build/assignees{/user}","branches_url":"https://api.github.com/repos/getlantern/flashlight-build/branches{/branch}","tags_url":"https://api.github.com/repos/getlantern/flashlight-build/tags","blobs_url":"https://api.github.com/repos/getlantern/flashlight-build/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/getlantern/flashlight-build/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/getlantern/flashlight-build/git/refs{/sha}","trees_url":"https://api.github.com/repos/getlantern/flashlight-build/git/trees{/sha}","statuses_url":"https://api.github.com/repos/getlantern/flashlight-build/statuses/{sha}","languages_url":"https://api.github.com/repos/getlantern/flashlight-build/languages","stargazers_url":"https://api.github.com/repos/getlantern/flashlight-build/stargazers","contributors_url":"https://api.github.com/repos/getlantern/flashlight-build/contributors","subscribers_url":"https://api.github.com/repos/getlantern/flashlight-build/subscribers","subscription_url":"https://api.github.com/repos/getlantern/flashlight-build/subscription","commits_url":"https://api.github.com/repos/getlantern/flashlight-build/commits{/sha}","git_commits_url":"https://api.github.com/repos/getlantern/flashlight-build/git/commits{/sha}","comments_url":"https://api.github.com/repos/getlantern/flashlight-build/comments{/number}","issue_comment_url":"https://api.github.com/repos/getlantern/flashlight-build/issues/comments/{number}","contents_url":"https://api.github.com/repos/getlantern/flashlight-build/contents/{+path}","compare_url":"https://api.github.com/repos/getlantern/flashlight-build/compare/{base}...{head}","merges_url":"https://api.github.com/repos/getlantern/flashlight-build/merges","archive_url":"https://api.github.com/repos/getlantern/flashlight-build/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/getlantern/flashlight-build/downloads","issues_url":"https://api.github.com/repos/getlantern/flashlight-build/issues{/number}","pulls_url":"https://api.github.com/repos/getlantern/flashlight-build/pulls{/number}","milestones_url":"https://api.github.com/repos/getlantern/flashlight-build/milestones{/number}","notifications_url":"https://api.github.com/repos/getlantern/flashlight-build/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/getlantern/flashlight-build/labels{/name}","releases_url":"https://api.github.com/repos/getlantern/flashlight-build/releases{/id}","created_at":"2014-12-06T23:27:18Z","updated_at":"2015-02-16T23:27:46Z","pushed_at":"2015-02-20T15:55:09Z","git_url":"git://github.com/getlantern/flashlight-build.git","ssh_url":"git@github.com:getlantern/flashlight-build.git","clone_url":"https://github.com/getlantern/flashlight-build.git","svn_url":"https://github.com/getlantern/flashlight-build","homepage":"","size":155861,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":13,"forks":0,"open_issues":13,"watchers":0,"default_branch":"devel"}},"base":{"label":"valencia","ref":"valencia","sha":"d2ce30e342c61d5ecc38a9d5ecfcd3761743dded","user":{"login":"getlantern","id":624178,"avatar_url":"https://avatars.githubusercontent.com/u/624178?v=3","gravatar_id":"","url":"https://api.github.com/users/getlantern","html_url":"https://github.com/getlantern","followers_url":"https://api.github.com/users/getlantern/followers","following_url":"https://api.github.com/users/getlantern/following{/other_user}","gists_url":"https://api.github.com/users/getlantern/gists{/gist_id}","starred_url":"https://api.github.com/users/getlantern/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/getlantern/subscriptions","organizations_url":"https://api.github.com/users/getlantern/orgs","repos_url":"https://api.github.com/users/getlantern/repos","events_url":"https://api.github.com/users/getlantern/events{/privacy}","received_events_url":"https://api.github.com/users/getlantern/received_events","type":"Organization","site_admin":false},"repo":{"id":27652771,"name":"flashlight-build","full_name":"getlantern/flashlight-build","owner":{"login":"getlantern","id":624178,"avatar_url":"https://avatars.githubusercontent.com/u/624178?v=3","gravatar_id":"","url":"https://api.github.com/users/getlantern","html_url":"https://github.com/getlantern","followers_url":"https://api.github.com/users/getlantern/followers","following_url":"https://api.github.com/users/getlantern/following{/other_user}","gists_url":"https://api.github.com/users/getlantern/gists{/gist_id}","starred_url":"https://api.github.com/users/getlantern/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/getlantern/subscriptions","organizations_url":"https://api.github.com/users/getlantern/orgs","repos_url":"https://api.github.com/users/getlantern/repos","events_url":"https://api.github.com/users/getlantern/events{/privacy}","received_events_url":"https://api.github.com/users/getlantern/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/getlantern/flashlight-build","description":"Repeatable builds for flashlight, using gox","fork":false,"url":"https://api.github.com/repos/getlantern/flashlight-build","forks_url":"https://api.github.com/repos/getlantern/flashlight-build/forks","keys_url":"https://api.github.com/repos/getlantern/flashlight-build/keys{/key_id}","collaborators_url":"https://api.github.com/repos/getlantern/flashlight-build/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/getlantern/flashlight-build/teams","hooks_url":"https://api.github.com/repos/getlantern/flashlight-build/hooks","issue_events_url":"https://api.github.com/repos/getlantern/flashlight-build/issues/events{/number}","events_url":"https://api.github.com/repos/getlantern/flashlight-build/events","assignees_url":"https://api.github.com/repos/getlantern/flashlight-build/assignees{/user}","branches_url":"https://api.github.com/repos/getlantern/flashlight-build/branches{/branch}","tags_url":"https://api.github.com/repos/getlantern/flashlight-build/tags","blobs_url":"https://api.github.com/repos/getlantern/flashlight-build/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/getlantern/flashlight-build/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/getlantern/flashlight-build/git/refs{/sha}","trees_url":"https://api.github.com/repos/getlantern/flashlight-build/git/trees{/sha}","statuses_url":"https://api.github.com/repos/getlantern/flashlight-build/statuses/{sha}","languages_url":"https://api.github.com/repos/getlantern/flashlight-build/languages","stargazers_url":"https://api.github.com/repos/getlantern/flashlight-build/stargazers","contributors_url":"https://api.github.com/repos/getlantern/flashlight-build/contributors","subscribers_url":"https://api.github.com/repos/getlantern/flashlight-build/subscribers","subscription_url":"https://api.github.com/repos/getlantern/flashlight-build/subscription","commits_url":"https://api.github.com/repos/getlantern/flashlight-build/commits{/sha}","git_commits_url":"https://api.github.com/repos/getlantern/flashlight-build/git/commits{/sha}","comments_url":"https://api.github.com/repos/getlantern/flashlight-build/comments{/number}","issue_comment_url":"https://api.github.com/repos/getlantern/flashlight-build/issues/comments/{number}","contents_url":"https://api.github.com/repos/getlantern/flashlight-build/contents/{+path}","compare_url":"https://api.github.com/repos/getlantern/flashlight-build/compare/{base}...{head}","merges_url":"https://api.github.com/repos/getlantern/flashlight-build/merges","archive_url":"https://api.github.com/repos/getlantern/flashlight-build/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/getlantern/flashlight-build/downloads","issues_url":"https://api.github.com/repos/getlantern/flashlight-build/issues{/number}","pulls_url":"https://api.github.com/repos/getlantern/flashlight-build/pulls{/number}","milestones_url":"https://api.github.com/repos/getlantern/flashlight-build/milestones{/number}","notifications_url":"https://api.github.com/repos/getlantern/flashlight-build/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/getlantern/flashlight-build/labels{/name}","releases_url":"https://api.github.com/repos/getlantern/flashlight-build/releases{/id}","created_at":"2014-12-06T23:27:18Z","updated_at":"2015-02-16T23:27:46Z","pushed_at":"2015-02-20T15:55:09Z","git_url":"git://github.com/getlantern/flashlight-build.git","ssh_url":"git@github.com:getlantern/flashlight-build.git","clone_url":"https://github.com/getlantern/flashlight-build.git","svn_url":"https://github.com/getlantern/flashlight-build","homepage":"","size":155861,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":13,"forks":0,"open_issues":13,"watchers":0,"default_branch":"devel"}},"_links":{"self":{"href":"https://api.github.com/repos/getlantern/flashlight-build/pulls/64"},"html":{"href":"https://github.com/getlantern/flashlight-build/pull/64"},"issue":{"href":"https://api.github.com/repos/getlantern/flashlight-build/issues/64"},"comments":{"href":"https://api.github.com/repos/getlantern/flashlight-build/issues/64/comments"},"review_comments":{"href":"https://api.github.com/repos/getlantern/flashlight-build/pulls/64/comments"},"review_comment":{"href":"https://api.github.com/repos/getlantern/flashlight-build/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/getlantern/flashlight-build/pulls/64/commits"},"statuses":{"href":"https://api.github.com/repos/getlantern/flashlight-build/statuses/69878a3ba96b2b70e109402d92658117835ded2c"}}}}