Create a custom filter with additional properties
- Last Updated: February 19, 2024
- 4 minute read
- OpenEdge
- Version 12.8
- Documentation
logging.config file:- Create a custom filter class.
- Create a custom filter builder.
- Register the filter class and filter builder.
toLang—the language that the message is to be translated in.serviceURI—the URI of the REST service that performs the translation.apiKey—an API key required by the translation service.
Create a custom filter class
The first step is to create the custom filter class and have it implement theILoggerFilter interface. The ABL code
that executes the filter's operations must be put inside the interface's ExecuteFilter() method. This step needs to be performed for
all custom filters, regardless of whether the filter requires additional properties. In the following example, the filter class (TranslatedMessageFormat) contains three properties—the translation
service URI, the api key, and the language to translate the message to. These
properties are used in the ExecuteFilter() method,
along with the log message, to build an HTTP request that is sent to the translation
service. The actual values for these properties are to be obtained from
configurations in the logging.config
file.
|
Create a custom filter builder
The properties defined in the custom filter class need to be bound to properties in the logging.config file. To do this, you need to create a custom filter builder that inherits theOpenEdge.Logging.Filter.LogFilterBuilder class and override
its NewFilter() method. The method must return an
ILoggerFilter object.In this
example, a JsonObject variable named options is used to map the properties defined in the
custom filter class (To, ApiKey, TranslationService), with
logger properties (toLang, apiKey, serviceURI) that will be used
in a logging configuration in the logging.config file.
|
Register the filter class and filter builder
Finally, register the custom filter class and builder. There are two ways to do this:- In the logging.config file (recommended)
- In an ABL procedure
Register the filter class and builder in the logging.config file (recommended)
filter object after the logger object. Inside the filter object, specify a name for the custom filter and define two
properties type and—builder. Set the filter class name as the value for type and the builder class name as the value for
builder.
|
Register the filter class and builder in an ABL procedure
To register a custom filter and builder in an ABL procedure, use theOpenEdge.Logging.LoggerFilterRegistry class as shown in this example:
|
Example: Using the custom filter with additional properties
After the custom filter and the custom filter builder have been registered, you can use the filter and specify its properties in the logging.config file as shown in this example:
|
logger:Info("Customer found."), the translated log output would be
"Client retrouvé.".