Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Oracle JDeveloper 11gR2 Cookbook

You're reading from   Oracle JDeveloper 11gR2 Cookbook Using JDeveloper to build ADF applications is a lot more straightforward when you learn through practical recipes. This book has over 85 of them to take you beyond the basics and raise your knowledge to a new level.

Arrow left icon
Product type Paperback
Published in Jan 2012
Publisher Packt
ISBN-13 9781849684767
Length 406 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Nick Haralabidis Nick Haralabidis
Author Profile Icon Nick Haralabidis
Nick Haralabidis
Arrow right icon
View More author details
Toc

Table of Contents (19) Chapters Close

Oracle JDeveloper 11gR2 Cookbook
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
1. Preface
1. Prerequisites to Success: ADF Project Setup and Foundations FREE CHAPTER 2. Dealing with Basics: Entity Objects 3. A Different Point of View: View Object Techniques 4. Important Contributors: List of Values, Bind Variables, View Criteria 5. Putting them all together: Application Modules 6. Go with the Flow: Task Flows 7. Face Value: ADF Faces, JSF Pages, and User Interface Components 8. Backing not Baking: Bean Recipes 9. Handling Security, Session Timeouts, Exceptions, and Errors 10. Deploying ADF Applications 11. Refactoring, Debugging, Profiling, and Testing 12. Optimizing, Fine-tuning, and Monitoring

Setting up logging


Logging is one of those areas that is often neglected during the initial phases of application design. There are a number of logging framework choices to use in your application, such as log4j by Apache. In this recipe, we will demonstrate the usage of the ADFLogger and Oracle Diagnostics Logging (ODL). The main advantage of using ODL when compared to other logging frameworks is its tight integration with WebLogic and JDeveloper. In WebLogic, the logs produced conform to and integrate with the diagnostics logging facility. Diagnostic logs include, in addition to the message logged, additional information such as the session and user that produced the log entry at run-time. This is essential when analyzing the application logs. In JDeveloper, the log configuration and analysis is integrated via the Oracle Diagnostics Logging Configuration and Oracle Diagnostics Log Analyzer respectively.

Getting ready

We will be adding logging to the application module framework extension class that we developed in the previous recipe.

How to do it…

  1. 1. ODL logs can be generated programmatically from within your code by using the ADFLogger class. Instantiate an ADFLogger via the static createADFLogger() method and use its log() method. Go ahead and add logging support to the application module framework extension class we developed in the previous recipe, as shown in the following code snippet:

    import oracle.adf.share.logging.ADFLogger;
    public class ExtApplicationModuleImpl extends ApplicationModuleImpl {
    // create an ADFLogger
    private static final ADFLogger LOGGER = ADFLogger.createADFLogger(ExtApplicationModuleImpl.class);
    public ExtApplicationModuleImpl() {
    super();
    // log a trace
    LOGGER.log(ADFLogger.TRACE, "ExtApplicationModuleImpl was constructed");
    }
    }
    

    Note

    Downloading the example code

    You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

  2. 2. The next step involves the configuration of the logger in the logging.xml file. The file is located in the config\fmwconfig\servers directory under the WebLogic domain for the server you are configuring. For the integrated WebLogic server, this file is located in the %JDEV_USER_DIR%\system11.1.2.1.38.60.81\DefaultDomain\config\fmwconfig\servers\DefaultServer directory. The exact location can vary slightly depending on the version of JDeveloper that you use.

    Open the file in JDeveloper and create a custom logger called com.packt by clicking on the Add Persistent Logger icon, as shown in the following screenshot:

  3. 3. This will display the Add Persistent Logger dialog to add your logger. Enter com.packt for the Logger Name and choose FINEST for the Logger Level.

  4. 4. Repeat this step and add another logger named com if one does not already exist for it. The final result should look similar to the following screenshot:

  5. 5. One more step that is required to complete the configuration is to use the -Djbo.debugoutput=adflogger and -Djbo.adflogger.level=FINEST options when starting the JVM. You can do this in JDeveloper by double-clicking on the main application's ViewController project to bring up the Project Properties dialog and selecting the Run/Debug/Profile node.

  6. 6. Then select the appropriate Run Configuration on the right and click on the Edit… button.

  7. 7. On the Edit Run Configuration dialog that is displayed, enter these Java options in the Java Options.

How it works…

In this example, we have declared a static ADFLogger and associated it with the class ExtApplicationModuleImpl by passing ExtApplicationModuleImpl.class as a parameter during its construction. We have declared the ADFLogger as static so we don't have to worry about passivating it. We then use its log() method to do our logging. The log() method accepts a java.util.logging.Level parameter indicating the log level of the message and it can be any of the following values: ADFLogger.INTERNAL_ERROR, ADFLogger.ERROR, ADFLogger.WARNING, ADFLogger.NOTIFICATION, or ADFLogger.TRACE.

ADFLogger leverages the Java Logging API to provide logging functionality. Because standard Java logging is used, it can be configured through the logging.xml configuration file. This file is located under the WebLogic domain directory config\fmwconfig\servers for the specific server that you are configuring. The file is opened and a logger is added.

Logging is controlled at the package level; we have added a logger for the com.packt package but we can fine-tune it for the additional levels: com.packt.jdeveloper, com.packt.jdeveloper.cookbook, com.packt.jdeveloper.cookbook.shared, and so on. The class name that we passed as an argument to the ADFLogger during its instantiation—that is, ExtApplicationModuleImpl.class—represents a logger that is defined in the logging configuration file. The logger that is added is a persistent logger, which means that it will remain permanently in the logging.xml configuration file. Transient loggers are also available; these persist only for the duration of the user session.

Each logger configured in the logging.xml is associated with a log handler. There are a number of handlers defined in the logging.xml namely a console-handler to handle logging to the console, an odl_handler to handle logging for ODL and others.

There's more…

Note

You can also use the ADFLogger methods severe(), warning(), info(), config(), fine(), finer(), and finest() to do your logging.

When you configure logging, ensure that you make the changes to the appropriate logging.xml file for the WebLogic server you are configuring.

See also

  • Breaking up the application in multiple workspaces, in this chapter

  • Configuring diagnostics logging, Chapter 11,Refactoring, Debugging,Profiling, Testing

  • Dynamically configure ADF trace logs on WebLogic, Chapter 11,Refactoring, Debugging,Profiling, Testing

You have been reading a chapter from
Oracle JDeveloper 11gR2 Cookbook
Published in: Jan 2012
Publisher: Packt
ISBN-13: 9781849684767
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime