0

I have a Spring MVC webapp and I have some external classes that are not on the class path. They are dynamically placed and are not known at startup time.

They are loaded like this:

List<Object> constructorArgs = new ArrayList<Object>();
List<Object> methodArgs = new ArrayList<Object>();
Constructor<?> c = (Constructor<?>)constructorArgs.get(0);
Method m = (Method)methodArgs.get(0);
Object o = c.newInstance();
Method myMethod = o.getClass().getMethod("myMethod", String.class);

However, none of the logging in those classes and methods work. I assume because they are not loaded at startup for some reason.

Is there a way to register this class with the logger? I am using slf4j with a log4j implementation.

mmaceachran
  • 3,178
  • 7
  • 53
  • 102
  • related? https://stackoverflow.com/questions/1324053/configure-log4j-to-log-to-custom-file-at-runtime do _you_ (as a programmer) know the classes (names) that will be loaded? Are you in control of their source code...? – Jocke May 13 '19 at 19:24
  • If not on the classpath, how did you get the `Constructor` object in the first place. Logging should work fine, assuming the classpath used when loading the class is correct, i.e. has the logging library on it. Are you even sure those classes contain logging statements, because if the classpath was wrong, you likely wouldn't even have been able to load the classes. – Andreas May 13 '19 at 19:30
  • Also, please share your log4j configuration. – Kamil Bęben May 13 '19 at 20:08

0 Answers0