I am using slf4j and log4j2 and i want to create a common interceptor. like below so in future if any log4j uprade came up, i would not have to change every class. Please review below code and let me know your thoughts regarding performance and memory. Is there any other better way we can do this?
Class LoggingHelper {
public static void logEvent(Class clazz, String message, Object ...args) {
Logger logger = LoggerFactory.getLogger(clazz);
logger.info(message,args);
}
}
Protecting users against changes in the underlying implementation is exactly what APIs like SLF4J or Log4j2 API (cf. API separation) are for. Although a semantic major version bump in the API can break consumer code, no such change ever occurred: e.g. the recent 2.x version of SLF4J semantically is a minor version bump and only requires updates in the implementations.
Using API wrappers like the one you are proposing is usually a bad idea, because you have to reimplement a lot of details that the API already takes care of. In your example:
LoggingHelper
,Software systems have a tendency to abandon their custom logging APIs: e.g. Jetty dropped its custom logging API in version 10.x.