The goal:  to configure log4j2 logging on a standalone EJB deployed to a JBoss 
EAP7 server in an EJB jar.  We do not wish to use the loggers supplied by JBoss 
for our applications.  I find that I can deploy a log4j2.xml file at the root 
of the ejb jar and it does get seen by JBoss but logging still isn't happening.

Referring to https://logging.apache.org/log4j/2.0/manual/extending.html, I see 
a glimmer of hope that this may provide a solution.  The LoggerContextFactory 
and ContextSelector sections seem to provide a possibility.  My approach is to 
create my own logging factory extending 
org.apache.logging.log4j.core.impl.Log4jContextFactory.  This makes a 
Log4jContextFactory that uses the JndiContextSelector and I will add envEntries 
to my EJB configuration to define the Jndi context.

public class EjbJarLoggingContextFactory extends Log4jContextFactory {
        public EjbJarLoggingContextFactory() {
                super(new 
org.apache.logging.log4j.core.selector.JndiContextSelector());
        }
}

Now how to tell log4j about this?  The LoggerContextFactory of the document is 
a bit vague, perhaps even contradictory:

The LoggerContextFactory binds the Log4j API to its implementation. The Log4j 
LogManager locates a LoggerContextFactory by locating all instances of 
META-INF/log4j-provider.properties, a standard java.util.Properties file, and 
then inspecting each to verify that it specifies a value for the 
Log4jAPIVersion property that conforms to the version required by the 
LogManager. If more than one valid implementation is located the value for 
FactoryPriority will be used to identify the factory with the highest priority. 
Finally, the value of the LoggerContextFactory property will be used to locate 
the LoggerContextFactory. In Log4j 2 this is provided by Log4jContextFactory.

Applications may change the LoggerContextFactory that will be used by

    1. Implementing a new LoggerContextFactory and creating a 
log4j-provider.properties to reference it making sure that it has the highest 
priority.
    2 . Create a new log4j-provider.xml and configure it with the desired 
LoggerContextFactory making sure that it has the highest priority.
    3. Setting the system property log4j2.loggerContextFactory to the name of 
the LoggerContextFactory class to use.
    4. Setting the property "log4j2.loggerContextFactory" in a properties file 
named "log4j2.LogManager.properties" to the name of the LoggerContextFactory 
class to use. The properties file must be on the classpath.

First we are told that it locates all instances of 
META-INF/log4j-provider.properties.  But then it goes on to list four possible 
ways to change this.  I settled on #4, created a log4j2LogManager.properties 
file defining the log4j2.loggerContextFactory property to point at my Factory 
class.

It doesn't work.  No logging occurs.  In the jboss logs I see no sign that my 
properties file has been consulted, and nothing happens.

So I have these questions:

1.  Does the introductory test about META-INF/log4j-provider.properties 
contradict the four methods suggested below.  If not, what am I not 
understanding?
2.  Is there a worked example somewhere of setting up such a configuration that 
I can consult?
3.  Is there a better way to achieve the goal I am trying to achieve - get 
logging to work in a standalone EJB?

Thanks.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to