title: How do you use Log4j2 from within Matlab
body: <p>I'm trying to switch from log4j 1.2 to log4j 2 in a Matlab application.</p>
  
  <p>I have added log4j-core-2.0-beta3.jar and log4j-api-2.0-beta3.jar to my Matlab java classpath.</p>
  
  <p>In my Matlab class constructor I:</p>
  
  <pre><code>import org.apache.logging.log4j.LogManager;
  import org.apache.logging.log4j.Logger;
  
  this.logger = LogManager.getLogger(myClassNameAsString);
  </code></pre>
  
  <p>but when I inspect the Logger object I see:</p>
  
  <pre><code>K&gt;&gt; this.logger
  
  ans =
  
  myClassNameAsString:ERROR in Default
  </code></pre>
  
  <p>I have no configuration file defined, I expected log4j to give me the default configuration and log to the console (as per log4j2 docs)</p>
  
  <p>Am I doing something wrong?</p>
  
  <p>Is there a problem using log4j2 from within Matlab?</p>
  
  <p>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.</p>