Book Image

Oracle JDeveloper 11gR2 Cookbook

By : Nick Haralabidis
Book Image

Oracle JDeveloper 11gR2 Cookbook

By: Nick Haralabidis

Overview of this book

Oracle's Application Development Framework (ADF) for Fusion Web Applications leverages Java EE best practices and proven design patterns to simplify constructing complex web solutions with JDeveloper, and this hands-on, task-based cookbook enables you to realize those complex, enterprise-scale applications. With the help of real-world implementations, practical recipes cover everything from design and construction, to deployment, testing, debugging and optimization. This practical, task-based cookbook takes you, the ADF developer, on a practical journey for building Fusion Web Applications. By implementing a range of real world use cases, you will gain invaluable and applicable knowledge for utilizing the ADF framework with JDeveloper 11gR2. "Oracle JDeveloper 11gR2 Cookbook"ù is a task-based guide to the complete lifecycle of Fusion Web Application development using Oracle JDeveloper 11gR2 and ADF.You will get quickly up and running with concepts like setting up Application Workspaces and Projects, before delving into specific Business Components such as Entity Objects, View Objects, Application Modules and more. Along the way you will encounter even more practical recipes about ADF Faces UI components and Backing Beans, and the book rounds off by covering security, session timeouts and exceptions.With "Oracle JDeveloper 11gR2 Cookbook"ù in hand you will be equipped with the practical knowledge of a range of ready to use implementation cases which can be applied to your own Fusion Web ADF Applications.
Table of Contents (19 chapters)
Oracle JDeveloper 11gR2 Cookbook
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface

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