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 6812335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:26:12+00:00 2026-05-26T20:26:12+00:00

I have a logging statement in a method of my Superclass. I want to

  • 0

I have a logging statement in a method of my Superclass. I want to enable this statement only if the method is called for an Object of SubClassA.

public class SuperClass
{
private static Logger               logger  = Logger.getLogger(SuperClass.class);
public void test()
{
    logger.info("test...");
}
}

…

public class SubClassA extends SuperClass
{
private static Logger               logger  = Logger.getLogger(SubClassA.class);
}

…

public class SubClassB extends SuperClass
{
private static Logger               logger  = Logger.getLogger(SubClassB.class);
public static void main(String[] p_Args)
{
    SubClassA subClassA = new SubClassA();
    SubClassB subClassB = new SubClassB();
    subClassA.test();
    subClassB.test();
}
}

How do I enable logging in test() only for SubclassA?

log4j.logger.SuperClass=info //enables logging in the test() method for both Subclasses

log4j.logger.SubClassA=info //does nothing for the test() method

  • 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-05-26T20:26:13+00:00Added an answer on May 26, 2026 at 8:26 pm

    I don’t think it’s possible, because logger doesn’t know anything about classes and inheritance. A logger name is a simple textual name like “a.b.c.d”. Maybe you could use subclass’s class in super class, i.e. instead of:

    private static Logger               logger  = Logger.getLogger(SuperClass.class);
    

    use:

    private Logger               logger  = Logger.getLogger(getClass());
    

    or you could use both:

    private Logger               subLogger  = Logger.getLogger(getClass());
    private static Logger        logger  = Logger.getLogger(SuperClass.class);
    

    and then you could use more sophisticated logic:

    if(logger.isInfoEnabled() || subLogger.isInfoEnabled())
    {
    ...
    }
    

    But if I were you, I would not use this magic, because logging should be as simple as possible (but not simpler).

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

Sidebar

Related Questions

Basically I have a logging statement inside of a method. Whenever the method is
I have a logging class that stores entries in a datatable dt. I then
I have a logging functionality and in this I have got log files. Now
I have a commons-logging configuration question. I want it to use SimpleLog (instead of
Ok I want some opinions how I can fix this mess of a method!
I have a table for logging method calls. It has LogId, MethodId, DateTime columns.
I have a logging project , i need to know how to build a
In my application, I have a 'logging' window, which shows all the logging, warnings,
I have a problem logging onto a page and then using it with cURL.
I have a static logging function that uses StringBuilder to concatenate a bunch of

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.