I want to add colors to the text in Log files. For e.g. I would want lines that contain text 'ERROR', to be red colored. So that when I view that file, these I should be able to easily find those lines with 'ERROR'. I tried looking for the answer to question but couldn't find anything helpful. Thanks in advnace.
So that when I view that file, these I should be able to easily find those lines with 'ERROR'.
Coloring those lines would be one way but there's a much simpler and more idiomatic way:
$ grep ERROR /path/to/logfile | less
will show you every line containing ERROR
from /path/to/logfile
in less
.
Someprogrammerdude suggested to use ability of viewers to colorize output. It is called 'syntax highlighting' in vim ecosystem but not only there.
The simplest thing you can do in vim is:
:sy match my_error /.*ERROR.*/
:hi my_error ctermfg=red guifg=red
You can add these lines to your .vimrc
or may better is to create a special syntax file for your log files where you can define more rules...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With