Colorize logs in eclipse console

后端 未结 10 702
别那么骄傲
别那么骄傲 2020-12-07 08:45

Is there a way to colorize parts of logs in the eclipse console. I know I could send to error and standard streams and color them differently but I\'m more looking someting

10条回答
  •  执笔经年
    2020-12-07 09:31

    You can use ANSI Escape in Console plugin for Eclipse. You'll need this so the Eclipse console can interpret ANSI Escape codes. Install it and restart Eclipse. Then you can use ANSI Color Codes to write in a certain color. Here's a list of ANSI Color Codes from another stackoverflow answer. Then you can do this:

    public static final String ANSI_RESET = "\u001B[0m";
    public static final String ANSI_RED = "\u001B[31m";
    
    public static void main(String[] args) {
        System.out.println(ANSI_RED + "This text is red!" + ANSI_RESET);
    }
    

    I used this to create a Custom Formatter for the Console Handler so it shows logs from Logger in different levels with different colors (INFO logs in cyan, WARNING logs in yellow and SEVERE logs in red). Here's how I did it, if you're interested.

提交回复
热议问题