- 1 Minute to read
- Print
- DarkLight
- PDF
Configure log4j
- 1 Minute to read
- Print
- DarkLight
- PDF
Downloads and Includes
The stackify-log-log4j12 project is open source and hosted on GitHub here. 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 The group id is com.stackify. The artifact id is stackify-log-log4j12. Substitute the version number you wish to use in the dependency snippet below.
<dependency>
<groupId>com.stackify</groupId>
<artifactId>stackify-log-log4j12</artifactId>
<version>INSERT_LATEST_MAVEN_CENTRAL_VERSION</version>
</dependency>
Configuration
Configuration via Properties file:
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:
<appender name="STACKIFY" class="com.stackify.log.log4j12.StackifyLogAppender">
<param name="apiKey" value="YOUR_ACTIVATION_KEY"/>
<param name="application" value="YOUR_APPLICATION_NAME"/>
<param name="environment" value="YOUR_ENVIRONMENT"/>
</appender>
...
<root>
...
<appender-ref ref="STACKIFY" />
</root>
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:
Add <param name="maskEnabled" value="true"/>
inside the <appender> ... </appender>
tag.
Customize Masking:
The example below has the following customizations:
- Credit Card value masking is disabled (
<param name="maskCreditCard" value="false"/>
) - IP Address masking is enabled (
<param name="maskIP" value="true"/>
). - Custom masking to remove vowels using a regex (
<param name="maskCustom" value="[aeiou]"/>
)
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
log4j.appender.STACKIFY.maskCreditCard=false
log4j.appender.STACKIFY.maskSSN=true
log4j.appender.STACKIFY.maskIP=true
log4j.appender.STACKIFY.maskCustom=[aeiou]
<appender name="STACKIFY" class="com.stackify.log.log4j12.StackifyLogAppender">
<param name="apiKey" value="YOUR_API_KEY"/>
<param name="application" value="YOUR_APPLICATION_NAME"/>
<param name="environment" value="YOUR_ENVIRONMENT"/>
<param name="maskEnabled" value="true"/>
<param name="maskCreditCard" value="false"/>
<param name="maskSSN" value="true"/>
<param name="maskIP" value="true"/>
<param name="maskCustom" value="[aeiou]"/>
</appender>
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.
Are you using log4j2?
If you are utilizing log4j2, the stackify-log-log4j2 project is open source and hosted on GitHub [here].