Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Outputting debug information in console

I am doing a Java application, which will use swing user interface. It will ask user to specify some settings, by filling in forms, and then process them and generate some files in the ./output/ directory.

During development process, I'd like to output some technical information in console, using System.out.println() method.

Do I need to remove all these console outputs when I'll finish development?

If yes, what is the best way to display debug information during development process to easily remove it before production?

Maybe I should use only JUnit tests for debugging purposes? I've just started with it, so I have vague idea of ​​its capabilities.

like image 325
Edward Ruchevits Avatar asked Aug 12 '12 15:08

Edward Ruchevits


People also ask

How do I show debug output?

To see the debug output window, in Microsoft Visual Studio, click View, click Other Windows, and then click Output. You can view the debug output in this window only if the debugger is attached to the process that is writing to the output window.

How do I view console debugger?

To see it, either open the Console panel of developer tools or press Esc while in another panel: that opens the console at the bottom. If we have enough logging in our code, then we can see what's going on from the records, without the debugger.

What is a debug output?

Debug Output is an OpenGL feature that makes debugging and optimizing OpenGL applications easier. Briefly, this feature provides a method for the driver to provide textual message information back to the application.

How does console debug work?

The console. debug() method outputs a message to the web console at the "debug" log level. The message is only displayed to the user if the console is configured to display debug output. In most cases, the log level is configured within the console UI.


1 Answers

If you're not going to use a specialised debugging framework it could be as easy as:

if (Debugger.isEnabled())
    Debugger.log("message here");

The Debugger class just encapsulates the println calls (like this):

public class Debugger{
    public static boolean isEnabled(){
        return true;
    }

    public static void log(Object o){
        System.out.println(o.toString());
    }
}

That way when you want to go to production, or you can modify the behavior of your debugging (or disable it) by changing one line in a class.

like image 134
Science_Fiction Avatar answered Sep 21 '22 08:09

Science_Fiction