Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8845853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:49:59+00:00 2026-06-14T11:49:59+00:00

If I have a java util logging statement such as logger.log(LEVEL.FINE, data buffer =

  • 0

If I have a java util logging statement such as

logger.log(LEVEL.FINE, "data buffer = {0}", 
CommonUtils.prepareDataBufferString(dataBuffer));

Now even when my log level is not at FINE, the expensive prepare.. method still gets called,
which is not what I want to happen. I end up checking the logger level before this statement

if(logger.isLoggable(LEVEL.FINE)){
   bufferString = CommonUtils.prepareDataBufferString(dataBuffer);
}

logger.log(LEVEL.FINE, "data buffer = {0}", bufferString);

this increases the lines of code unnecessarily. Can I avoid having to do this somehow. please help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T11:50:01+00:00Added an answer on June 14, 2026 at 11:50 am

    A technique like this might help.

    logger.log(LEVEL.FINE, "data buffer = {0}", 
        new Object() {
            @Override public String toString() {
                return CommonUtils.prepareDataBufferString(dataBuffer));
            }
        });
    

    FYI, it’s not the log framework calling the method, it’s Java. Java requires that you evaluate all the parameters to a method before the method can be invoked (this is called eager evaluation, contrast to lazy evaluation).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to use java.util.logging.logger to log stuff on to a file
Using java.util.logging.Logger to output some log to the console just like this: public static
Hi I currently have this in my .properties file: java.util.logging.FileHandler.pattern = %h/programName%u%g.log I would
I have initialized a java.util.logging.Logger bean and now want to add a Handler which
I am using java.util.logging.Logger Class for logging in my application. I have added FileHandler
package ewa; import java.io.UnsupportedEncodingException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.logging.Level; import java.util.logging.Logger; import java.math.BigInteger;
Say I have the following config for the java util logger I am using
I want to inherit to extend java.util.logging.Logger . The only visible constructor is protected
I'm having trouble finding my physical log files. I'm using the java.util.logging classes. I
In my application I have written my own Logging utility using Java.Util.Logging import java.io.IOException;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.