Create a custom filter
- Last Updated: February 19, 2024
- 2 minute read
- OpenEdge
- Version 12.8
- Documentation
If the built-in filters do not meet your requirements, you can extend the OpenEdge Logger framework by writing your own custom filter.
Overview of steps to create a custom filter
Follow these steps to create a custom filter:- Create an ABL class that implements the
ILoggerFilterinterface. - Register the filter using the
LoggerFilterRegistry.
Note: If the custom filter requires
additional properties to be set in the logging.config file, you need to perform additional steps. See Create a custom filter with additional properties.
Implement the ILoggerFilter interface
Create an ABL class that
implements the OpenEdge.Logging.Filter.ILoggerFilter
interface. This interface provides a method named ExecuteFilter() that takes a LogEvent
object as an input parameter. Override this method and write your
custom filter code inside it. Typically, you will want to manipulate the
To learn more about properties of the LogEvent object's properties. In the following example,
the custom filter code retrieves the log message from the LogEvent object's Message property
and reverses the order of the words in the message:
|
LogEvent object, see Log events.Register the custom filter
After writing the custom filter class, you need to register it by associating a filter name with the filter class. You can then use the filter name in the"filters": [...] array in the logging.config file, just like you do with any other
filter. There are two ways to register a filter:
- In the logging.config file (recommended)
- In an ABL procedure
Register the custom filter in the logging.config file (recommended)
To register a custom
filter in the logging.config file, add a
filter object after the
logger object as shown in this
example:
|
Register the custom filter in an ABL procedure
To register a custom filter in an ABL procedure, use theOpenEdge.Logging.LoggerFilterRegistry class as
shown in this example:
|
Example: Using the custom filter
Building on the previous examples, here is how you would use the custom filter using the filter name (reversed_words_filter in our example) in a logging.config file:
|
logger:Info("Customer found."), the formatted log output would be "found. Customer".