"Less" prompts for "binary file" display when colors in output
Solution 1
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
Solution 2
I would never colorize the logfiles themself. This would potentially break any third party script or tool (like grep, sed, awk ...) that would operate on the logfiles or at least clutter their output.
I would instead colorize the output on demand when watching/tailing the logfile. Use colortail
for example.
Related videos on Youtube
reinhard.codes
Updated on September 18, 2022Comments
-
reinhard.codes over 1 year
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 likeless
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?