{"action":"created","issue":{"url":"https://api.github.com/repos/go-kit/kit/issues/116","labels_url":"https://api.github.com/repos/go-kit/kit/issues/116/labels{/name}","comments_url":"https://api.github.com/repos/go-kit/kit/issues/116/comments","events_url":"https://api.github.com/repos/go-kit/kit/issues/116/events","html_url":"https://github.com/go-kit/kit/pull/116","id":103982317,"number":116,"title":"Implement term.ColorLogger (take 2)","user":{"login":"ChrisHines","id":1060711,"avatar_url":"https://avatars.githubusercontent.com/u/1060711?v=3","gravatar_id":"","url":"https://api.github.com/users/ChrisHines","html_url":"https://github.com/ChrisHines","followers_url":"https://api.github.com/users/ChrisHines/followers","following_url":"https://api.github.com/users/ChrisHines/following{/other_user}","gists_url":"https://api.github.com/users/ChrisHines/gists{/gist_id}","starred_url":"https://api.github.com/users/ChrisHines/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ChrisHines/subscriptions","organizations_url":"https://api.github.com/users/ChrisHines/orgs","repos_url":"https://api.github.com/users/ChrisHines/repos","events_url":"https://api.github.com/users/ChrisHines/events{/privacy}","received_events_url":"https://api.github.com/users/ChrisHines/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-08-31T04:21:53Z","updated_at":"2015-08-31T07:34:50Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/go-kit/kit/pulls/116","html_url":"https://github.com/go-kit/kit/pull/116","diff_url":"https://github.com/go-kit/kit/pull/116.diff","patch_url":"https://github.com/go-kit/kit/pull/116.patch"},"body":"This is an evolution of #109 to improve the concurrency story.\r\n\r\nThe key change is to have `ColorLogger` completely own the wrapped formatting logger and thereby eliminate the possibility that some other part of the application potentially calls its `Log` method outside of the `ColorLogger`'s control and cause havoc.\r\n\r\nTo achieve this goal we change the signature of `NewColorLogger` to the following.\r\n```go\r\nfunc NewColorLogger(w io.Writer, newLogger func(io.Writer) log.Logger, color func(keyvals ...interface{}) FgBgColor) log.Logger\r\n```\r\nIt now accepts an `io.Writer` and a constructor function. It uses `newLogger` to create `Logger`s that write to buffers controlled by the `ColorLogger`. The `ColorLogger` adds color codes to the buffered results and writes the combined results to `w`.\r\n\r\nCreateing a `ColorLogger` now looks like this\r\n```go\r\nlogger := term.NewColorLogger(os.Stdout, log.LogfmtLogger, term.LevelColor)\r\n```\r\n\r\nFurthermore, `log.Hijacker` and all of its implementations are eliminated. The concurrency question is handled by a `sync.Pool` that manages a free list of buffer-Logger pairs. Using a buffer pool reduces the amortized allocation cost of `ColorLogger` to zero and eliminates the `sync.Mutex`s from the previous version.\r\n\r\n```\r\nBenchmarkLogfmtLoggerSimple-4             500000              2508 ns/op             384 B/op          6 allocs/op\r\nBenchmarkColorLoggerSimple-4              500000              2672 ns/op             384 B/op          6 allocs/op\r\n\r\nBenchmarkLogfmtLoggerContextual-4         500000              3656 ns/op             560 B/op          9 allocs/op\r\nBenchmarkColorLoggerContextual-4          300000              4270 ns/op             560 B/op          9 allocs/op\r\n```"},"comment":{"url":"https://api.github.com/repos/go-kit/kit/issues/comments/136288127","html_url":"https://github.com/go-kit/kit/pull/116#issuecomment-136288127","issue_url":"https://api.github.com/repos/go-kit/kit/issues/116","id":136288127,"user":{"login":"tgulacsi","id":256074,"avatar_url":"https://avatars.githubusercontent.com/u/256074?v=3","gravatar_id":"","url":"https://api.github.com/users/tgulacsi","html_url":"https://github.com/tgulacsi","followers_url":"https://api.github.com/users/tgulacsi/followers","following_url":"https://api.github.com/users/tgulacsi/following{/other_user}","gists_url":"https://api.github.com/users/tgulacsi/gists{/gist_id}","starred_url":"https://api.github.com/users/tgulacsi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tgulacsi/subscriptions","organizations_url":"https://api.github.com/users/tgulacsi/orgs","repos_url":"https://api.github.com/users/tgulacsi/repos","events_url":"https://api.github.com/users/tgulacsi/events{/privacy}","received_events_url":"https://api.github.com/users/tgulacsi/received_events","type":"User","site_admin":false},"created_at":"2015-08-31T07:34:50Z","updated_at":"2015-08-31T07:34:50Z","body":"Nice solution."}}