logginglog4japache-tomeeopenejb

OpenEJB Logger configuration when running tests from TestNG in Intellij IDEA


I have a problem configuring the logs output when running tests from IntelliJ.

Every change I make does not seem to have an effect.

I run the test using @Module annotation via ApplicationComposer.

    @Listeners(ApplicationComposerListener.class)
    public class TestLogs {

        private static final Logger LOGGER = Logger.getInstance(LogCategory.OPENEJB, TestLogs.class);

        @Module
        @Classes(cdi=true,value = {
        })
        public EjbModule ejbModule() throws Exception {
            EjbModule ejbModule = new EjbModule(new EjbJar());
            System.setProperty("openejb.home", "../../../build/ejbhome");
            System.setProperty("openejb.deployments.classpath.include",".*(my_app).*");
            System.setProperty("ejb.jndi.name.app", getClass().getSimpleName());
            System.setProperty("ejb.jndi.name.module", ejbModule.getModuleId());
            System.setProperty("log4j.category.OpenEJB","off");
            return ejbModule;
        }


        @Test
        public void testLog_LoggingIsOff() {
            LOGGER.info("*********************************************************");
        }
    }

When I run the test, the log line with wildcards gets printed in the console, though I set up configuration that should have turned the logs off for OpenEJB category.


EDIT

The solution that did work:

  1. Provide the following settings In the VM options on the JDK settings tab in the Debug/Run configuration (and not in the @JvmParams annotation, as it is loaded after the JuliLogStreamFactory)

    -Djava.util.logging.config.file=path\to\\file.logging.properties
    
  2. Provide the relevant file handlers in the config file

    handlers = org.apache.openejb.log.FileHandler, java.util.logging.ConsoleHandler
    .level = INFO
    
    org.apache.openejb.log.FileHandler.level = FINE
    org.apache.openejb.log.FileHandler.directory = logs
    org.apache.openejb.log.FileHandler.prefix = my_tests_log.
    org.apache.openejb.log.FileHandler.formatter = java.util.logging.SimpleFormatter
    
    
    java.util.logging.ConsoleHandler.level = SEVERE
    java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
    
    java.util.logging.SimpleFormatter.format = %1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS.%1$tL %4$s [location: %2$s] %5$s%6$s%n
    

Not working stuff:

Ways I tried to turn off the logging:

  1. System.setProperty("log4j.category.OpenEJB","off");
  2. All convolutions of upper/lower case in the previous statement
  3. Setting Environment variables in IntelliJ Run/Debug configurations
  4. Putting the following file embedded.logging.properties to ../../../build/ejbhome:

    log4j.rootLogger           = fatal,C
    log4j.category.OpenEJB         = off
    log4j.category.OpenEJB.server      = info
    log4j.category.OpenEJB.startup     = info
    log4j.category.OpenEJB.startup.service = warn
    log4j.category.OpenEJB.startup.config = info
    log4j.category.OpenEJB.hsql    = info
    log4j.category.CORBA-Adapter       = info
    log4j.category.Transaction     = warn
    log4j.category.org.apache.activemq = error
    log4j.category.org.apache.geronimo = error
    log4j.category.openjpa         = error
    
    log4j.appender.C           = org.apache.log4j.ConsoleAppender
    log4j.appender.C.layout        = org.apache.log4j.SimpleLayout
    
  5. Putting the same file with the name log4j.embedded.logging.properties to ../../../build/ejbhome

  6. Putting the same file with the name jndi.properties to ../../../build/ejbhome
  7. Putting these 3 files to the module dir/conf
  8. Setting IntelliJ classpath to the directory above with Project Structure -> Dependencies

Neither way has any effect on the line output.


Solution

  • OpenEJB uses JUL by default and therefore you just need to configure JUL as on any JVM setting java.util.logging.config.file on the JVM and using JUL syntax and not log4j one (by default log4j is not in the classpath).

    Alternative is to add in app composer properties (@Configuration):

    openejb.jul.forceReload=true
    # custom handler impl
    openejb.jul.consoleHandlerClazz = com.company.MyHandler
    # then jul properties, see org.apache.openejb.util.JuliLogStreamFactory.OpenEJBLogManager for advanced usage