简体   繁体   中英

How to write OCI JAVA SDK logs into Weblogic Server log files

Here I am using Weblogic 12c Server to deploy my web application. In my application I'm using OCI JAVA SDK to interact with Oracle Cloud Infrastructure(OCI) Service. As per the documentation by OCI, "OCI JAVA SDK" is using SLF4J logging. So that I've bundled "slf4j-jdk14-1.7.23.jar" JAR file in my ear file. Still I was not able to see the OCI SDK generated logs in the weblogic log files.

I've added the below entries in weblogic-application.xml as well:

<prefer-application-packages>
    <package-name>org.slf4j.*</package-name>
</prefer-application-packages>


<!-- if not using prefer-application-resources you will get a warning like this: -->
<!-- Class path contains multiple SLF4J bindings -->
<!-- SLF4J: Found binding in [jar:file:/C:/wls1211/modules/org.slf4j.jdk14_1.6.1.0.jar!/org/slf4j/impl/StaticLoggerBinder.class] -->
<prefer-application-resources>
    <resource-name>org/slf4j/impl/StaticLoggerBinder.class</resource-name>
</prefer-application-resources>

After adding the above entries, "StaticLoggerBinder" class not found errors are resolved. But still not able to see the SDK generated log statements in weblogic log files.

Am I missing any specific configuration ?

Unfortunately, I don't have any experience with Weblogic, but I tried configuring "JDK14"-style logging from the command line, hoping that it will help you.

As an example, I'm using PaginationExample.java , which is in the examples directory of the oci-java-sdk.zip file that you can download from the releases page .

I have unpacked the oci-java-sdk.zip file, changed into the examples directory and compiled the PaginationExample.java file:

cd oci-java-sdk/examples
javac -cp "../lib/oci-java-sdk-full-1.2.38.jar:../third-party/lib/*" PaginationExample.java

Now I have a PaginationExample.class file in the current directory.

I also downloaded the slf4j-1.7.23.zip file and unpacked it. For me, the JDK logging bridge file is ../../slf4j-1.7.23/slf4j-jdk14-1.7.23.jar .

I can now write a logging.properties file to configure JDK14 logging, eg:

handlers = java.util.logging.FileHandler, java.util.logging.ConsoleHandler
.level = FINE
java.util.logging.ConsoleHandler.level = FINE
java.util.logging.FileHandler.level = FINE
java.util.logging.FileHandler.pattern = java%u.log
java.util.logging.FileHandler.limit = 50000
java.util.logging.FileHandler.count = 1
java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter
java.util.logging.SimpleFormatter.format=%4$s [%1$tc]: %5$s%n

Now I can run the example using:

java -Djava.util.logging.config.file=logging.properties -cp ../lib/oci-java-sdk-full-1.2.38.jar:../third-party/lib/*:../../slf4j-1.7.23/slf4j-jdk14-1.7.23.jar:. PaginationExample <tenancy ocid>

With the above logging.properties file, output, down to the FINE level (which is DEBUG in slf4j terminology) goes both to console and to a file.

This works on the command line. It sounds like WebLogic is using the JDK14 java.util.logging framework, and we need to get slf4j to feed into that. You're already doing what was recommended here .

Since the above configuration works for console and file, I'm wondering if the [server logging bridge]( https://docs.oracle.com/middleware/1212/wls/WLLOG/logging_services.htm#WLLOG200 ) isn't configured correctly.

This page seems to describe how to do that: http://buttso.blogspot.com/2011/06/using-slf4j-with-weblogic-server.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM