extend debug(character) with debug(longchar) openedge

Viewed 70

I need to log messages that will possibly exceed the 32k character limit. How can I extend the LogWriter with a debug(character) or what would be the best way to use the Logging Framework to log messages that are greater than 32k characters

1 Answers

There is a way, but it takes a bit of code.

The first step is to use the debug(LogMessage, ...) method, rather than debug(character, ...) method.

You will need to build the LogMessage but can't use its public properties (since they are also character. So you will need to use the LogMessage's AddContext method. This takes a character for the key and a Progress.Lang.Object as the value. You can use an instance of OpenEdge.Core.String, which holds longchar values.

using OpenEdge.Logging.*.
using OpenEdge.Core.*.

define variable logger as ILogWriter no-undo.
define variable logMsg as LogMessage no-undo.

logger = LoggerBuilder:GetLogger('something').

// do stuff

define variable longcharWithLotsOfData as longchar no-undo.

logMsg = new LogMessage(logger:Name, 'short message').
logMsg:AddContext('long-message', new String(longcharWithLotsOfData)).

logger:debug(logMsg).

You will probably also need to add your own filter to read this message from that context, and write it into the logfile. You can see an example of how to create one here .

You'll need to write to a 'named file' rather than the LOG-MANAGER since the WRITE-MESSAGE() method only takes a character for the message.

The writer will need to output the String object's Value property; ToString() returns a character. The filter will need to check the type of the object returned from the GetContext() method, and cast it to get the value.

You will need to use the COPY-LOB... APPEND statement to write the longchar value to the output file.

There are basically 3 steps

  1. Create a class that implements ILoggerFilter
  2. Add the filter definition to the filter property in logging.config
  3. Add the filter to your logger(s) in logging.config
Related