This week's book giveaway is in the NodeJS forum.
We're giving away four copies of Serverless Applications with Node.js and have Slobodan Stojanovic & Aleksandar Simovic on-line!
See this thread for details.
Win a copy of Serverless Applications with Node.js this week in the NodeJS forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

What is the use of Supplier in logging message  RSS feed

 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • 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: 9997
208
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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: 101
  • Mark post as helpful
  • send pies
  • 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.
 
When I was younger I felt like a man trapped inside a woman’s body. Then I was born. My twin is a tiny ad:
global solutions you can do at home or in your backyard
https://www.kickstarter.com/projects/paulwheaton/better-world-boo
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!