Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Keep in mind that the overriding ability you get with the OpenEJB logger works with system properties as well as InitialContext properties.</p> <p>The <code>openejb.logger.external</code> property is really aimed at servers integrating OpenEJB, such as Geronimo, who are using different logging systems and need advanced control over logging. It is not designed for common use as with this option enabled and no other steps taken, you get <strong>no logging</strong> of any kind, not even ERROR, and no info on failed deployments. Even correct usage will still disable all options discussed below.</p> <p>If the desire is to get the logging configuration in or out of the test there are many ways to do it without losing any logging functionality OpenEJB provides.</p> <h2>Option 1: in code via InitialContext properties</h2> <p>In the test case itself via InitialContext properties</p> <pre><code>Properties p = new Properties(); p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory"); p.put("log4j.rootLogger", "fatal,C"); p.put("log4j.category.OpenEJB", "warn"); p.put("log4j.category.OpenEJB.options", "warn"); p.put("log4j.category.OpenEJB.server", "warn"); p.put("log4j.category.OpenEJB.startup", "warn"); p.put("log4j.category.OpenEJB.startup.service", "warn"); p.put("log4j.category.OpenEJB.startup.config", "warn"); p.put("log4j.category.OpenEJB.hsql", "warn"); p.put("log4j.category.CORBA-Adapter", "warn"); p.put("log4j.category.Transaction", "warn"); p.put("log4j.category.org.apache.activemq", "error"); p.put("log4j.category.org.apache.geronimo", "error"); p.put("log4j.category.openjpa", "warn"); p.put("log4j.appender.C", "org.apache.log4j.ConsoleAppender"); p.put("log4j.appender.C.layout", "org.apache.log4j.SimpleLayout"); p.put("openejb.nobanner", "false"); Context context = new InitialContext(p); </code></pre> <h2>Option 2: a jndi.properties file</h2> <p>File must be in the classpath at any path that evaluates to "/jndi.properties", so not "/META-INF/jndi.properties"</p> <p>In Maven this can be done by placing the file at <code>src/test/resources/jndi.properties</code></p> <pre><code>log4j.rootLogger = fatal,C log4j.category.OpenEJB = warn log4j.category.OpenEJB.options = warn log4j.category.OpenEJB.server = warn log4j.category.OpenEJB.startup = warn log4j.category.OpenEJB.startup.service = warn log4j.category.OpenEJB.startup.config = warn log4j.category.OpenEJB.hsql = warn log4j.category.CORBA-Adapter = warn log4j.category.Transaction = warn log4j.category.org.apache.activemq = error log4j.category.org.apache.geronimo = error log4j.category.openjpa = warn log4j.appender.C = org.apache.log4j.ConsoleAppender log4j.appender.C.layout = org.apache.log4j.SimpleLayout openejb.nobanner = false </code></pre> <p>Here is a <a href="http://www.youtube.com/watch?v=LW6jsIJ3-tM" rel="noreferrer">short video</a> of the above option in action.</p> <p>Note that finding and reading the jndi.properties file is a functionality of the <a href="http://download.oracle.com/javase/jndi/tutorial/beyond/env/source.html" rel="noreferrer">java vm</a> so if it doesn't work, it is more likely to be a configuration issue rather than a vm bug.</p> <h2>Option 3: Maven Surefire config</h2> <pre><code>&lt;plugin&gt; &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt; &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt; &lt;version&gt;2.5&lt;/version&gt; &lt;configuration&gt; &lt;systemPropertyVariables&gt; &lt;log4j.rootLogger&gt;fatal,C&lt;/log4j.rootLogger&gt; &lt;log4j.category.OpenEJB&gt;warn&lt;/log4j.category.OpenEJB&gt; &lt;log4j.category.OpenEJB.options&gt;warn&lt;/log4j.category.OpenEJB.options&gt; &lt;log4j.category.OpenEJB.server&gt;warn&lt;/log4j.category.OpenEJB.server&gt; &lt;log4j.category.OpenEJB.startup&gt;warn&lt;/log4j.category.OpenEJB.startup&gt; &lt;log4j.category.OpenEJB.startup.service&gt;warn&lt;/log4j.category.OpenEJB.startup.service&gt; &lt;log4j.category.OpenEJB.startup.config&gt;warn&lt;/log4j.category.OpenEJB.startup.config&gt; &lt;log4j.category.OpenEJB.hsql&gt;warn&lt;/log4j.category.OpenEJB.hsql&gt; &lt;log4j.category.CORBA-Adapter&gt;warn&lt;/log4j.category.CORBA-Adapter&gt; &lt;log4j.category.Transaction&gt;warn&lt;/log4j.category.Transaction&gt; &lt;log4j.category.org.apache.activemq&gt;error&lt;/log4j.category.org.apache.activemq&gt; &lt;log4j.category.org.apache.geronimo&gt;error&lt;/log4j.category.org.apache.geronimo&gt; &lt;log4j.category.openjpa&gt;warn&lt;/log4j.category.openjpa&gt; &lt;log4j.appender.C&gt;org.apache.log4j.ConsoleAppender&lt;/log4j.appender.C&gt; &lt;log4j.appender.C.layout&gt;org.apache.log4j.SimpleLayout&lt;/log4j.appender.C.layout&gt; &lt;openejb.nobanner&gt;false&lt;/openejb.nobanner&gt; &lt;/systemPropertyVariables&gt; &lt;/configuration&gt; &lt;/plugin&gt; </code></pre> <h2>Option 4: any combination</h2> <p>Also note that all of the above techniques can be used at once, including any overrides you wish to put in individual test cases. The order of precedence is as follows:</p> <ol> <li>InitialContext properties</li> <li>jndi.properties in classpath</li> <li>system propertes (in this case, setup via surefire)</li> <li>embedded.logging.properties in classpath</li> </ol> <h2>Option 5: Request a feature</h2> <p>As always we are very happy to make things easier in any way we can. If you have a specific need or idea, we're happy to try and work it in or help you do it should you want to contribute.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload