Question

I'm trying to switch from log4j 1.2 to log4j 2 in a Matlab application.

I have added log4j-core-2.0-beta3.jar and log4j-api-2.0-beta3.jar to my Matlab java classpath.

In my Matlab class constructor I:

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

this.logger = LogManager.getLogger(myClassNameAsString);

but when I inspect the Logger object I see:

K>> this.logger

ans =

myClassNameAsString:ERROR in Default

I have no configuration file defined, I expected log4j to give me the default configuration and log to the console (as per log4j2 docs)

Am I doing something wrong?

Is there a problem using log4j2 from within Matlab?

Edit: I believe this is related to the inbuilt usage of log4j in Matlab for Matlab's own internal logging. I managed to work around a similar issue with logback, in that logback complains about Matlab's use of log4j. The classpath.txt file can probably be used to resolve this, ie remove log4j from the classpath.txt but this may break Matlab's internal logging. I worked around the issue by switching to a different logging tool.

Was it helpful?

Solution

My version of Matlab (R2012a) utilizes log4j under the hood so your code might be linking to the older version of log4j (R2012a\java\jarext\log4j.jar ).

Check out the classpath.txt file located under your Matlab Root:\toolbox\local directory.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top