{"action":"created","comment":{"url":"https://api.github.com/repos/gin-gonic/contrib/pulls/comments/31149479","id":31149479,"diff_hunk":"@@ -0,0 +1,52 @@\n+// Package ginrus provides log handling using logrus package.\n+//\n+// Based on github.com/stephenmuss/ginerus but adds more options.\n+package ginrus\n+\n+import (\n+\t\"time\"\n+\n+\t\"github.com/Sirupsen/logrus\"\n+\t\"github.com/gin-gonic/gin\"\n+)\n+\n+// Ginrus returns a gin.HandlerFunc (middleware) that logs requests using logrus.\n+//\n+// Requests with errors are logged using logrus.Error().\n+// Requests without errors are logged using logrus.Info().\n+//\n+// It receives:\n+//   1. A time package format string (e.g. time.RFC3339).\n+//   2. A boolean stating whether to use UTC time zone or local.\n+func Ginrus(logger *logrus.Logger, timeFormat string, utc bool) gin.HandlerFunc {\n+\treturn func(c *gin.Context) {\n+\t\tstart := time.Now()\n+\t\tif utc {\n+\t\t\tstart = start.UTC()\n+\t\t}\n+\n+\t\tc.Next()\n+\n+\t\tend := time.Now()\n+\t\tif utc {\n+\t\t\tend = end.UTC()\n+\t\t}\n+\n+\t\tentry := logger.WithFields(logrus.Fields{\n+\t\t\t\"status\":     c.Writer.Status(),\n+\t\t\t\"method\":     c.Request.Method,\n+\t\t\t\"path\":       c.Request.URL.Path,\n+\t\t\t\"ip\":         c.ClientIP(),\n+\t\t\t\"latency\":    end.Sub(start),\n+\t\t\t\"user-agent\": c.Request.UserAgent(),\n+\t\t\t\"time\":       end.Format(timeFormat),\n+\t\t})\n+\n+\t\tif len(c.Errors) > 0 {\n+\t\t\t// Append error field if this is an erroneous request.\n+\t\t\tentry.WithField(\"errors\", c.Errors.String()).Error()","path":"ginrus/ginrus.go","position":null,"original_position":47,"commit_id":"dc531e5e301cecb0aa3b02f0a0446e6fff2ac39d","original_commit_id":"7ef530899e9a94dd610dc388143bcf5d689d61e7","user":{"login":"oryband","id":115387,"avatar_url":"https://avatars.githubusercontent.com/u/115387?v=3","gravatar_id":"","url":"https://api.github.com/users/oryband","html_url":"https://github.com/oryband","followers_url":"https://api.github.com/users/oryband/followers","following_url":"https://api.github.com/users/oryband/following{/other_user}","gists_url":"https://api.github.com/users/oryband/gists{/gist_id}","starred_url":"https://api.github.com/users/oryband/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/oryband/subscriptions","organizations_url":"https://api.github.com/users/oryband/orgs","repos_url":"https://api.github.com/users/oryband/repos","events_url":"https://api.github.com/users/oryband/events{/privacy}","received_events_url":"https://api.github.com/users/oryband/received_events","type":"User","site_admin":false},"body":"@manu there we go, i updated it","created_at":"2015-05-27T16:00:16Z","updated_at":"2015-05-27T16:00:16Z","html_url":"https://github.com/gin-gonic/contrib/pull/40#discussion_r31149479","pull_request_url":"https://api.github.com/repos/gin-gonic/contrib/pulls/40","_links":{"self":{"href":"https://api.github.com/repos/gin-gonic/contrib/pulls/comments/31149479"},"html":{"href":"https://github.com/gin-gonic/contrib/pull/40#discussion_r31149479"},"pull_request":{"href":"https://api.github.com/repos/gin-gonic/contrib/pulls/40"}}},"pull_request":{"url":"https://api.github.com/repos/gin-gonic/contrib/pulls/40","id":35126577,"html_url":"https://github.com/gin-gonic/contrib/pull/40","diff_url":"https://github.com/gin-gonic/contrib/pull/40.diff","patch_url":"https://github.com/gin-gonic/contrib/pull/40.patch","issue_url":"https://api.github.com/repos/gin-gonic/contrib/issues/40","number":40,"state":"open","locked":false,"title":"added ginrus logrus logger middleware","user":{"login":"oryband","id":115387,"avatar_url":"https://avatars.githubusercontent.com/u/115387?v=3","gravatar_id":"","url":"https://api.github.com/users/oryband","html_url":"https://github.com/oryband","followers_url":"https://api.github.com/users/oryband/followers","following_url":"https://api.github.com/users/oryband/following{/other_user}","gists_url":"https://api.github.com/users/oryband/gists{/gist_id}","starred_url":"https://api.github.com/users/oryband/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/oryband/subscriptions","organizations_url":"https://api.github.com/users/oryband/orgs","repos_url":"https://api.github.com/users/oryband/repos","events_url":"https://api.github.com/users/oryband/events{/privacy}","received_events_url":"https://api.github.com/users/oryband/received_events","type":"User","site_admin":false},"body":"- This middleware provides loggin via github.com/Sirupsen/logrus package.\r\n- It is based on https://github.com/stephenmuss/ginerus\r\n- But adds more options:\r\n  - Logging only errors.\r\n  - Errors are logged via `logrus.Error()` function instead of `.Info()`.\r\n  - Control time format and whether to use UTC or not.","created_at":"2015-05-11T13:24:19Z","updated_at":"2015-05-27T16:00:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8a77e195838f55af88e5e86d3d265dd21dc399a6","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/gin-gonic/contrib/pulls/40/commits","review_comments_url":"https://api.github.com/repos/gin-gonic/contrib/pulls/40/comments","review_comment_url":"https://api.github.com/repos/gin-gonic/contrib/pulls/comments{/number}","comments_url":"https://api.github.com/repos/gin-gonic/contrib/issues/40/comments","statuses_url":"https://api.github.com/repos/gin-gonic/contrib/statuses/dc531e5e301cecb0aa3b02f0a0446e6fff2ac39d","head":{"label":"rounds:logrus-middleware","ref":"logrus-middleware","sha":"dc531e5e301cecb0aa3b02f0a0446e6fff2ac39d","user":{"login":"rounds","id":3406523,"avatar_url":"https://avatars.githubusercontent.com/u/3406523?v=3","gravatar_id":"","url":"https://api.github.com/users/rounds","html_url":"https://github.com/rounds","followers_url":"https://api.github.com/users/rounds/followers","following_url":"https://api.github.com/users/rounds/following{/other_user}","gists_url":"https://api.github.com/users/rounds/gists{/gist_id}","starred_url":"https://api.github.com/users/rounds/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rounds/subscriptions","organizations_url":"https://api.github.com/users/rounds/orgs","repos_url":"https://api.github.com/users/rounds/repos","events_url":"https://api.github.com/users/rounds/events{/privacy}","received_events_url":"https://api.github.com/users/rounds/received_events","type":"Organization","site_admin":false},"repo":{"id":34664362,"name":"go-gin-contrib","full_name":"rounds/go-gin-contrib","owner":{"login":"rounds","id":3406523,"avatar_url":"https://avatars.githubusercontent.com/u/3406523?v=3","gravatar_id":"","url":"https://api.github.com/users/rounds","html_url":"https://github.com/rounds","followers_url":"https://api.github.com/users/rounds/followers","following_url":"https://api.github.com/users/rounds/following{/other_user}","gists_url":"https://api.github.com/users/rounds/gists{/gist_id}","starred_url":"https://api.github.com/users/rounds/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rounds/subscriptions","organizations_url":"https://api.github.com/users/rounds/orgs","repos_url":"https://api.github.com/users/rounds/repos","events_url":"https://api.github.com/users/rounds/events{/privacy}","received_events_url":"https://api.github.com/users/rounds/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/rounds/go-gin-contrib","description":"Collection of middlewares created by the community","fork":true,"url":"https://api.github.com/repos/rounds/go-gin-contrib","forks_url":"https://api.github.com/repos/rounds/go-gin-contrib/forks","keys_url":"https://api.github.com/repos/rounds/go-gin-contrib/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rounds/go-gin-contrib/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rounds/go-gin-contrib/teams","hooks_url":"https://api.github.com/repos/rounds/go-gin-contrib/hooks","issue_events_url":"https://api.github.com/repos/rounds/go-gin-contrib/issues/events{/number}","events_url":"https://api.github.com/repos/rounds/go-gin-contrib/events","assignees_url":"https://api.github.com/repos/rounds/go-gin-contrib/assignees{/user}","branches_url":"https://api.github.com/repos/rounds/go-gin-contrib/branches{/branch}","tags_url":"https://api.github.com/repos/rounds/go-gin-contrib/tags","blobs_url":"https://api.github.com/repos/rounds/go-gin-contrib/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rounds/go-gin-contrib/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rounds/go-gin-contrib/git/refs{/sha}","trees_url":"https://api.github.com/repos/rounds/go-gin-contrib/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rounds/go-gin-contrib/statuses/{sha}","languages_url":"https://api.github.com/repos/rounds/go-gin-contrib/languages","stargazers_url":"https://api.github.com/repos/rounds/go-gin-contrib/stargazers","contributors_url":"https://api.github.com/repos/rounds/go-gin-contrib/contributors","subscribers_url":"https://api.github.com/repos/rounds/go-gin-contrib/subscribers","subscription_url":"https://api.github.com/repos/rounds/go-gin-contrib/subscription","commits_url":"https://api.github.com/repos/rounds/go-gin-contrib/commits{/sha}","git_commits_url":"https://api.github.com/repos/rounds/go-gin-contrib/git/commits{/sha}","comments_url":"https://api.github.com/repos/rounds/go-gin-contrib/comments{/number}","issue_comment_url":"https://api.github.com/repos/rounds/go-gin-contrib/issues/comments{/number}","contents_url":"https://api.github.com/repos/rounds/go-gin-contrib/contents/{+path}","compare_url":"https://api.github.com/repos/rounds/go-gin-contrib/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rounds/go-gin-contrib/merges","archive_url":"https://api.github.com/repos/rounds/go-gin-contrib/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rounds/go-gin-contrib/downloads","issues_url":"https://api.github.com/repos/rounds/go-gin-contrib/issues{/number}","pulls_url":"https://api.github.com/repos/rounds/go-gin-contrib/pulls{/number}","milestones_url":"https://api.github.com/repos/rounds/go-gin-contrib/milestones{/number}","notifications_url":"https://api.github.com/repos/rounds/go-gin-contrib/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rounds/go-gin-contrib/labels{/name}","releases_url":"https://api.github.com/repos/rounds/go-gin-contrib/releases{/id}","created_at":"2015-04-27T12:08:25Z","updated_at":"2015-05-07T13:57:18Z","pushed_at":"2015-05-27T16:00:01Z","git_url":"git://github.com/rounds/go-gin-contrib.git","ssh_url":"git@github.com:rounds/go-gin-contrib.git","clone_url":"https://github.com/rounds/go-gin-contrib.git","svn_url":"https://github.com/rounds/go-gin-contrib","homepage":"https://gin-gonic.github.io/gin/","size":260,"stargazers_count":0,"watchers_count":0,"language":"Go","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":"gin-gonic:master","ref":"master","sha":"66a849e21d8f012522e3ee1c0e75615de80dfbfe","user":{"login":"gin-gonic","id":7894478,"avatar_url":"https://avatars.githubusercontent.com/u/7894478?v=3","gravatar_id":"","url":"https://api.github.com/users/gin-gonic","html_url":"https://github.com/gin-gonic","followers_url":"https://api.github.com/users/gin-gonic/followers","following_url":"https://api.github.com/users/gin-gonic/following{/other_user}","gists_url":"https://api.github.com/users/gin-gonic/gists{/gist_id}","starred_url":"https://api.github.com/users/gin-gonic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gin-gonic/subscriptions","organizations_url":"https://api.github.com/users/gin-gonic/orgs","repos_url":"https://api.github.com/users/gin-gonic/repos","events_url":"https://api.github.com/users/gin-gonic/events{/privacy}","received_events_url":"https://api.github.com/users/gin-gonic/received_events","type":"Organization","site_admin":false},"repo":{"id":21525599,"name":"contrib","full_name":"gin-gonic/contrib","owner":{"login":"gin-gonic","id":7894478,"avatar_url":"https://avatars.githubusercontent.com/u/7894478?v=3","gravatar_id":"","url":"https://api.github.com/users/gin-gonic","html_url":"https://github.com/gin-gonic","followers_url":"https://api.github.com/users/gin-gonic/followers","following_url":"https://api.github.com/users/gin-gonic/following{/other_user}","gists_url":"https://api.github.com/users/gin-gonic/gists{/gist_id}","starred_url":"https://api.github.com/users/gin-gonic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gin-gonic/subscriptions","organizations_url":"https://api.github.com/users/gin-gonic/orgs","repos_url":"https://api.github.com/users/gin-gonic/repos","events_url":"https://api.github.com/users/gin-gonic/events{/privacy}","received_events_url":"https://api.github.com/users/gin-gonic/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/gin-gonic/contrib","description":"Collection of middlewares created by the community","fork":false,"url":"https://api.github.com/repos/gin-gonic/contrib","forks_url":"https://api.github.com/repos/gin-gonic/contrib/forks","keys_url":"https://api.github.com/repos/gin-gonic/contrib/keys{/key_id}","collaborators_url":"https://api.github.com/repos/gin-gonic/contrib/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/gin-gonic/contrib/teams","hooks_url":"https://api.github.com/repos/gin-gonic/contrib/hooks","issue_events_url":"https://api.github.com/repos/gin-gonic/contrib/issues/events{/number}","events_url":"https://api.github.com/repos/gin-gonic/contrib/events","assignees_url":"https://api.github.com/repos/gin-gonic/contrib/assignees{/user}","branches_url":"https://api.github.com/repos/gin-gonic/contrib/branches{/branch}","tags_url":"https://api.github.com/repos/gin-gonic/contrib/tags","blobs_url":"https://api.github.com/repos/gin-gonic/contrib/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/gin-gonic/contrib/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/gin-gonic/contrib/git/refs{/sha}","trees_url":"https://api.github.com/repos/gin-gonic/contrib/git/trees{/sha}","statuses_url":"https://api.github.com/repos/gin-gonic/contrib/statuses/{sha}","languages_url":"https://api.github.com/repos/gin-gonic/contrib/languages","stargazers_url":"https://api.github.com/repos/gin-gonic/contrib/stargazers","contributors_url":"https://api.github.com/repos/gin-gonic/contrib/contributors","subscribers_url":"https://api.github.com/repos/gin-gonic/contrib/subscribers","subscription_url":"https://api.github.com/repos/gin-gonic/contrib/subscription","commits_url":"https://api.github.com/repos/gin-gonic/contrib/commits{/sha}","git_commits_url":"https://api.github.com/repos/gin-gonic/contrib/git/commits{/sha}","comments_url":"https://api.github.com/repos/gin-gonic/contrib/comments{/number}","issue_comment_url":"https://api.github.com/repos/gin-gonic/contrib/issues/comments{/number}","contents_url":"https://api.github.com/repos/gin-gonic/contrib/contents/{+path}","compare_url":"https://api.github.com/repos/gin-gonic/contrib/compare/{base}...{head}","merges_url":"https://api.github.com/repos/gin-gonic/contrib/merges","archive_url":"https://api.github.com/repos/gin-gonic/contrib/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/gin-gonic/contrib/downloads","issues_url":"https://api.github.com/repos/gin-gonic/contrib/issues{/number}","pulls_url":"https://api.github.com/repos/gin-gonic/contrib/pulls{/number}","milestones_url":"https://api.github.com/repos/gin-gonic/contrib/milestones{/number}","notifications_url":"https://api.github.com/repos/gin-gonic/contrib/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/gin-gonic/contrib/labels{/name}","releases_url":"https://api.github.com/repos/gin-gonic/contrib/releases{/id}","created_at":"2014-07-05T18:22:40Z","updated_at":"2015-05-23T10:07:24Z","pushed_at":"2015-05-27T16:00:01Z","git_url":"git://github.com/gin-gonic/contrib.git","ssh_url":"git@github.com:gin-gonic/contrib.git","clone_url":"https://github.com/gin-gonic/contrib.git","svn_url":"https://github.com/gin-gonic/contrib","homepage":"https://gin-gonic.github.io/gin/","size":817,"stargazers_count":53,"watchers_count":53,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":37,"mirror_url":null,"open_issues_count":18,"forks":37,"open_issues":18,"watchers":53,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/gin-gonic/contrib/pulls/40"},"html":{"href":"https://github.com/gin-gonic/contrib/pull/40"},"issue":{"href":"https://api.github.com/repos/gin-gonic/contrib/issues/40"},"comments":{"href":"https://api.github.com/repos/gin-gonic/contrib/issues/40/comments"},"review_comments":{"href":"https://api.github.com/repos/gin-gonic/contrib/pulls/40/comments"},"review_comment":{"href":"https://api.github.com/repos/gin-gonic/contrib/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/gin-gonic/contrib/pulls/40/commits"},"statuses":{"href":"https://api.github.com/repos/gin-gonic/contrib/statuses/dc531e5e301cecb0aa3b02f0a0446e6fff2ac39d"}}}}