• 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

sysout or logger?

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I would like to know if there are any performance benefits in using a logger (like log4j) and using a System.out.println to print debug / info in an application server. I understand that the use of a logging mechanism is better, but has anybody seen a significant difference between them ?

Thanks,
Midhun.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The big one is you can turn logging off declaratively using a logger, you can't do that with system.out.println statements.
 
Ranch Hand
Posts: 754
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I gonna say 3 benefits for now.:
* You can save the log in a file.
* You can define the level of log. Like, info, debug... This help you like, just showing when the problem is an error.
* You can send the output to more than one exit sysout.

So... go for it! \o/
 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i think sysout will be faster than logging in DEBUG level. but when your application goes to production, you will not log everything. if you do so you have to face a big performance issue. logger gives you much convenient ways implement logging.
 
Ranch Hand
Posts: 608
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no necessary significant performance penalty of using a logger instead of System.out.println(). The time taken to actually print a statement on console far exceeds any overhead of the actual call.

That does not mean log statements should be used blindly - there can be significant performance problems when using logging (special when writing to a file, with log4j - its synchronized.)

However if the choice is between using Println() and logger then logger give significant benefits with no compromise to performance!
 
Curse your sudden but inevitable betrayal! And this tiny ad too!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic