12

enter image description here

Reading a Rails log with vim, we can see a colored log. But when we use tail -f or less to watch the log, it isn't colorized anymore. Is there any way to see the colored log with tail or less or whatever?

Benjamin
  • 10,085
  • 19
  • 80
  • 130

3 Answers3

21

pass -R to less for it to let colour escape sequences pass through, i.e.

less -R log/development.log

This should result in them being displayed in colour, assuming you are using the proper terminal type

Frederick Cheung
  • 83,189
  • 8
  • 152
  • 174
  • 1
    Could you explain about the *proper terminal type* little more? – Benjamin Jun 24 '12 at 16:46
  • 1
    The colours come from unprintable characters that tell your terminal to switch colours. If your terminal isn't configured to display colours this will do nothing. How you set this up is platform dependant - on OS x's standard terminal it's the ANSI colors setting. – Frederick Cheung Jun 24 '12 at 17:11
7
tail -f log/development.log | ccze -A

You may need to install ccze

sudo apt-get install ccze

it works better, not ideal but works

chech
  • 1,085
  • 14
  • 21
1

You can't do that out of the box, since tail and less know nothing about Rails, and logs are saved a simple text files. You could use regular expressions to colorize output but I doubt it's worth the trouble.

EDIT: see alfonso's comment for some alternatives.

Oscar Del Ben
  • 4,485
  • 1
  • 27
  • 41