用 debug(longchar) openedge 扩展 debug(character)

extend debug(character) with debug(longchar) openedge

我需要记录可能超过 32k 字符限制的消息。如何使用调试(字符)扩展 LogWriter 或者使用日志记录框架记录大于 32k 字符的消息的最佳方式是什么

有办法,但需要一些代码。

第一步是使用debug(LogMessage, ...)方法,而不是debug(character, ...)方法。

您将需要构建 LogMessage 但不能使用其 public 属性(因为它们也是 character。因此您将需要使用 LogMessageAddContext 方法。这需要一个字符作为键和一个 Progress.Lang.Object 作为值。您可以使用 OpenEdge.Core.String 的实例,它保存 longchar 值。

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).

您可能还需要添加自己的过滤器以从该上下文中读取此消息,并将其写入日志文件。您可以查看如何创建 here .

的示例

您需要写入 'named file' 而不是 LOG-MANAGER,因为 WRITE-MESSAGE() 方法只需要一个字符作为消息。

作者需要输出String对象的Value属性; ToString() returns一个字符。过滤器将需要检查从 GetContext() 方法返回的对象的类型,并将其强制转换以获取值。

您需要使用 COPY-LOB... APPEND 语句将 longchar 值写入输出文件。

基本上有3个步骤

  1. 创建一个实现 ILoggerFilter
  2. 的 class
  3. 将过滤器定义添加到 filter 属性 in logging.config
  4. 将过滤器添加到 logging.config
  5. 中的记录器