{"action":"created","comment":{"url":"https://api.github.com/repos/docker/docker/pulls/comments/29791371","id":29791371,"diff_hunk":"@@ -0,0 +1,114 @@\n+package gelf\n+\n+import (\n+\t\"bytes\"\n+\t\"fmt\"\n+\t\"os\"\n+\t\"strings\"\n+\t\"time\"\n+\n+\t\"github.com/Graylog2/go-gelf/gelf\"\n+\t\"github.com/docker/docker/daemon/logger\"\n+\t\"github.com/docker/docker/pkg/parsers\"\n+)\n+\n+type GelfLogger struct {\n+\twriter   *gelf.Writer\n+\tmetadata GelfMetadata\n+}\n+\n+type GelfMetadata struct {\n+\tContainerId string\n+\tImageId     string\n+\tEntrypoint  string\n+\tArgs        []string\n+}\n+\n+func New(options []string, gelfMetadata GelfMetadata) (logger.Logger, error) {\n+\thost := \"localhost\"\n+\tport := \"12201\"\n+\n+\t// parse the options\n+\tfor _, option := range options {\n+\t\tkey, val, err := parsers.ParseKeyValueOpt(option)\n+\t\tif err != nil {\n+\t\t\treturn nil, err\n+\t\t}\n+\t\tkey = strings.ToLower(key)\n+\t\tswitch key {\n+\t\tcase \"gelf.host\":\n+\t\t\thost = val\n+\t\tcase \"gelf.port\":\n+\t\t\tport = val\n+\t\t}\n+\t}\n+\n+\tgelfWriter, err := gelf.NewWriter(fmt.Sprintf(\"%s:%s\", host, port))\n+\tif err != nil {\n+\t\treturn nil, fmt.Errorf(\"Can not connect to GELF endpoint: %v\", err)\n+\t}\n+\n+\treturn &GelfLogger{\n+\t\twriter:   gelfWriter,\n+\t\tmetadata: gelfMetadata,\n+\t}, nil\n+}\n+\n+func (s *GelfLogger) Log(msg *logger.Message) error {\n+\t// remove trailing and leading whitespace\n+\tp := bytes.TrimSpace([]byte(msg.Line))\n+\n+\t// If there are newlines in the message, use the first line\n+\t// for the short message and set the full message to the\n+\t// original input.  If the input has no newlines, stick the\n+\t// whole thing in Short.\n+\tshort := p\n+\tfull := []byte(\"\")\n+\tif i := bytes.IndexRune(p, '\\n'); i > 0 {\n+\t\tshort = p[:i]\n+\t\tfull = p\n+\t}\n+\n+\tlevel := int32(6)\n+\tif msg.Source == \"stderr\" {\n+\t\tlevel = 3\n+\t}\n+\n+\thostname, err := os.Hostname()\n+\tif err != nil {\n+\t\treturn fmt.Errorf(\"Can not resolve hostname: %v\", err)\n+\t}\n+\n+\tcommand := []string{s.metadata.Entrypoint}\n+\tfor _, arg := range s.metadata.Args {\n+\t\tcommand = append(command, arg)\n+\t}\n+\n+\tm := gelf.Message{\n+\t\tVersion:  \"1.1\",\n+\t\tHost:     hostname,\n+\t\tShort:    string(short),\n+\t\tFull:     string(full),\n+\t\tTimeUnix: float64(msg.Timestamp.UnixNano()/int64(time.Millisecond)) / 1000.0,","path":"daemon/logger/gelf/gelf.go","position":92,"original_position":92,"commit_id":"3a77220829a0a49d048b20b322bfa1d138bb5b90","original_commit_id":"3a77220829a0a49d048b20b322bfa1d138bb5b90","user":{"login":"mariussturm","id":356597,"avatar_url":"https://avatars.githubusercontent.com/u/356597?v=3","gravatar_id":"","url":"https://api.github.com/users/mariussturm","html_url":"https://github.com/mariussturm","followers_url":"https://api.github.com/users/mariussturm/followers","following_url":"https://api.github.com/users/mariussturm/following{/other_user}","gists_url":"https://api.github.com/users/mariussturm/gists{/gist_id}","starred_url":"https://api.github.com/users/mariussturm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mariussturm/subscriptions","organizations_url":"https://api.github.com/users/mariussturm/orgs","repos_url":"https://api.github.com/users/mariussturm/repos","events_url":"https://api.github.com/users/mariussturm/events{/privacy}","received_events_url":"https://api.github.com/users/mariussturm/received_events","type":"User","site_admin":false},"body":"Ah, the milliseconds need to be given as decimal places, something like 1430939403.123","created_at":"2015-05-06T19:10:32Z","updated_at":"2015-05-06T19:10:32Z","html_url":"https://github.com/docker/docker/pull/13015#discussion_r29791371","pull_request_url":"https://api.github.com/repos/docker/docker/pulls/13015","_links":{"self":{"href":"https://api.github.com/repos/docker/docker/pulls/comments/29791371"},"html":{"href":"https://github.com/docker/docker/pull/13015#discussion_r29791371"},"pull_request":{"href":"https://api.github.com/repos/docker/docker/pulls/13015"}}},"pull_request":{"url":"https://api.github.com/repos/docker/docker/pulls/13015","id":34818709,"html_url":"https://github.com/docker/docker/pull/13015","diff_url":"https://github.com/docker/docker/pull/13015.diff","patch_url":"https://github.com/docker/docker/pull/13015.patch","issue_url":"https://api.github.com/repos/docker/docker/issues/13015","number":13015,"state":"open","locked":false,"title":"Add logging driver for GELF via UDP","user":{"login":"mariussturm","id":356597,"avatar_url":"https://avatars.githubusercontent.com/u/356597?v=3","gravatar_id":"","url":"https://api.github.com/users/mariussturm","html_url":"https://github.com/mariussturm","followers_url":"https://api.github.com/users/mariussturm/followers","following_url":"https://api.github.com/users/mariussturm/following{/other_user}","gists_url":"https://api.github.com/users/mariussturm/gists{/gist_id}","starred_url":"https://api.github.com/users/mariussturm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mariussturm/subscriptions","organizations_url":"https://api.github.com/users/mariussturm/orgs","repos_url":"https://api.github.com/users/mariussturm/repos","events_url":"https://api.github.com/users/mariussturm/events{/privacy}","received_events_url":"https://api.github.com/users/mariussturm/received_events","type":"User","site_admin":false},"body":"A first shot of a remote logging driver. The driver sends log messages to a GELF endpoint (e.g. Graylog or Logstash/ELK) via UDP.\r\nI had to introduce a new command line option `--log-opt` in order to make the target IP and port configurable. I think this needs to be done in a better implementation but it is not exactly scope of this PR. Maybe someone from the core team can help out.\r\nCurrently you have to start the _daemon_ with  `--log-opt=gelf.host=<Graylog server ip>` and start a container with `docker run --log-driver=gelf` to send logs remotely.","created_at":"2015-05-06T13:54:22Z","updated_at":"2015-05-06T19:10:32Z","closed_at":null,"merged_at":null,"merge_commit_sha":"332defc317775164058dbd23f35e3736e1828112","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/docker/docker/pulls/13015/commits","review_comments_url":"https://api.github.com/repos/docker/docker/pulls/13015/comments","review_comment_url":"https://api.github.com/repos/docker/docker/pulls/comments{/number}","comments_url":"https://api.github.com/repos/docker/docker/issues/13015/comments","statuses_url":"https://api.github.com/repos/docker/docker/statuses/3a77220829a0a49d048b20b322bfa1d138bb5b90","head":{"label":"mariussturm:master","ref":"master","sha":"3a77220829a0a49d048b20b322bfa1d138bb5b90","user":{"login":"mariussturm","id":356597,"avatar_url":"https://avatars.githubusercontent.com/u/356597?v=3","gravatar_id":"","url":"https://api.github.com/users/mariussturm","html_url":"https://github.com/mariussturm","followers_url":"https://api.github.com/users/mariussturm/followers","following_url":"https://api.github.com/users/mariussturm/following{/other_user}","gists_url":"https://api.github.com/users/mariussturm/gists{/gist_id}","starred_url":"https://api.github.com/users/mariussturm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mariussturm/subscriptions","organizations_url":"https://api.github.com/users/mariussturm/orgs","repos_url":"https://api.github.com/users/mariussturm/repos","events_url":"https://api.github.com/users/mariussturm/events{/privacy}","received_events_url":"https://api.github.com/users/mariussturm/received_events","type":"User","site_admin":false},"repo":{"id":34808174,"name":"docker","full_name":"mariussturm/docker","owner":{"login":"mariussturm","id":356597,"avatar_url":"https://avatars.githubusercontent.com/u/356597?v=3","gravatar_id":"","url":"https://api.github.com/users/mariussturm","html_url":"https://github.com/mariussturm","followers_url":"https://api.github.com/users/mariussturm/followers","following_url":"https://api.github.com/users/mariussturm/following{/other_user}","gists_url":"https://api.github.com/users/mariussturm/gists{/gist_id}","starred_url":"https://api.github.com/users/mariussturm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mariussturm/subscriptions","organizations_url":"https://api.github.com/users/mariussturm/orgs","repos_url":"https://api.github.com/users/mariussturm/repos","events_url":"https://api.github.com/users/mariussturm/events{/privacy}","received_events_url":"https://api.github.com/users/mariussturm/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mariussturm/docker","description":"Docker - the open-source application container engine","fork":true,"url":"https://api.github.com/repos/mariussturm/docker","forks_url":"https://api.github.com/repos/mariussturm/docker/forks","keys_url":"https://api.github.com/repos/mariussturm/docker/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mariussturm/docker/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mariussturm/docker/teams","hooks_url":"https://api.github.com/repos/mariussturm/docker/hooks","issue_events_url":"https://api.github.com/repos/mariussturm/docker/issues/events{/number}","events_url":"https://api.github.com/repos/mariussturm/docker/events","assignees_url":"https://api.github.com/repos/mariussturm/docker/assignees{/user}","branches_url":"https://api.github.com/repos/mariussturm/docker/branches{/branch}","tags_url":"https://api.github.com/repos/mariussturm/docker/tags","blobs_url":"https://api.github.com/repos/mariussturm/docker/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mariussturm/docker/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mariussturm/docker/git/refs{/sha}","trees_url":"https://api.github.com/repos/mariussturm/docker/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mariussturm/docker/statuses/{sha}","languages_url":"https://api.github.com/repos/mariussturm/docker/languages","stargazers_url":"https://api.github.com/repos/mariussturm/docker/stargazers","contributors_url":"https://api.github.com/repos/mariussturm/docker/contributors","subscribers_url":"https://api.github.com/repos/mariussturm/docker/subscribers","subscription_url":"https://api.github.com/repos/mariussturm/docker/subscription","commits_url":"https://api.github.com/repos/mariussturm/docker/commits{/sha}","git_commits_url":"https://api.github.com/repos/mariussturm/docker/git/commits{/sha}","comments_url":"https://api.github.com/repos/mariussturm/docker/comments{/number}","issue_comment_url":"https://api.github.com/repos/mariussturm/docker/issues/comments{/number}","contents_url":"https://api.github.com/repos/mariussturm/docker/contents/{+path}","compare_url":"https://api.github.com/repos/mariussturm/docker/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mariussturm/docker/merges","archive_url":"https://api.github.com/repos/mariussturm/docker/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mariussturm/docker/downloads","issues_url":"https://api.github.com/repos/mariussturm/docker/issues{/number}","pulls_url":"https://api.github.com/repos/mariussturm/docker/pulls{/number}","milestones_url":"https://api.github.com/repos/mariussturm/docker/milestones{/number}","notifications_url":"https://api.github.com/repos/mariussturm/docker/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mariussturm/docker/labels{/name}","releases_url":"https://api.github.com/repos/mariussturm/docker/releases{/id}","created_at":"2015-04-29T17:34:50Z","updated_at":"2015-05-06T14:53:47Z","pushed_at":"2015-05-06T14:53:45Z","git_url":"git://github.com/mariussturm/docker.git","ssh_url":"git@github.com:mariussturm/docker.git","clone_url":"https://github.com/mariussturm/docker.git","svn_url":"https://github.com/mariussturm/docker","homepage":"http://www.docker.com","size":52301,"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":"docker:master","ref":"master","sha":"a242ceaa0967a72dee55ef6a2cec05c78526d33c","user":{"login":"docker","id":5429470,"avatar_url":"https://avatars.githubusercontent.com/u/5429470?v=3","gravatar_id":"","url":"https://api.github.com/users/docker","html_url":"https://github.com/docker","followers_url":"https://api.github.com/users/docker/followers","following_url":"https://api.github.com/users/docker/following{/other_user}","gists_url":"https://api.github.com/users/docker/gists{/gist_id}","starred_url":"https://api.github.com/users/docker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/docker/subscriptions","organizations_url":"https://api.github.com/users/docker/orgs","repos_url":"https://api.github.com/users/docker/repos","events_url":"https://api.github.com/users/docker/events{/privacy}","received_events_url":"https://api.github.com/users/docker/received_events","type":"Organization","site_admin":false},"repo":{"id":7691631,"name":"docker","full_name":"docker/docker","owner":{"login":"docker","id":5429470,"avatar_url":"https://avatars.githubusercontent.com/u/5429470?v=3","gravatar_id":"","url":"https://api.github.com/users/docker","html_url":"https://github.com/docker","followers_url":"https://api.github.com/users/docker/followers","following_url":"https://api.github.com/users/docker/following{/other_user}","gists_url":"https://api.github.com/users/docker/gists{/gist_id}","starred_url":"https://api.github.com/users/docker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/docker/subscriptions","organizations_url":"https://api.github.com/users/docker/orgs","repos_url":"https://api.github.com/users/docker/repos","events_url":"https://api.github.com/users/docker/events{/privacy}","received_events_url":"https://api.github.com/users/docker/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/docker/docker","description":"Docker - the open-source application container engine","fork":false,"url":"https://api.github.com/repos/docker/docker","forks_url":"https://api.github.com/repos/docker/docker/forks","keys_url":"https://api.github.com/repos/docker/docker/keys{/key_id}","collaborators_url":"https://api.github.com/repos/docker/docker/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/docker/docker/teams","hooks_url":"https://api.github.com/repos/docker/docker/hooks","issue_events_url":"https://api.github.com/repos/docker/docker/issues/events{/number}","events_url":"https://api.github.com/repos/docker/docker/events","assignees_url":"https://api.github.com/repos/docker/docker/assignees{/user}","branches_url":"https://api.github.com/repos/docker/docker/branches{/branch}","tags_url":"https://api.github.com/repos/docker/docker/tags","blobs_url":"https://api.github.com/repos/docker/docker/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/docker/docker/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/docker/docker/git/refs{/sha}","trees_url":"https://api.github.com/repos/docker/docker/git/trees{/sha}","statuses_url":"https://api.github.com/repos/docker/docker/statuses/{sha}","languages_url":"https://api.github.com/repos/docker/docker/languages","stargazers_url":"https://api.github.com/repos/docker/docker/stargazers","contributors_url":"https://api.github.com/repos/docker/docker/contributors","subscribers_url":"https://api.github.com/repos/docker/docker/subscribers","subscription_url":"https://api.github.com/repos/docker/docker/subscription","commits_url":"https://api.github.com/repos/docker/docker/commits{/sha}","git_commits_url":"https://api.github.com/repos/docker/docker/git/commits{/sha}","comments_url":"https://api.github.com/repos/docker/docker/comments{/number}","issue_comment_url":"https://api.github.com/repos/docker/docker/issues/comments{/number}","contents_url":"https://api.github.com/repos/docker/docker/contents/{+path}","compare_url":"https://api.github.com/repos/docker/docker/compare/{base}...{head}","merges_url":"https://api.github.com/repos/docker/docker/merges","archive_url":"https://api.github.com/repos/docker/docker/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/docker/docker/downloads","issues_url":"https://api.github.com/repos/docker/docker/issues{/number}","pulls_url":"https://api.github.com/repos/docker/docker/pulls{/number}","milestones_url":"https://api.github.com/repos/docker/docker/milestones{/number}","notifications_url":"https://api.github.com/repos/docker/docker/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/docker/docker/labels{/name}","releases_url":"https://api.github.com/repos/docker/docker/releases{/id}","created_at":"2013-01-18T18:10:57Z","updated_at":"2015-05-06T18:57:36Z","pushed_at":"2015-05-06T19:03:58Z","git_url":"git://github.com/docker/docker.git","ssh_url":"git@github.com:docker/docker.git","clone_url":"https://github.com/docker/docker.git","svn_url":"https://github.com/docker/docker","homepage":"http://www.docker.com","size":199307,"stargazers_count":21392,"watchers_count":21392,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":4999,"mirror_url":null,"open_issues_count":963,"forks":4999,"open_issues":963,"watchers":21392,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/docker/docker/pulls/13015"},"html":{"href":"https://github.com/docker/docker/pull/13015"},"issue":{"href":"https://api.github.com/repos/docker/docker/issues/13015"},"comments":{"href":"https://api.github.com/repos/docker/docker/issues/13015/comments"},"review_comments":{"href":"https://api.github.com/repos/docker/docker/pulls/13015/comments"},"review_comment":{"href":"https://api.github.com/repos/docker/docker/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/docker/docker/pulls/13015/commits"},"statuses":{"href":"https://api.github.com/repos/docker/docker/statuses/3a77220829a0a49d048b20b322bfa1d138bb5b90"}}}}