I want to write a message in red colour on the log file in java using logger.debug method,is there any way to do it?
How to get coloured Output on the Log file in java?
4.9k views Asked by user3089783 At
3
There are 3 answers
0
On
Logging itself is just plain text with no means of displaying a message in a particular colour (think of it as a txt file). So if you really want colour in your logs you need to encode that as formatting information which can later be interpreted by a text reader, log viewer or web browser. Probably the easiest would be to use HTML for this. This could for example look like this:
<span class="error">02.01.13 14:23 Something bad happend</span>
<span class="info">02.01.13 14:24 This is just an info message</span>
and additionally providing a CSS file containing the styling information.
.info{ color: #000000; }
.error{ color: #FF0000; font-weight:bold;}
Logs don't support styled text! The software used to display them might use some cleverness to color different parts differently, but that is done purely in the software.