Dear,
I am trying to enable logback logging separation (see
http://logback.qos.ch/manual/loggingSeparation.html).
I need to create a logback/context-name resource in JNDI.
I need this environment variable ear scoped (other ears should have
different values for this resource), so I included in my
application.xml, the content:
<env-entry>
<description>The context name of the logger</description>
<env-entry-name>logback/context-name</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>app1</env-entry-value>
</env-entry>
I am testing if the JNDI resource is available from a listener
included in a war inside my ear:
public class InitListener implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent ce) {
// ch.qos.logback.classic.selector.ContextJNDISelector a;
//
// ch.qos.logback.classic.selector.servlet.ContextDetachingSCL b;
String loggerContextName = null;
try {
Context ctx = JNDIUtil.getInitialContext();
loggerContextName = JNDIUtil.lookup(ctx, JNDI_CONTEXT_NAME);
} catch (NamingException ne) {
System.out.println("WARN: Failed to access the JNDI Server while
search for JNDI resource [" + JNDI_CONTEXT_NAME + "].");
}
if (loggerContextName != null) {
ContextSelector selector =
ContextSelectorStaticBinder.getSingleton().getContextSelector();
LoggerContext context = selector.getLoggerContext(loggerContextName);
if (context != null) {
System.out.println("Context named " + loggerContextName + " was found.");
} else {
System.out.println("WARN: No context named " + loggerContextName +
" was found.");
}
} else {
System.out
.println("WARN: Failed to get JNDI resource ["
+ JNDI_CONTEXT_NAME
+ "]. It should exists and define the name of the logger
context. See
http://logback.qos.ch/manual/loggingSeparation.html for
more details.");
}
}
@Override
public void contextDestroyed(ServletContextEvent ce) {
// do nothing
}
In server.log I can see the message:
WARN: Failed to get JNDI resource
[java:comp/env/logback/context-name]. It should exists and define the
name of the logger context. See
http://logback.qos.ch/manual/loggingSeparation.html for more
details.|#]
What am I missing?
Br,
Orair.