I am using Spring IOC and autowired bean of Logger which is a custom wrapper around logger.
@Autowired
private Loggers logger;
which has some wrapper code basically for formatting string's and printing values of enumns in case enums are passed.
public class Loggers implements Serializable {
private static final long serialVersionUID = 1L;
public static Logger TRACE = LogManager.getLogger("com.mypackage.class");
public static String msgXidFormat = " %s : %s : %s ";
public static String msgFormat = " %s : %s ";
public static Logger getLogger(Class clazz) {
Logger logger = LogManager.getLogger(clazz);
return logger;
}
public void info(String message) {
TRACE.info(String.format(msgXidFormat,message);
}
}
And there are some statements which are logged from the Application classes where this Logger bean has been autowired for Ex ::
logger.info("Lion is the king of the Jungle");
where logger refers to the above class.
And this is the log4j pattern Layout in log4j2.xml I am using to print the message along with Class name and Line Number.
<PatternLayout pattern="%d{ISO8601}{GMT} %-5p %c{1}:%L - %m%n"/>
But I am getting the class name for every class as Loggers where i expect the class from which this log statement was first requested. Is there any way i can handle this by not changing the code,as there are lot of classes where this been has been autowired. If any one had faced similar situation or have some idea on it please Share.