Spring 如何使用模式布局log4j2将数据放入日志中

Spring 如何使用模式布局log4j2将数据放入日志中,spring,spring-boot,log4j2,pattern-layout,Spring,Spring Boot,Log4j2,Pattern Layout,我正在log4j2spring.xml中定义log4j2配置。在本文中,我将图案布局定义如下: <Property name="LOG_PATTERN" value="%d [%thread] [%-5level] [Content-Id:%X{CID}] [SessionId:%X{sessionId}] [CustomerId:%X{customerId}] [%c{1.}] - %msg%n" /> 现在我想把数据动态地

我正在log4j2spring.xml中定义log4j2配置。在本文中,我将图案布局定义如下:

        <Property name="LOG_PATTERN" value="%d [%thread] [%-5level] 
               [Content-Id:%X{CID}] [SessionId:%X{sessionId}] 
 [CustomerId:%X{customerId}] [%c{1.}] - %msg%n" />

现在我想把数据动态地放在客户ID中,但我不知道怎么做

非常感谢您的帮助。

如您在中所读,请将customerId放入
线程上下文中

ThreadContext.put("customerId", <your customerID>); 
ThreadContext.put(“customerId”);

占位符将被log4j2取代,这很好,如果我把它放在控制器中,它会工作得很好吗