Linux – “Less” prompts for “binary file” display when colors in output

escape-sequenceslesslinuxshellunix

We've recently enabled colouring the log files of a few services, I believe we use ANSI escape sequences for that. Looks like this:

[2014-06-12 10:56:43,214] [main] [VOID] ESC[34mINFO ESC[0;39m ESC[36mc.a.m.p.s.config.DataSourceConfigESC[0;39m 

My colleagues mostly use tail to view logfiles, but I like less better. Unfortunately, less doesn't automatically pick up on those escape codes. Instead it tells me that my log file "may be a binary file. See it anyway?".

I know if I add the -r option, less will display the colors, but it still asks the "binary file" question.

Is there a way to get around this? If yes, can I make this a default?

Best Answer

The flag is -f or --force:

less -f -r myfile

In order to make it default you should set this environment variable, for example in /etc/profile

LESS=-f