Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preserve colors of heroku logs output when piping to other command (e.g. grep)

I am using grep to remove a lot of log noise generated e.g. by NewRelic. I do so using the following command:

heroku logs --force-colors -t -a myApp -s app | grep --color=never web.1

Unfortunately the useful coloring of the logs gets lost somewhere, and the output is uncolored.

The --force-colors flag should force the heroku logs command to output colors even when pipping the output elsewhere. the --color=never flag is supposed to force grep not to use their own coloring scheme.

I have tried all possible combinations with absence or presence of these two color flags, to no avail. Does anybody have a suggestion on how to solve this issue?

like image 857
David Schumann Avatar asked Aug 17 '18 10:08

David Schumann


1 Answers

I have found a solution here:

script -q /dev/null heroku logs --force-colors -t -a myApp -s app | grep --color=never web.1

The color flags are no even necessary so this works as well:

script -q /dev/null heroku logs -t -a myApp -s app | grep web.1
like image 147
David Schumann Avatar answered Nov 08 '22 00:11

David Schumann