{"action":"created","issue":{"url":"https://api.github.com/repos/sirupsen/logrus/issues/780","repository_url":"https://api.github.com/repos/sirupsen/logrus","labels_url":"https://api.github.com/repos/sirupsen/logrus/issues/780/labels{/name}","comments_url":"https://api.github.com/repos/sirupsen/logrus/issues/780/comments","events_url":"https://api.github.com/repos/sirupsen/logrus/issues/780/events","html_url":"https://github.com/sirupsen/logrus/issues/780","id":336512803,"node_id":"MDU6SXNzdWUzMzY1MTI4MDM=","number":780,"title":"[Question]: Strange output to file in case of io.MultiWriter","user":{"login":"Blogoslov","id":2910785,"node_id":"MDQ6VXNlcjI5MTA3ODU=","avatar_url":"https://avatars0.githubusercontent.com/u/2910785?v=4","gravatar_id":"","url":"https://api.github.com/users/Blogoslov","html_url":"https://github.com/Blogoslov","followers_url":"https://api.github.com/users/Blogoslov/followers","following_url":"https://api.github.com/users/Blogoslov/following{/other_user}","gists_url":"https://api.github.com/users/Blogoslov/gists{/gist_id}","starred_url":"https://api.github.com/users/Blogoslov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Blogoslov/subscriptions","organizations_url":"https://api.github.com/users/Blogoslov/orgs","repos_url":"https://api.github.com/users/Blogoslov/repos","events_url":"https://api.github.com/users/Blogoslov/events{/privacy}","received_events_url":"https://api.github.com/users/Blogoslov/received_events","type":"User","site_admin":false},"labels":[{"id":61224104,"node_id":"MDU6TGFiZWw2MTIyNDEwNA==","url":"https://api.github.com/repos/sirupsen/logrus/labels/question","name":"question","color":"cc317c","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-06-28T07:56:19Z","updated_at":"2018-06-30T13:48:51Z","closed_at":null,"author_association":"NONE","body":"Hello, I use io.MultiWriter to be able to see logs in the console and in the log file.  As a solution, I use this approach which was recommended here.\r\n\r\nHere is my example for reproducing:\r\n\r\n```\r\npackage main\r\n\r\nimport (\r\n\t\"github.com/sirupsen/logrus\"\r\n\t\"io\"\r\n\t\"os\"\r\n)\r\n\r\nfunc main() {\r\n\tlog := logrus.New()\r\n\r\n\tcustomFormatter := new(logrus.TextFormatter)\r\n\tcustomFormatter.TimestampFormat = \"2006-01-02 15:04:05\"\r\n\tcustomFormatter.ForceColors = true\r\n\tcustomFormatter.FullTimestamp = true\r\n\tcustomFormatter.DisableColors = false\r\n\tlog.Formatter = customFormatter\r\n\r\n\tlog.Level = logrus.InfoLevel\r\n\r\n\tfile, _ := os.Create(\"./tt\")\r\n\tmw := io.MultiWriter(os.Stdout, file)\r\n\tlog.Out = mw\r\n\tlog.Info(\"This is test\")\r\n\tlog.Error(\"Error message\")\r\n\r\n}\r\n```\r\n\r\nAs a result, I see a nice colored output in the console, but this is what I see in the file:\r\n\r\n\r\n> \u001B[34mINFO\u001B[0m[2018-06-28 09:52:15] This is test                                 \r\n> \u001B[31mERRO\u001B[0m[2018-06-28 09:52:15] Error message      \r\n\r\n                          \r\n\r\nSo I see non-readable strange symbols which wrap the level.\r\n\r\nHow to avoid this strange behavior?\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/sirupsen/logrus/issues/comments/401542420","html_url":"https://github.com/sirupsen/logrus/issues/780#issuecomment-401542420","issue_url":"https://api.github.com/repos/sirupsen/logrus/issues/780","id":401542420,"node_id":"MDEyOklzc3VlQ29tbWVudDQwMTU0MjQyMA==","user":{"login":"dgsb","id":5495748,"node_id":"MDQ6VXNlcjU0OTU3NDg=","avatar_url":"https://avatars1.githubusercontent.com/u/5495748?v=4","gravatar_id":"","url":"https://api.github.com/users/dgsb","html_url":"https://github.com/dgsb","followers_url":"https://api.github.com/users/dgsb/followers","following_url":"https://api.github.com/users/dgsb/following{/other_user}","gists_url":"https://api.github.com/users/dgsb/gists{/gist_id}","starred_url":"https://api.github.com/users/dgsb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dgsb/subscriptions","organizations_url":"https://api.github.com/users/dgsb/orgs","repos_url":"https://api.github.com/users/dgsb/repos","events_url":"https://api.github.com/users/dgsb/events{/privacy}","received_events_url":"https://api.github.com/users/dgsb/received_events","type":"User","site_admin":false},"created_at":"2018-06-30T13:48:51Z","updated_at":"2018-06-30T13:48:51Z","author_association":"COLLABORATOR","body":"Those strange are tty escape sequence to produce colors on the terminal. With the current implementation you can not have both color in the terminal and clean output in the file.\r\nIf you want to have clean content in your file you should configure your formatter by setting ForColors field to true and DisableColors to false."}}
{"actor":{"display_login":"dgsb"}}