+ return false;
+ }
+
+ /*
+ * Detect capabilities of the log4j library. We only
+ * support log4j >= 1.2.15. The getTimeStamp() method
+ * was introduced in log4j 1.2.15, so verify that it
+ * is available.
+ *
+ * We can't rely on the getPackage().getImplementationVersion()
+ * call that would retrieves information from the manifest file
+ * found in the JAR since the manifest file shipped
+ * from upstream is known to be broken in several
+ * versions of the library.
+ *
+ * More info:
+ * https://issues.apache.org/bugzilla/show_bug.cgi?id=44370
+ */
+
+ try {
+ logging.getDeclaredMethod("getTimeStamp");
+ } catch (NoSuchMethodException e) {
+ System.err.println("Warning: The loaded log4j library is too old. Log4j tracing with LTTng will be disabled.");
+ return false;
+ } catch (NullPointerException e) {
+ /* Should never happen */
+ return false;
+ } catch (SecurityException e) {
+ return false;
+ }
+
+ return true;
+ }
+
+ private Class<?> loadClass(String className) throws ClassNotFoundException {
+ ClassLoader loader;
+ Class<?> loadedClass;
+
+ try {
+ /* Try to load class using the current thread's context class loader */
+ loader = Thread.currentThread().getContextClassLoader();
+ loadedClass = loader.loadClass(className);
+ } catch (ClassNotFoundException e) {
+ /* Loading failed, try using the system class loader */
+ loader = ClassLoader.getSystemClassLoader();
+ loadedClass = loader.loadClass(className);