Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

sysout or logger?  RSS feed

 
Midhun Agnihotram
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • 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.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • 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.
 
Hebert Coelho
Ranch Hand
Posts: 754
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • 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/
 
Poobhathy Kannan
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • 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.
 
Saifuddin Merchant
Ranch Hand
Posts: 607
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • 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!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!