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
I override log method like debug , trace, info etc.
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.".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.