MDC application configuration for LOG4J2

Source: Internet
Author: User

The MDC concept:manufacturing Data Collection real-time acquisition and analysis. sometimes the actual development process does not find the bug in the production environment, need to go to the production environment to analyze the real-time log for bug tracking; LOG4J2 provides MDC functionality to output specific users ' logs to a specific file in a separate process.
config keyword threadcontext,dynamicthresholdfilter ,threadcontextmapfilter
1.dynamicthresholdfilter controls the log default output level as a whole and can adjust the log level for specific values <!--threadcontext.put ("LoginId", "User1"); Other than User1, the log is the error level by default, and the USER1 related log is the debug level--
<dynamicthresholdfilter key= "LoginId" defaultthreshold= "ERROR" onmatch= "ACCEPT" onmismatch= "DENY" > < KeyValuePair key= "User1" value= "DEBUG"/> </DynamicThresholdFilter>
2.Threadcontextmapfilter The record contents of the control file, record to the file according to the condition, and all others refuse to write the log <!--I only record USER1 log information, to find production environment bugs. --<file name= "Testuserlog" filename= "Target/testuserlog2" append= "true" > <threadcontextmapfilter onMat Ch= "ACCEPT" onmismatch= "DENY" > <keyvaluepair key= "loginId" value= "User1"/> &LT;/THREADCONTEXTMAPFILTER&G   T <patternlayout pattern= "%n%t%-5p%c{2} mdc%x-%m"/> </File>
3. In the Web application, you can add the following code to the filter filters:threadcontext.put ("LoginId", Session.getattribute ("userid"));//UserID represents the work number information of the login session In the case of an app, you can use the proxy mode (if you use spring, you can work with AOP, if you don't have spring, you can use Cglib or other) to implement
code engineering based on MAVEN, resources: Http://note.youdao.com/share/?id=75707f4ae039b0d1e2f2cf46c8342d34&type=note

MDC application configuration for LOG4J2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.