Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logging to command window?

Tags:

java

Coming from Web-Applications: if I create a normal java tool with only some command prompt output - what is the best way to print those outputs? Using System.out.println, or is there some kind of logger that I'm not aware of?

(apart from including external libs like log4j, which would be overkill for a small tool).

like image 703
membersound Avatar asked Feb 03 '26 17:02

membersound


1 Answers

If you don't want to use log4j (which you should), you can use Java's standard logger.

log4j is more popular because of its ease of use, configurability, more intuitive severity levels, and a much nicer default pattern.

A nice tutorial on the standard Java logger can be found here.

A nice tutorial on log4j configured to output to STDOUT (which is the console for console apps) can be found here.

The use of System.our.println is discouraged because you cannot easily disable certain messages that you may have needed at some point (and may need again in the future) for debugging.

like image 139
Zoltán Avatar answered Feb 06 '26 06:02

Zoltán



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!