Re: System.out.println() vs Logging, was Re: JComboBox.setSelectedItem() doesn´t update selected Item?
- From: Lew <lew@xxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 27 May 2007 18:53:29 -0400
RedGrittyBrick wrote:
Lew wrote:Piet71 wrote:In my real program I have added lots of System.out.println's from
One trouble with System.out.println (why didn't you use System.err?) is that they have to be removed for production.
Sorry to jump in here, I'd certainly agree that you should remove those sort of statements (or make them conditional), however since output to System.out is not normally visible in a jar'd Swing application (i.e. when not run from an IDE or command shell) - is there any major problem if they're left in?
Only the drag on performance - println() is invoked regardless of need. Logging libraries are optimized for minimal impact on production performance.
There are many reasons not to use System.out for debug or trace purposes.
I'd be interested in reading your list of those reasons.
The performance reason, ibid. Not having the output stream cluttered with trace statements.
Why not using logging?
I can't answer for the OP, but in my case it went like this:
- System.out.println() works
- it needs no special classes/jars bundled with your app.
Specious.
- it needs no complex XML config files
Neither does log4j.
- it needs no class instantiation/initialisation
Neither does log4j unless you need the flexibility.
- it is just as easy to make conditional
No, it isn't. The conditions add complexity to your code, instead of being hidden inside the logging aspect.
- it is just as easy to comment-out or remove using search/replace
Which is a source code change, much harder than not changing source code. Logging wins, since it doesn't need any code change, not commenting out nor removal via search/replace.
- Logging classes seem like they're oriented to making complex
logging needs possible. Few of them make simple jobs simple.
I have no idea how you came up with this. Logging libraries are dog-simple to use, about as complex as:
Logger logger = Logger.getLogger( getClass() );
....
logger.error( msg );
- There's too many to choose from. Writing System.out.println()
a few dozen times takes a lot less gumption than studying a
half dozen logging classes and choosing one then using it.
I cannot believe you are touting ignorance as an excuse. Pathetic.
Logging takes all of five minutes to learn. Arguing that you are too lazy to learn it is not an indictment of the logging library but of the practitioner.
For my limited needs I preferred to reinvent the logging wheel myself, though I did feel properly guilty about it :-) I ended up with something I could control by environment variables or command line params, which could be used statically without configuration files or instantiation, which could have logging levels set programatically if needed, and which did the right thing in the absence of any configuration.
I don't see how any of that differs from, say, log4j.
It goes without saying that it does a lot less than the more developed logging classes. But I like that it's as easy to use as System.out.println().
I like logging, which is as easy to use as "logger.error( msg )" and doesn't require re-compilation to remove them,
I still use System.out.println() for simple programs.
I'm open to persuasion, so I'm interested to hear more details of the evils of System.out.println().
Go to, say, the Apache logging page for that. They lay the argument out better than I can.
You should actually learn to use, say, log4j, before you pass judgment. By admitting that you haven't learned either that nor java.util.logging, you admit that you do not have a basis for your judgment.
Try it, you'll like it.
--
Lew
.
- Follow-Ups:
- References:
- JComboBox.setSelectedItem() doesn´t update selected Item?
- From: Piet71
- Re: JComboBox.setSelectedItem() doesn´t update selected Item?
- From: Roedy Green
- Re: JComboBox.setSelectedItem() doesn´t update selected Item?
- From: Piet71
- Re: JComboBox.setSelectedItem() doesn´t update selected Item?
- From: Lew
- System.out.println() vs Logging, was Re: JComboBox.setSelectedItem() doesn´t update selected Item?
- From: RedGrittyBrick
- JComboBox.setSelectedItem() doesn´t update selected Item?
- Prev by Date: Re: How to draw a simple line....
- Next by Date: Re: Help: strange behaviour of Combo box
- Previous by thread: System.out.println() vs Logging, was Re: JComboBox.setSelectedItem() doesn´t update selected Item?
- Next by thread: Re: System.out.println() vs Logging, was Re: JComboBox.setSelectedItem() doesn´t update selected Item?
- Index(es):
Relevant Pages
|