In a previous post (Starting with ADF 11G Logging), I explained how ADF logging is simple to set up, and how it will enable you to set the logging levels at runtime, without having to restart any server. When I showed this to a colleague of mine, he immedialtely popped the question : “Can’t we use this for all of our java applications, even the ones that don’t use ADF?”. Well, the answer is yes, and it turns out to be very easy. Just add the correct jar to your project and your done.
This blog will demonstrate how to get this working. I use Eclipse Juno to create a small webproject, only containing a servlet that does the logging. In fact I will use the same servlet I used in the previous post.
So I open my Eclipse , and started with a File -> New -> Dynamic Web project. Give it a name, set ‘Dynamic web module version’ to 2.5, click the ‘Add project to an ear’ checkbox and click finish.
Now Eclipse has created a web and ear module for me.
Now right click the web project (ADFLogging), and select New -> Servlet, give it a name, eg. TestServlet, and click finish.
Remove the generated code in the servlet, and copy the code from the servlet ‘ExecuteLogger’ from my previous post (here) and paste it in our new serlvet.
PS. : When you copied the code from my previous blog, don’t forget to set ADFLogger.createADFLogger to our current servlet class name : TestServlet.class.
We will get compile errors on HttpServletRequest,etc… and on the ADFLogger class because they are not defined in the classpath of the project. So we’ll add them in order to get our servlet compiled. I get the 2 jar’s from a JDeveloper installation I did on my machine. We’ll only add these jar’s in order to get the servlet compiled in Eclipse. We will NOT deploy them, as they are already available on our Weblogic server.
To add the jar’s, right click on the web project, and go to Properties. In the Properties, click on ‘Java Build Path’.
Click on ‘Add External JARs…’ , and go to the directory where you installed your JDeveloper, which in my case is : C:\Oracle\Middleware.
In that directory , get following jar’s from the sub-directory :
\oracle_common\modules\javax.servlet_126.96.36.199_2-5.jar : contains the servlet classes like HttpServletRequest/Response,etc…
\oracle_common\modules\oracle.adf.share.ca_11.1.1\adf-share-base.jar : contains the ADFLogger classes.
Now we see the the following jar’s added :
Click OK and return to the servlet. In the servlet use CTRL-SHIFT-O to import the neccessary classes from the jar’s we just added.
Now all compile errors should be gone.
Generate the ear file as follow : File -> Export -> Ear file
Select the ear project and enter destination of the ear file
When you examine the ear, you will notice that the folder \WEB-INF\lib is empty.
As the servlet and ADFLogger jar is already available on Weblogic, there is no need to deploy it with our application.
Now deploy the ear to the Weblogic and test the servlet with following url. :
It will generate following output :
To check the logging done by this servlet :
As I used the integrated Weblogic of JDeveloper, I will look for my logs using JDeveloper, but in a production environment,
these logs can be viewed using the enterprise manager of Weblogic. For details, see my previous blog.
In the Oracle Diagnostics Logging configuration, I see my servlet after the deployment. No message level is defined, so it will take “Warning”, as this one is defined as default by the Root Logger
After te execution, I see following log lines in the log analyzer.
So that’s it. So the bottom line is to add the ADFLogger jar to your non-ADF project, and you are ready to go !