• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

log4j vs system.out.Println()

 
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi guys

what is the difference between printing

a content in console using log4j and

system.out.println().peoples use to say

that using system.out.println() is performance

loss

i think log4j is written in java so it may also

use system.out.println() to print the content in console


then why peoples preferring log4j ?

i think i have posted this topic in correct forum
i am not including any web related techonology


regards
amir
 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If all you're ever going to want to do is print a few messages to console, then System.out.println() is fine.

A proper logging system, like Log4J, adds all sorts of features that are very useful in real applications. You can direct the output to different places (console, file, network etc.). You can tell it to output only a subset of the messages, without having to recompile. You can get timestamp on each message etc.

If you're writing a small utility program for your own use, which will never expand into something more, use System.out.println(). If you're writing industrial-strength code, or a utility library for others, using a proper logging system is the professional thing to do.

Log4J is not the only one, by the way.
 
Amirtharaj Chinnaraj
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks perter

for your reply

iam scrutinize only in the performance

some bloggers have told that system.out.prrintln() will consume

to much of performance than log4j

i think log4j will consume more performance because it

have has to print more information

regards
amir
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
log4j's ConsoleAppender uses either System.out or System.err, so what you were told is not correct. And as log4j is wrapping the standard streams, it is a bit slower than using System directly.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Amirtharaj, could you please avoid to separate each lines with a blank line. It makes it really difficult to read. Thank you
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Configuration is another factor for using log4j over SOP's.
Even while you are developing you application you can set the log4j level to DEBUG and at production you can turn that to ERROR or FATAL.

Logging too much statements might be a performance overhead .You should always follow the best practices for better performance.
Check out the last section of document.
http://logging.apache.org/log4j/docs/manual.html
 
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Even if you use System.out.println() I would use a wrapper logging class that will later allow you to use log4j while only changing this class and not all of your apps logging methods. I don't have a good example of all the methods you should include, but something like this (as well as the methods that take an exception would be good i.e. error(message, exception))



Initiallly debug might look like this:

 
Amirtharaj Chinnaraj
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks one and all i want to know what are all the similar opensource tools like log4j that can be used in java platform
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you mean open source for logging ?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since Java 1.4, the standard API itself contains a logging facility: see the API documentation of package java.util.logging.

However, a lot of people still seem to prefer Log4J above the standard logging API. Log4J is probably a bit more flexible than the standard logging API.
 
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah, for normal small programs where performance or any other similar issue is never a problem, SOP's are fine, but when running a real time project, its best to use some kind of logger. log4j is great, but even the logger from the util package is better than SOPs...Another thing which intruiges me is assertions, need to use it more!
 
reply
    Bookmark Topic Watch Topic
  • New Topic