--- title: "How to Use log4j With Retrace" slug: "errors-and-logs-log4j" description: "Download and include Stackify's log4j12 project in your Java application. Configure the XML or properties file for logging, masking, and advanced features." updated: 2024-01-24T07:56:42Z published: 2024-01-24T07:56:42Z canonical: "docs.stackify.com/errors-and-logs-log4j" --- > ## Documentation Index > Fetch the complete documentation index at: https://docs.stackify.com/llms.txt > Use this file to discover all available pages before exploring further. # Configure Log4j ## Overview Retrace supports both Log4j 1.x and 2.x. You will find the instructions in the succeeding sections below on how to integrate logs from this logging framework into Retrace for both versions. Tip Stackify's packages for Log4j are open source and are available on GitHub: [Log4j 1.x](https://github.com/stackify/stackify-log-log4j12) and [Log4j 2.x](https://github.com/stackify/stackify-log-log4j2). ## Downloads and Includes Maven artifacts are available in the central Maven repository within a few hours after a new release. [https://search.maven.org/#search%7Cga%7C1%7CStackify](https://search.maven.org/#search%7Cga%7C1%7CStackify). The group id is com.stackify. ### v1.x The artifact id is stackify-log-log4j12. Substitute the version number you wish to use in the dependency snippet below. ``` com.stackify stackify-log-log4j12 INSERT_LATEST_MAVEN_CENTRAL_VERSION ``` ### v2.x The artifact id is stackify-log-log4j2. Substitute the version number you wish to use in the dependency snippet below. ``` com.stackify stackify-log-log4j2 INSERT_LATEST_MAVEN_CENTRAL_VERSION runtime javax.xml.bind jaxb-api INSERT_LATEST_MAVEN_CENTRAL_VERSION ``` ## Configuration ### v1.x Using the Properties file (e.g. log4j.properties): ``` log4j.appender.STACKIFY=com.stackify.log.log4j12.StackifyLogAppender log4j.appender.STACKIFY.apiKey=YOUR_ACTIVATION_KEY log4j.appender.STACKIFY.application=YOUR_APPLICATION_NAME log4j.appender.STACKIFY.environment=YOUR_ENVIRONMENT ... log4j.rootLogger=..., STACKIFY ``` Configuration via XML file (e.g. log4j.xml): ``` ... ... ``` ### v2.x Using the properties file (e.g. log4j2.properties): ``` packages=com.stackify.log.log4j2 # Stackify appender.stackifyLog.type=StackifyLog appender.stackifyLog.name=STACKIFY appender.stackifyLog.apiKey=YOUR_ACTIVATION_KEY appender.stackifyLog.application=YOUR_APPLICATION_NAME appender.stackifyLog.environment=YOUR_ENVIRONMENT ### # ...other appenders/options... ### rootLogger=DEBUG, STACKIFY ``` Configuration using XML (e.g. log4j2.xml): ``` ``` **Be sure to shut down Log4j to flush this appender** of any errors and shutdown the background thread: ``` LogManager.shutdown(); ``` ## Masking The Stackify appender has built-in data masking for credit cards and social security number values. ### Enable Masking: #### v1.x Add `<param name="maskEnabled" value="true"/>` inside the `<appender> ... </appender>` tag. #### v2.x Add `<MaskEnabled>true</MaskEnabled>` inside the `<StackifyLog> ... </StackifyLog>` tag. ### Customize Masking: The example below has the following customizations: 1. Credit Card value masking is disabled (`maskCreditCard=true`). 2. Social Security Numbers (`maskSSN=true`) 3. IP Address masking is enabled (`maskIP=true`). 4. Custom masking to remove vowels using a regex (`maskCustom=[aeiou]`). #### v1.x ``` log4j.appender.STACKIFY=com.stackify.log.log4j12.StackifyLogAppender log4j.appender.STACKIFY.apiKey=YOUR_API_KEY log4j.appender.STACKIFY.application=YOUR_APPLICATION_NAME log4j.appender.STACKIFY.environment=YOUR_ENVIRONMENT log4j.appender.STACKIFY.maskEnabled=true # Option to mask credit card numbers log4j.appender.STACKIFY.maskCreditCard=true # Mask social security numbers log4j.appender.STACKIFY.maskSSN=true # Enable masking of IPs log4j.appender.STACKIFY.maskIP=true # Custom masking by using a regular expression to remove vowels log4j.appender.STACKIFY.maskCustom=[aeiou] ``` ``` ``` #### v2.x ``` # ... Base Stackify appender configuration... # Credit Card appender.stackifyLog.mask_cc.type=Mask appender.stackifyLog.mask_cc.value=CREDITCARD appender.stackifyLog.mask_cc.enabled=true # Social Security Number appender.stackifyLog.mask_ssn.type=Mask appender.stackifyLog.mask_ssn.value=SSN appender.stackifyLog.mask_ssn.enabled=true # IP appender.stackifyLog.mask_ip.type=Mask appender.stackifyLog.mask_ip.value=IP appender.stackifyLog.mask_ip.enabled=true # Custom - aeiou appender.stackifyLog.mask_custom.type=Mask appender.stackifyLog.mask_custom.value=[aeiou] appender.stackifyLog.mask_custom.enabled=true ``` ``` true CREDITCARD SSN IP [aeiou] ``` ## Sending Logs Through a Proxy If you are wanting to send your logs into Stackify through a proxy, you will want to set the 'https.proxyHost' and 'https.proxyPort' system properties. If both of these properties are set in your app, your logs go through the proxy specified. ## Advanced Features: MDC, and NDC If you're utilizing MDC (Mapped Diagnostic Context) or NDC (Nested Diagnostic Context), Stackify will automatically pick up and report any data you add via MDC/NDC. This information will be available to you under the Custom Properties heading in the error details screen within Retrace.