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

  • Home
  • SEARCH
  • 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 8425539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:17:54+00:00 2026-06-10T04:17:54+00:00

I don’t want to use something like this : Logger.getLogger(MyClass.class).info(Info message); each time I

  • 0

I don’t want to use something like this :

Logger.getLogger(MyClass.class).info("Info message");

each time I want to log something.

I’ve tried to implement a logging service that has methods like :

public void info(final Object aMessage, final Object aSender);

This allows me get Logger instance based on sender’s class, but it hides the method and line of the log source class.

I know about alternatives like AOP or Slf4j. The first one is not exactly I want, the second one introduces something similar to the first line of code :

LoggerFactory.getLogger(HelloWorld.class).info("Info message");

So, my concern is not about hiding Log4j dependency, it’s about unifying logging calls through the whole application, like this :

//loggingController instance was injected previously
loggingControler.info("Info message",this);

Is there any way to implement this ?

  • 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-10T04:17:56+00:00Added an answer on June 10, 2026 at 4:17 am

    Ok, seems that there is at least one way to resolve the issue :

    For example there are LoggingService and LoggingController. The first one works directly with Log4j, the second one is just a layer between service and the whole application.

    public class LoggingService implements ILoggingService{
    
       //other methods here.
    
       @Override
       public void warn(final Object aMessage, final Object aSender, final Throwable aThrowable) {
           log(aMessage, aSender, Level.WARN, aThrowable);
       }
    
    
       private void log(final Object aMessage, final Object aSender, final Level aLevel, final Throwable aThrowable) {
           final String className = getClassNameBy(aSender);
           Logger.getLogger(className).log(className, aLevel, aMessage, aThrowable);
       }
    }
    
    public class LoggingController implement ILoggingController{
        //logging service is injected previously
        @Override
        public void warn(final Object aMessage, final Throwable aThrowable) {
            loggingService.warn(aMessage, this, aThrowable);
        }
    }
    

    So, in this case you allow the user to log something using :

    loggingController.warn("A warning", null);
    

    Using this way:

    1. User knows nothing about underlying logging functionality
    2. You always have the possibility to provide a dummy logger if you don’t need it, or the environment doesn’t allow it.
    3. The logging functionality is unified across the whole application
    4. The class name and code line are shown correctly in the log.
    5. You cannot use one of the most useful features of the Log4j – filtering by package/class name.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't want to use the Default Satchmo search listener. I've created my own
Don't ask me why but i can't use this method because I need to
Don't want to sort the entries. using this does not preserve the order as
Don't know if this is possible, but I have some code like this: val
Don't know if I'm missing something here. I'd like to run multiple global variables
don't know better title for this, but here's my code. I have class user
Don't dismiss this as a newbie question! It's not, I'm not, I've tried everything,
I don't know why, but this code worked for me a month ago... maybe
For some reason, after submitting a string like this Jack’s Spindle from a text
Don't know if I worded the question right, but basically what I want to

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.