Colors for debug texts

Is there a way to get colors in the text I sent to the debug console?

This does not work:
System.out.println(DBGContext+ "\u001B[41m" + _text + "\u001B[0m");

1 Like

The debug console, in this case, meaning the Netbeans-based SDK?

I’ve never tried to do this. The Apache Netbeans site has a very old HOWTO that might provide a clue.

1 Like
  1. Use logback or log4j2 instead of System.out for debug console output.
  2. for logback you can use color patterns.
    ch.qos.logback.core.pattern.color (Logback-Parent 1.5.5 API)

or just use System.err.println(“”) to output RED text.

1 Like

Also one tip is to use a facade. SLF4J or Java’s own logging API (available from Java 9 and onward). Hook the facade then to actual logging implementation such as the already mentioned ones.

This does not change the outcome of course. This is just a type of architectural choice that potentially helps you in the long run. Only downside is that you might not get access to some logger specific stuff in the code (but you need to configure logger anyway so you can probably get around this anyway).

1 Like

slf4j for the win.

2 Likes

Thanks all, it looks like there is more to it than I had hoped. I will look into it later on. For now I need to find other ways to make debug info more readable.

1 Like

You could use the system shell for a quick trial, try this or a sort of it:

Process run = Runtime.getRuntime().exec(new String[]{"echo", "-e", "\033[38;2;255;50;50m", data}); // data is your data
        
       
 if (run.waitFor() == 1) {
         System.out.println("Run Failed!");
 }

 /* release resources */
 run.destroy();
 run = null;

And, then you could build an API around the system shell to serve this purpose, but you might need to put in mind the system specific shells.

EDIT:
This forks your process (e.g., Unix Process) for a new shell process and destroys it releasing the resources. Destruction could be modeled to run at the end of the jMonkeyEngine application or state, the close() event, and the subprocess could be modeled to run with a JME state initialization, ideally reducing memory allocation/deallocation overheads.