I am trying to solve an issue related to logging from an outbound resource adapter.
It runs on Weblogic 12.2.1.2, and has been written following the Oracle J2EE guide.
I have setup the logging descriptor as per the Oracle documentation, and when I deploy it weblogic creates a new empty log file in the location I have provided by the descriptor (as expected).
I have deeply followed the guide Writing Messages to the WebLogic Server Log. I tried with java.util.logging, the NonCatalogLogger by the mock JAR and slf4j so, all the log messages are printed to the console and into the domain log file, but NOT into the log file I have configured.
Could anybody tell me why?
Thank you so much!
Unfortunately I cannot make weblogic working, so I had to find an alternative.
Here is my solution based on Logback.
pom.xml
<properties>
<logback.version>1.2.3</logback.version> <!-- Depends on slf4j 1.7.25, conflicting with Weblogic 12.2.1.2 -->
<slf4j.version>1.7.5</slf4j.version> <!-- Shipped with Weblogic 12.2.1.2 -->
<adapter.config.file>/etc/logback-my-resource-adapter.xml</adapter.config.file>
</properties>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>${logback.version}</version>
</dependency>
</dependencies>
LoggerHelper.java
package it.sisal.betting.sdg.adapter.sogei.logging;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.util.ContextInitializer;
import org.slf4j.ILoggerFactory;
public class LoggerHelper {
static {
// https://logback.qos.ch/manual/configuration.html
System.setProperty(ContextInitializer.CONFIG_FILE_PROPERTY, "${adapter.config.file}");
}
public static final ILoggerFactory FACTORY = StaticLoggerBinderHack
.getSingleton()
.getLoggerFactory()
;
public static LoggerContext CONTEXT = (LoggerContext)FACTORY;
}
MyResourceAdapter.java
public class MyResourceAdapter implements ResourceAdapter, Serializable {
private static final Logger logger = LoggerHelper
.FACTORY
.getLogger(MyResourceAdapter.class)
;
private BootstrapContext context = null;
@Override
public void start(BootstrapContext context)
throws ResourceAdapterInternalException
{
if (logger.isInfoEnabled()) {
logger.info("start(...)");
}
this.context = context;
}
// And so on...
}