-1

Is it possible to create annotation to expose a custom Logger variable into the class for direct use, so that I don't have to do something to the effect of:

Logger logger = CustomerLoggerFactory.getLogger(MyClass.class);

It would be nice if the above was implicitly available due to the annotation and I could just go about doing logger.debug("..."); without the declaration.

Similar question is asked https://stackoverflow.com/questions/6351082/using-java-annotation-to-inject-logger-dependency for Spring and all answers are Spring specific. I am looking for simple Java.

Edit: I cannot use lombok as the IBM product I am developing for provides its own logger factories and those the only way to get a logger via MXLogger.getLogger(key) method

AhmedRana
  • 486
  • 9
  • 22

1 Answers1

0

Try this:

  1. Add maven Lombok dependency and user @log4j2
  2. Create a class that will return logger to you

If I understand you correctly, this is ur answer.

  • Lombok can only provide some specific loggers I believe. The IBM product I am developing for gives logger from its own factory. – AhmedRana Nov 08 '22 at 08:24