0

I'm trying to build a component for application level (java/java ee) logging using log4j.where i can create the jar of the component and put it in class path of any application and use it. Below approach i have followed

  1. I override log method like debug , trace, info etc.

  2. single and multiple argument substutution e.g. MessageFormatter.format("Hi {}. My name is {}.", "Alice", "Bob"); will return the string "Hi Alice. My name is Bob.".

  3. say for example for trace message

    public boolean isTraceEnabled() {  return logger.isTraceEnabled();}
    
    public void trace(String msg, Throwable throwable, Object... args) {
        log(isTraceEnabled(),throwable,msg,args);//
    }
    
    private void log(boolean isEnabled, Throwable throwable, String msg,Object... args)
    {
    
        if(throwable!=null){
            String message=MessageFormatter.getFormattedMessage(throwable);//Formated the exception message 
            msg=msg+message;
            throwable=null;
        }
    
          if (args == null || args.length == 0) {
                logger.log(FQCN,LEVELmsg, throwable);
            } else {
                if (isEnabled) {
                    String formattedMsg = MessageFormatter.arrayFormat(msg, args);//single and multiple argument substutution 
                    logger.log(FQCN, UtilConstant. Level.TRACEformattedMsg, throwable);
                }
            }
    }
    

My aim is to build the component which can cater all the Java EE applications. Is that two approach sufficient or I need to do more on that. Please help.

1
  • What does this do that log4j (or slf4j or others) do not already do? Commented Dec 19, 2011 at 7:43

1 Answer 1

3

It seems to me you're reinventing the wheel. Check out the SLF4J, it can do the things that you're aiming to implement, and it shields you from underlying messaging system, which you can change at any time (it works with log4j out of the box, too).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.