logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Remko Popma (JIRA)" <j...@apache.org>
Subject [jira] [Created] (LOG4J2-232) Custom Converter plugin won't load.
Date Wed, 01 May 2013 23:32:15 GMT
Remko Popma created LOG4J2-232:

             Summary: Custom Converter plugin won't load.
                 Key: LOG4J2-232
                 URL: https://issues.apache.org/jira/browse/LOG4J2-232
             Project: Log4j 2
          Issue Type: Bug
    Affects Versions: 2.0-beta5
            Reporter: Remko Popma

From: John Smith <java.dev.mtl@gmail.com>
To: log4j-user@logging.apache.org 
Sent: Thursday, May 2, 2013 5:41 AM
Subject: Custom Converter plugin won't load.

Using log4j2-beta5

I'm writing a custom PatternConverter to mask logs for such things as
Credit Card and Card Security Code and some additional elements.

My converter looks like so....

package com.xxx.log4j.converters;

import java.util.List;
import java.util.regex.Pattern;

import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.layout.PatternLayout;
import org.apache.logging.log4j.core.pattern.ConverterKeys;
import org.apache.logging.log4j.core.pattern.LogEventPatternConverter;
import org.apache.logging.log4j.core.pattern.PatternFormatter;
import org.apache.logging.log4j.core.pattern.PatternParser;

@Plugin(name = "MaskConverter", type = "Converter")
@ConverterKeys({"ma", "mask" })
public class MaskConverter extends LogEventPatternConverter  {

private final List<PatternFormatter> formatters;
private final Pattern ccPattern;
private final Pattern cvnPattern;

public static final String CARD_PATTERN =
public static final String CARD_MASK = "$1$2********$4";
public static final String CVN_PATTERN = "(Cvn)([=\\^])([0-9]{3,4})";
public static final String CVN_MASK = "$1$2****";

    private MaskConverter(final List<PatternFormatter> formatters, final
Pattern ccPattern, final Pattern cvnPattern) {
        super("ma", "mask");


        this.formatters = formatters;
        this.ccPattern = ccPattern;
        this.cvnPattern = cvnPattern;

    public static MaskConverter newInstance(final Configuration config,
final String[] options) {


    if (options.length != 1) {
            LOGGER.error("Incorrect number of options on mask. Expected 1
received " + options.length);
            return null;

        final Pattern ccPattern = Pattern.compile(CARD_PATTERN,
        final Pattern cvnPattern = Pattern.compile(CVN_PATTERN,

        final PatternParser parser =
        final List<PatternFormatter> formatters = parser.parse(options[0]);
        return new MaskConverter(formatters, ccPattern, cvnPattern);

public void format(final LogEvent event, final StringBuilder toAppendTo) {

        System.out.println("Where..." + event.getMessage());
final StringBuilder buf = new StringBuilder();

for (final PatternFormatter formatter : formatters) {
            formatter.format(event, buf);


And my log4j2.xml looks like...

<?xml version="1.0" encoding="UTF-8"?>
<configuration status="TRACE" monitorInterval="5"
<FastFile name="FILE" fileName="C:/Temp/XXXJava/logs/vertx.log"
immediateFlush="false" append="false">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} -
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} -
<root level="DEBUG">
<appender-ref ref="Console"/>
<appender-ref ref="FILE"/>

But it doesn't seem to load the plugin I don't see any of my print
statements in the console and all I see is the word ask appended to my log

Have I missed something

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org

View raw message