Working with the Log4J Logging sample
This sample demonstrates the TPTP support for logging Common Base Events using Apache Log4J logging APIs.
Users experience logging Common Base Events to the console and a Logging Agent.
If you have not already done so, create the example by File >
New > Example... >Logging > Apache Log4J Logging Sample.
The contents of the sample Java source code should be obtained from CVS
and stored in org.eclipse.tptp.platform.examples_<version>.jar with a path of archive\HyadesLoggingLog4JSample. The plugin.xml contents of org.eclipse.tptp.platform.examples_<version>.jar should be updated to include the relevant extension and extension
points from plugin.xml revision 1.3 in CVS.
The dependencies and configuration file necessary to log Common Base Events to a Apache Log4J logger are included.
Apache Log4J 1.2.8 (included) or above is required to compile and execute this sample.
Assumptions
- When launching this application from the Profiling and Logging Perspective of the workbench, the application launch configuration or the
Agent Controller application or service class path contains Apache Log4J 1.2.8 or above in the class path.
- The 'log4j.configuration' environment variable is set to the Apache Log4J logging configuration file's (HyadesLoggingLog4JSample.xml) absolute path and name in the form of a URL. For example, file:/<workspace>/HyadesLoggingLog4JProject/cfg/HyadesLoggingLog4JSample.xml.
- The Apache Log4J Document Type Definition (DTD) as defined in <Apache Log4J logging JAR>/org/apache/log4j/xml/log4j.dtd is copied to <workspace>/HyadesLoggingLog4JProject/cfg/ directory for use by the Apache Log4J logging configuration file (file:/<workspace>/HyadesLoggingLog4JProject/cfg/HyadesLoggingLog4JSample.xml).
To run this sample and automatically attach to the Logging Agent, follow these steps:
- Confirm that all compilation errors have been fixed.
- If you are using a standalone installation of the Agent Controller(AC), then make sure it is started (not required). Alternatively you can use Integrated Agent Controller which is included with the workbench.
- Open the Profiling and Logging Perspective (Window > Open Perspective > Other... > Profiling and Logging).
-
Run the sample class from the Profiling and Logging Perspective (Run > Profile... > Create a new launch configuration of
type Java Application > Set the project name to the example's project name > Set the Main class to 'HyadesLoggingLog4JSample'
> Switch to the Arguments tab and specify the following JVM property: -Dlog4j.configuration="file:/<workspace>/HyadesLoggingLog4JProject/cfg/HyadesLoggingLog4JSample.xml"
>Switch to the Monitor tab > De-select "Java
Profiling" and select "Agent Discoverer" > Profile).
- After a few seconds, the logging agent should automatically be detected and attached. Select the logging agent discovered and open the Log View in the Profiling and Logging Perspective to view the logged Common Base Event log records (Window > Show View > Other... > Profiling and Logging > Log View > OK).
- Refresh Log View in the Profiling and Logging Perspective (<right-click the 'HyadesLoggingLog4JSample' Logging Agent> > Refresh).
- One Log record should display in the Log view.
Alternatively, to run this sample and manually attach to the Logging Agent, follow these steps:
- Confirm that all compilation errors have been fixed.
- If you are using a standalone installation of the Agent Controller(AC), then make sure it is started (not required). Alternatively you can use Integrated Agent Controller which is included with the workbench.
-
Run the sample class from the Java Perspective (Run > Run... > Create a new launch configuration of type Java Application
> Main class > Search... > HyadesLoggingLog4JSample > OK >Switch to the Arguments tab and specify the following JVM property:
-Dlog4j.configuration="file:/<workspace>/HyadesLoggingLog4JProject/cfg/HyadesLoggingLog4JSample.xml" >
Run).
- Open the Profiling and Logging Perspective (Window > Open Perspective > Other... > Profiling and Logging).
- Attach to the 'HyadesLoggingLog4JSample' Logging Agent in the Profiling and Logging Perspective (Run > Profile... > Attach - Java Process > New > Hosts tab > Use 'localhost:<port>' if you are not using a standalone installation of the Agent Controller. Use a valid hostname and a port otherwise. > Agents tab > Double click the HyadesLoggingLog4JSample agent > Select the Destination tab > Profiling project > Browse... > 'HyadesLoggingLog4JProject' > OK > Profile).
- Start monitoring the 'HyadesLoggingLog4JSample' Logging Agent (<right-click the 'HyadesLoggingLog4JSample' Logging Agent> > Start Monitoring).
- Open the Log View in the Profiling and Logging Perspective to view the logged Common Base Event log records (Window > Show View > Other... > Profiling and Logging > Log View > OK).
- Refresh Log View in the Profiling and Logging Perspective (<right-click the 'HyadesLoggingLog4JSample' Logging Agent> > Refresh).
- One Log record should display in the Log view.
(C) Copyright IBM Corporation 2000, 2007.