Writng a Java class for the static adapter

In creating a static log parser, the extractor, parser and formatter components of the adapter configuration file are replaced with a Java class. The static parser class should implement the interface org.eclipse.hyades.logging.parser.IParser. This can be done by extending one of the abstract classes org.eclipse.hyades.logging.parser.Parser or org.eclipse.hyades.logging.parser.MonitoringParser.

Extending the Parser class

This class should be used when you are creating a static parser to parse log files that are no longer being updated or to parse a log file once during the execution of the context. If this class is used, the Context Instance must be configured with the Continuous operation check box not selected.

  1. Add an import statement import org.eclipse.hyades.logging.parsers.Parser;.
  2. Add the following methods to the class:

Note: The protected method Parser.readALine() can be used to read data from the log file. This method reads a line from the log file and it will throw an exception if an error occurs when it is reading the file. The exception will contain information about why the read failed. The existing readLine() method which returns null if an error occurs has been deprecated in this release.

Extending the MonitoringParser class

This class should be used when you need to create a static parser that can continuously monitor a log file. Note: This class will allow a log file to be monitored even if the log file does not exist at the time that monitoring is started. The abstract class org.eclipse.hyades.logging.parser.MonitoringParser must be extended. This class extends the Parser class. Implement the methods as described for the Parser class but note the following:

  1. Add an import statement import org.eclipse.hyades.logging.parser.MonitoringParser.
  2. If the following Parser methods are overridden, ensure that the corresponding methods of the super class are called by the overriding methods:
  3. Add a call to setEndOfFile() in the parseNext() method before it returns null to indicate that there are currently no more parsed records to return. This will ensure that the next time readALine() is called, the log file will be examined to determine if the file has changed and has new records to parse
  4. If the static parser requires a command to convert the log file to a format more easily parsed or to generate the log file, it must be specified to the MonitoringParser class using one of the following methods calls after setConfiguration() is called: setConverterCommand(String) or setConverterCommand(String[]).
    If the command writes the log data to a file with a name different that that specified in the configuration parameters in setConfiguration(), the new log file name must be specified to the MonitoringParser class using the setFilename(String) method.

Note:

  1. org.eclipse.hyades.logging.parsers plug-in now has a dependency on org.eclipse.hyades.logging.adapter plug-in.
  2. The MonitoringParser class provides no direct access to the log file except for the readALine() method. Static parsers that currently use the logFile member of Parser class to directly read data from the log file should be modified to use the readALine() method.

Once you have written and tested your Java parser class, you can configure the sensor component of the adapter configuration file to refer to this class. .

Related Concepts
Overview of the Hyades Generic Log Adapter
Common Base Event format specification

Related tasks
Creating a log parser
Creating a static adapter
Configuring the sensor component

Related references
Adapter Configuration File structure
Adapter Configuration Editor
Regular expression grammar