Re: System.out.println() vs Logging, was Re: JComboBox.setSelectedItem() doesn´t update selected Item?



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
.



Relevant Pages

  • Re: Delphi 2007 more Flakey than 2006?
    ... The most effective manner to debug the IDE is using a developer build. ... With that comes full access to source code. ... to customers except in a secure environment (which is actually what ... logging technology (CodeSite, windows event log, roll your own, ...
    (borland.public.delphi.non-technical)
  • Re: changing log file of log4j for an individual package within a webapp running on Tomcat
    ... Is there a way I can make this thread (the source code of which comes ... The Webapp is NOT using log4j but is using Commons- ... folder and the log4j in the web-ing/lib folder...all the logging of ...
    (comp.lang.java.programmer)
  • Re: AOP use cases
    ... > use cases for AOP as well. ... the logging example seems to ... Because I couldn't get the source code to change it, ... would not need it (and I don't really care if the design is ...
    (comp.lang.python)
  • Re: Limit on "fmt" buffer size? Loose much of long line.
    ... >> If you have control over the program which is doing the logging, ... But will modify the source code to limit ... my iterations counters have rolled over. ...
    (comp.unix.programmer)
  • Re: Limit on "fmt" buffer size? Loose much of long line.
    ... >> If you have control over the program which is doing the logging, ... But will modify the source code to limit ... my iterations counters have rolled over. ...
    (comp.unix.solaris)