{"action":"created","issue":{"url":"https://api.github.com/repos/Sirupsen/logrus/issues/230","repository_url":"https://api.github.com/repos/Sirupsen/logrus","labels_url":"https://api.github.com/repos/Sirupsen/logrus/issues/230/labels{/name}","comments_url":"https://api.github.com/repos/Sirupsen/logrus/issues/230/comments","events_url":"https://api.github.com/repos/Sirupsen/logrus/issues/230/events","html_url":"https://github.com/Sirupsen/logrus/issues/230","id":99940045,"number":230,"title":"Multiple io.Writers","user":{"login":"demizer","id":30035,"avatar_url":"https://avatars.githubusercontent.com/u/30035?v=3","gravatar_id":"","url":"https://api.github.com/users/demizer","html_url":"https://github.com/demizer","followers_url":"https://api.github.com/users/demizer/followers","following_url":"https://api.github.com/users/demizer/following{/other_user}","gists_url":"https://api.github.com/users/demizer/gists{/gist_id}","starred_url":"https://api.github.com/users/demizer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/demizer/subscriptions","organizations_url":"https://api.github.com/users/demizer/orgs","repos_url":"https://api.github.com/users/demizer/repos","events_url":"https://api.github.com/users/demizer/events{/privacy}","received_events_url":"https://api.github.com/users/demizer/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Sirupsen/logrus/labels/help-wanted","name":"help-wanted","color":"5319e7"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-08-09T23:31:22Z","updated_at":"2016-04-16T08:03:48Z","closed_at":"2016-04-16T08:03:48Z","body":"It would be great for CLI applications if there was a way to have colorized stdout and json/logfmt formatted output to a file at the same time. It is possible to set `logger.Out` to an `io.MultiWriter`, but then file output is ansi encoded, when logfmt or json formatted output would be much preferred. Using tee with a logrus enabled cli application sets the output to a purely logfmt formatted output with no coloring.\r\n\r\nI have done this previously in my own (now defunct) logging package [go-logs](https://github.com/demizer/go-logs/blob/master/src/logs/logger.go#L775) by writing to multiple `io.Writers` and removing coloring for writers that were of type `*os.File`, but not `os.Stout` or `os.Stderr`. \r\n\r\n```go\r\n\tfor _, w := range l.streams {\r\n\t\twIface := reflect.ValueOf(w).Interface()\r\n\t\tswitch wType := wIface.(type) {\r\n\t\tcase *os.File:\r\n\t\t\tif wType == os.Stdout || wType == os.Stderr {\r\n\t\t\t\twrite(w, ASCII_OUTPUT)\r\n\t\t\t\tcontinue\r\n\t\t\t}\r\n\t\t\twrite(w, LOGFMT_OUTPUT)\r\n\t\tdefault:\r\n\t\t\twrite(w, LOGFMT_OUTPUT)\r\n\t\t}\r\n\t}\r\n```\r\nThis implementation used reflect on every write, but this would only be necessary in cases where there were more than one `io.Writer`."},"comment":{"url":"https://api.github.com/repos/Sirupsen/logrus/issues/comments/210760947","html_url":"https://github.com/Sirupsen/logrus/issues/230#issuecomment-210760947","issue_url":"https://api.github.com/repos/Sirupsen/logrus/issues/230","id":210760947,"user":{"login":"aybabtme","id":1189716,"avatar_url":"https://avatars.githubusercontent.com/u/1189716?v=3","gravatar_id":"","url":"https://api.github.com/users/aybabtme","html_url":"https://github.com/aybabtme","followers_url":"https://api.github.com/users/aybabtme/followers","following_url":"https://api.github.com/users/aybabtme/following{/other_user}","gists_url":"https://api.github.com/users/aybabtme/gists{/gist_id}","starred_url":"https://api.github.com/users/aybabtme/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aybabtme/subscriptions","organizations_url":"https://api.github.com/users/aybabtme/orgs","repos_url":"https://api.github.com/users/aybabtme/repos","events_url":"https://api.github.com/users/aybabtme/events{/privacy}","received_events_url":"https://api.github.com/users/aybabtme/received_events","type":"User","site_admin":false},"created_at":"2016-04-16T08:03:48Z","updated_at":"2016-04-16T08:03:48Z","body":"Personally, I think this is best handled in Hooks and Formatters. This is how I've done it before to add syslog output.\r\n\r\n@demizer if you want to implement a custom formatter that does this, we could then add it to the README list."}}