Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure OpenEJB logging?

Tags:

java

openejb

How can I configure OpenEJB logging format? This is what what I see now in logs:

[...]
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.011 sec
Running com.XXX.FooTest
Apache OpenEJB 3.1.3    build: 20101015-05:42
http://openejb.apache.org/
INFO - openejb.home = /code/XXX
INFO - openejb.base = /code/XXX
INFO - Configuring Service(id=Default Security Serv...
[...]

I would like to disable INFO messages, and change formatting of others. Changes in log4j.properties have no effect.

like image 441
yegor256 Avatar asked Nov 14 '10 09:11

yegor256


1 Answers

Keep in mind that the overriding ability you get with the OpenEJB logger works with system properties as well as InitialContext properties.

The openejb.logger.external 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 no logging of any kind, not even ERROR, and no info on failed deployments. Even correct usage will still disable all options discussed below.

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.

Option 1: in code via InitialContext properties

In the test case itself via InitialContext properties

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);

Option 2: a jndi.properties file

File must be in the classpath at any path that evaluates to "/jndi.properties", so not "/META-INF/jndi.properties"

In Maven this can be done by placing the file at src/test/resources/jndi.properties

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

Here is a short video of the above option in action.

Note that finding and reading the jndi.properties file is a functionality of the java vm so if it doesn't work, it is more likely to be a configuration issue rather than a vm bug.

Option 3: Maven Surefire config

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>2.5</version>
  <configuration>
    <systemPropertyVariables>
      <log4j.rootLogger>fatal,C</log4j.rootLogger>
      <log4j.category.OpenEJB>warn</log4j.category.OpenEJB>
      <log4j.category.OpenEJB.options>warn</log4j.category.OpenEJB.options>
      <log4j.category.OpenEJB.server>warn</log4j.category.OpenEJB.server>
      <log4j.category.OpenEJB.startup>warn</log4j.category.OpenEJB.startup>
      <log4j.category.OpenEJB.startup.service>warn</log4j.category.OpenEJB.startup.service>
      <log4j.category.OpenEJB.startup.config>warn</log4j.category.OpenEJB.startup.config>
      <log4j.category.OpenEJB.hsql>warn</log4j.category.OpenEJB.hsql>
      <log4j.category.CORBA-Adapter>warn</log4j.category.CORBA-Adapter>
      <log4j.category.Transaction>warn</log4j.category.Transaction>
      <log4j.category.org.apache.activemq>error</log4j.category.org.apache.activemq>
      <log4j.category.org.apache.geronimo>error</log4j.category.org.apache.geronimo>
      <log4j.category.openjpa>warn</log4j.category.openjpa>
      <log4j.appender.C>org.apache.log4j.ConsoleAppender</log4j.appender.C>
      <log4j.appender.C.layout>org.apache.log4j.SimpleLayout</log4j.appender.C.layout>
      <openejb.nobanner>false</openejb.nobanner>
    </systemPropertyVariables>
  </configuration>
</plugin>

Option 4: any combination

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:

  1. InitialContext properties
  2. jndi.properties in classpath
  3. system propertes (in this case, setup via surefire)
  4. embedded.logging.properties in classpath

Option 5: Request a feature

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.

like image 183
David Blevins Avatar answered Oct 02 '22 04:10

David Blevins