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?
            Asked
            
        
        
            Active
            
        
            Viewed 4,957 times
        
    2
            
            
        - 
                    4Logs don't support styled text! – Andrew Thompson Jan 02 '14 at 13:49
 - 
                    2Text is just data, it doesn't have a color. How are you going to denote color? Rich text? HTML? – David Jan 02 '14 at 13:49
 - 
                    You can print it in red in console though: System.err.println() – Lucas Jan 02 '14 at 13:50
 - 
                    i know about the system.err.println(),but to get the output on log file in red colour. – user3089783 Jan 02 '14 at 13:51
 - 
                    1You are either not listening to, or not understanding, what you are being told. – Andrew Thompson Jan 02 '14 at 13:52
 - 
                    Actually i saw some code i.e. using MulticolorLayout to set the colors of messaages in log4j file – user3089783 Jan 02 '14 at 13:57
 - 
                    What is `MulticolorLayout`?!? Links please.. I can only guess that the foftware producing the log is actually writing HTML, as discussed in the answer of feaDawn. Tip: Add @Lucas (or whoever - the `@` is important) to *notify* them of a new comment. – Andrew Thompson Jan 02 '14 at 14:05
 
3 Answers
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