Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have been doubting for a long time whether or not to have a logger in methods (usually helper methods) like the one below.

Whether we can print it in the method or print the response where the method is called.

public String getAddNewUserUrl()
    String url      =   null;
    String mode     =   null;
    {"Inside getAddNewUserUrl "); // Can u use logs like this.
        mode        =   new ModeUtil().getMode();

        if("local".equalsIgnoreCase(mode) || "staging".equalsIgnoreCase(mode))
            url     =   ResourceBundle.getBundle("ApplicationResources").getString("staging.url");
            url     =   ResourceBundle.getBundle("ApplicationResources").getString("staging.url");  
        }"The url is  : " + url);  // Can u use logs like this

    catch(Exception e)
        e.printStackTrace();"Exception in the method getMode ::"+e.getMessage());
    return url;
share|improve this question
up vote 6 down vote accepted

Logs are supposed to be put in every part of your application to provide meaningful information to developer/tester/debuggers or any other stake holder.

Just be careful to put appropriate logging level in your helper classes/utilities especially if you going to distribute it as jar.

share|improve this answer
I'd add that it's good to be judicious with logging. In addition to setting the correct logging level, it's important to think about why you're doing the logging, and whether you'll glean (or regret missing) some crucial piece of information at runtime. – Jonathan Feb 5 '13 at 13:11

It's ok to have logging in every part of your application, even in the helper methods, if you can set different logging levels."The url is  : " + url, LogLevel.Debug);

This ensures that you can turn it on or off depending on how much info you want to gather. Having it always on, that's not so smart.

share|improve this answer
can I use ? log.log(java.util.logging.Level.SEVERE,e.getMessage(),e); – Sridhar Feb 5 '13 at 11:26
yes, that's for stuff like exceptions that shouldn't happen, i.e. your database connection is down or some file that's supposed to be there isn't. – linkerro Feb 5 '13 at 11:27

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.