【问题标题】:Override Hysterix Logging覆盖 Hysterix 日志记录
【发布时间】:2022-01-13 09:41:58
【问题描述】:

我正在尝试了解SpringBoot在实施Hysterix Circuit Breaker之前和之后生成的日志

在 Hystrix 之前,日志看起来像,

17:31:35.977 [http-nio-8080-exec-2] [TransID:bcc8a9e9-41b7-47c8-9eb1-0f8becb42f68] INFO  c.f.e.common.logging.MethodLogging - Entered Class: class com.org.myapp.service.MyService, Method: getData, Arguments: 123456

实施 Hystrix 后的日志如下所示,

17:21:23.197 [hystrix-MyController-1] [TransID:] INFO  c.f.e.common.logging.MethodLogging - Entered Class: class com.org.myapp.service.MyService, Method: getData, Arguments: 123456

那么,http-nio-8080-exec-2 是如何被 hystrix-OrchestratorController-1 替换的,以及为什么在实施 Hystrix 时它没有显示我的 TransactionId。 Hystrix 是如何接管日志的?两者有什么区别?有什么办法可以恢复到我的旧日志格式? 我在 application.properties 中尝试了hystrix.command.default.requestLog.enabled=false,但没有运气。

主类

@SpringBootApplication
@EnableCircuitBreaker
class MyApp{
}

休息控制器

@GetMapping("...")
@HystrixCommand(commandKey="data")
public Object getData(){
}

application.properties

hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=5000

【问题讨论】:

  • Hystrix 使用线程池来做超时,因此不同的线程。不确定应该在您的日志中提供什么 transid,但这可能存储在一些本地线程中并被检索,而不是使用 MDC。

标签: java spring spring-boot logging hystrix


【解决方案1】:

Hystrix 使用自己的线程而不是本地线程。这就是您的日志看起来不同的原因。

在你的 application.properties 中添加这个属性

hystrix.command.default.execution.isolation.strategy=SEMAPHORE

现在 hystrix 将使用您的本地线程。

【讨论】:

    猜你喜欢
    • 2012-01-12
    • 2014-03-17
    • 2022-01-27
    • 2021-05-17
    • 1970-01-01
    • 1970-01-01
    • 2012-06-01
    • 2014-04-17
    • 2016-04-27
    相关资源
    最近更新 更多