【问题标题】:Is there any way to suppress attribute a isn't defined error in stringTemplate?有什么方法可以抑制 stringTemplate 中未定义属性的错误?
【发布时间】:2016-12-08 10:00:34
【问题描述】:

在设置模板时,如果属性键未设置到 ST 对象中,则会引发错误:

         context [anonymous] 11:27 attribute  isn't defined

有什么方法可以抑制此错误或标记以不在日志中显示错误。我正在使用 log4j 记录我的日志已归档 attribute is not defined 错误我该怎么办从日志中删除它?

【问题讨论】:

    标签: java log4j stringtemplate stringtemplate-4


    【解决方案1】:

    您可以编写自己的STErrorListener 或使用ErrorBuffer 来捕获错误,然后遍历错误消息并根据其类型决定是否要将其写入日志。

    【讨论】:

    • 谢谢。我觉得这需要一个 STGroup (stGroup.errMgr=...) ,对于 ST 直接来说,我还没有找到添加 errorListener 的方法,很遗憾
    • 更新:即使使用 ST,也可以添加 ErrorHandler。只需用一个指向错误处理程序的组构造 ST - C'est tout! :)
    • new ErrorManager(new STErrorListener() { @Override public void runTimeError(STMessage msg) { if (msg.error == ErrorType.NO_SUCH_ATTRIBUTE) ... }; ... }
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-27
    • 2019-05-17
    • 1970-01-01
    • 1970-01-01
    • 2018-09-23
    • 2018-11-12
    • 1970-01-01
    相关资源
    最近更新 更多