【问题标题】:How can you set the logger (log category / log name) in Camel's onException clause?如何在 Camel 的 onException 子句中设置记录器(日志类别/日志名称)?
【发布时间】:2014-10-15 05:39:16
【问题描述】:

我有以下路线:

            onException(Exception.class)
                .logExhausted(true)
                .logStackTrace(true)
                .logExhaustedMessageHistory(true)
                .process(new MyErrorProcessor());

            from(uri)
            .process(new MyProcessor());

发生错误时,日志会打印在 org.apache.camel.processor.DefaultErrorHandler 日志类别中。有没有办法将其更改为自定义日志类别? .errorHandler() 允许您设置日志类别,但 .onException() 似乎不允许。

谢谢。

【问题讨论】:

    标签: logging apache-camel onexception


    【解决方案1】:

    你可以试试

    .onException(Exception.class)
                .to("log:logger_name?level=ERROR&multiline=true&showCaughtException=true&showStackTrace=true")
    ...
    

    【讨论】:

    • 这不是我真正想要的。我需要 onException 的默认 errorHandler 执行的所有日志记录才能转到我的记录器。意思是,重试日志、重试耗尽、消息历史记录等。与 errorHandler 完成的方式相同。
    【解决方案2】:

    你可以试试这样的:

    onException(Exception.class)
                    .handled(true)
                    .log(LoggingLevel.ERROR, this.getClass().getSimpleName(),
                            "${exception.stacktrace} ${messageHistory(false)}");
    

    您还可以在此处查找更多变量: https://camel.apache.org/manual/latest/simple-language.html

    【讨论】:

      【解决方案3】:

      默认情况下,路由 ID 用作记录器类别。因此,将路由 ID 设置为类名,然后您可以按照通常的方式配置日志记录:

      from(uri)
          .id(this.getClass().getName())
          .process(new MyProcessor());
      

      id 在 Camel 2 中可能已被命名为 routeId;以上适用于 Camel 3)。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-03-23
        • 2016-11-27
        • 2010-12-17
        • 1970-01-01
        • 1970-01-01
        • 2023-03-24
        • 1970-01-01
        • 2012-03-12
        相关资源
        最近更新 更多