• 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

What is the use of Supplier in logging message

 
Ranch Hand
Posts: 163
1
jQuery Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I could not able to understand the usage of the Supplier method in logging from OCJP book by Kathy and Sierra. I studied for thrice but couldnot make out any thing. Can any one throw some light on it with simple example.

Thanks & Regards,

Swapna
 
Saloon Keeper
Posts: 15510
363
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What if your log level is set so high that the log statement doesn't need to be performed? For instance, the statement is a debug statement, but the application is configured to only log warning messages or higher.

If it is expensive to create the log message, then it is a waste to create it if it isn't even going to be logged. Instead, you give it a supplier that tells the logger how to create the message, and it only gets called when the message is actually logged.

In general, you want to use the overload that takes a String only if you are logging a literal message, or if you can create the message by concatenating very simple fields or local variables. When in doubt, use the Supplier version.
 
Swapna latha
Ranch Hand
Posts: 163
1
jQuery Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:What if your log level is set so high that the log statement doesn't need to be performed? For instance, the statement is a debug statement, but the application is configured to only log warning messages or higher.

If it is expensive to create the log message, then it is a waste to create it if it isn't even going to be logged. Instead, you give it a supplier that tells the logger how to create the message, and it only gets called when the message is actually logged.

In general, you want to use the overload that takes a String only if you are logging a literal message, or if you can create the message by concatenating very simple fields or local variables. When in doubt, use the Supplier version.


Thank you Stephan. I can understand now.
reply
    Bookmark Topic Watch Topic
  • New Topic