Working with the Hyades Log4J Logging Sample

Introduction

This sample demonstrates the Hyades support for logging Common Base Events using Apache Log4J logging APIs. Users experience logging Common Base Events to the console and a Logging Agent. The Logging Agent may be monitored via the Hyades Data Collection Engine application or service and the Hyades workbench.


Contents

The contents of the sample include the Java source code, dependencies and configuration file necessary to log Common Base Events to a Apache Log4J logger.


Requirements

  1. Apache Log4J 1.2.8 (included) or above is required to compile and execute this sample.

Assumptions
  1. When either launching this application from the Profiling and Logging Perspective of the workbench or attaching to a Logging Agent using the workbench, the Hyades Data Collection Engine application or service is configured and running.
  2. When launching this application from the Profiling and Logging Perspective of the workbench, the application launch configuration or the Hyades Data Collection Engine application or service classpath contains Apache Log4J 1.2.8 or above in the classpath.
  3. The 'log4j.configuration' environment variable is set to the Apache Log4J logging's configuration file's (HyadesLoggingLog4JSample.xml) absolute path and name in the form of a URL. For example, file:/<workspace>/HyadesLoggingLog4JProject/cfg/HyadesLoggingLog4JSample.xml.
  4. <workspace> represents the absolute path to the workbench's workspace.

Dependencies

The JAR files that are listed in the table are required to execute this sample:

JAR file Plug-in it is contained in Reason for requirement
hexr.jar org.eclipse.hyades.execution.remote Hyades Logging Agent
hlcore.jar org.eclipse.hyades.logging.core Common Base Event's Hyades Logging Core dependency
hlcbe101.jar org.eclipse.hyades.logging.core Common Base Event implementation
hllog4j.jar org.eclipse.hyades.logging.log4j Hyades support for Apache Log4J logging APIs
ecore.jar org.eclipse.emf.ecore Common Base Event's Eclipse Modeling Framework (EMF) dependency
common.jar org.eclipse.emf.common Common Base Event's Eclipse Modeling Framework (EMF) dependency
log4j-1.2.8.jar org.apache.jakarta_log4j_logging Apache Log4J logging APIs


Execution Steps

To run this sample and manually attach to the Logging Agent, follow these steps:
  1. Confirm that all compilation errors have been fixed.
  2. Start the Hyades Data Collection Engine application or service.
  3. Enable logging in the Profiling and Logging preferences (Window > Preferences... > Profiling and Logging > Enable logging > OK).
  4. Run the sample class from the Java Perspective (Run > Run... > Java Application > New... > Main class > Search... > HyadesLoggingLog4JSample > OK > Arguments > VM arguments > '-Dlog4j.configuration=file:/<workspace>/HyadesLoggingLog4JProject/cfg/HyadesLoggingLog4JSample.xml' > Run), where <workspace> represents the absolute path to the workbench's workspace.
  5. Open the Profiling and Logging Perspective (Window > Open Perspective > Other... > Profiling and Logging).
  6. Attach to the 'HyadesLoggingLog4JSample' Logging Agent in the Profiling and Logging Perspective (Run > Profile... > Attach - Java Process > New > Agents > HyadesLoggingLog4JSample > Profiling > Destination > Profiling project > Browse... > 'HyadesLoggingLog4JProject' > OK > Run).
  7. Start monitoring the 'HyadesLoggingLog4JSample' Logging Agent (<right-click the 'HyadesLoggingLog4JSample' Logging Agent> > Start Monitoring).
  8. 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).
  9. Refresh Log View in the Profiling and Logging Perspective (<right-click the 'HyadesLoggingLog4JSample' Logging Agent> > Refresh).
Alternatively, to run this sample and automatically attach to the Logging Agent, follow these steps:
  1. Confirm that all compilation errors have been fixed.
  2. Start the Hyades Data Collection Engine application or service.
  3. Enable logging in the Profiling and Logging preferences (Window > Preferences... > Profiling and Logging > Enable logging > OK).
  4. Add the 'HyadesLoggingLog4JSample' Logging Agent to the Profiling and Logging preferences (Window > Preferences... > Profiling and Logging > Logging Agents > New agent > HyadesLoggingLog4JSample > Add agent > OK).
  5. Open the Profiling and Logging Perspective (Window > Open Perspective > Other... > Profiling and Logging).
  6. Run the sample class from the Profiling and Logging Perspective (Run > Profile... > Java Application > New... > Main class > Search... > HyadesLoggingLog4JSample > OK > Arguments > VM arguments > '-Dlog4j.configuration=file:/<workspace>/HyadesLoggingLog4JProject/cfg/HyadesLoggingLog4JSample.xml' > Run), where <workspace> represents the absolute path to the workbench's workspace.
  7. 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).
  8. Refresh Log View in the Profiling and Logging Perspective (<right-click the 'HyadesLoggingLog4JSample' Logging Agent> > Refresh).