栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Log4j2的RoutingAppender的通配符模式

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Log4j2的RoutingAppender的通配符模式

感谢链接Remko,我找到了一个临时解决方案,直到Log4j2的人员对该功能进行了改进。该解决方案同时使用RoutingAppender和Filters。这是我的log4j2配置的样子(我定义了属性,但未在此处显示):

<appenders>    <appender name="applicationAppender" type="RollingFile" fileName="${logFileName}" filePattern="${logFileNamePattern}" bufferedIO="true" immediateFlush="true" append="true">        <layout type="PatternLayout" pattern="${logPattern}" />        <Policies> <TimebasedTriggeringPolicy /> <SizebasedTriggeringPolicy size="${logFileSize}" />        </Policies>        <DefaultRolloverStrategy max="${logFileCount}" />    </appender>    <Routing name="contextSpecificAppender">        <Routes pattern="$${ctx:contextId}"> <Route>     <appender name="Rolling-${ctx:contextId}" type="RollingFile" fileName="logs/${ctx:contextId}.log" filePattern="${logFileNamePattern}" bufferedIO="true" immediateFlush="true" append="true">         <layout type="PatternLayout" pattern="${logPattern}" />         <Policies>  <TimebasedTriggeringPolicy />  <SizebasedTriggeringPolicy size="${logFileSize}" />         </Policies>         <DefaultRolloverStrategy max="${logFileCount}" />     </appender> </Route>        </Routes>    </Routing></appenders><loggers>    <root level="info">        <appender-ref ref="contextSpecificAppender"> <ThreadContextMapFilter onMatch="DENY" onMismatch="ACCEPT">     <KeyValuePair key="contextId" value="" /> </ThreadContextMapFilter>        </appender-ref>        <appender-ref ref="applicationAppender"> <ThreadContextMapFilter onMatch="ACCEPT" onMismatch="DENY">     <KeyValuePair key="contextId" value="" /> </ThreadContextMapFilter>        </appender-ref>    </root></loggers>

我要做的是根据要记录的追加程序调用ThreadContext.put(“ contextId”,“”)或ThreadContext.put(“
contextId”,“ something”)。我希望可以迅速实现荒野功能,但与此同时,此解决方案对我来说已经足够。

谢谢!



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/570075.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号