2

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?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
user3089783
  • 91
  • 1
  • 2
  • 4

3 Answers3

7

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.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
1

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;}
mweisz
  • 3,899
  • 3
  • 17
  • 16
0

You could look for a plugin to your IDE if you want colorized logs.

Xavier Coulon
  • 1,580
  • 10
  • 15