How to define custom log4j2 logging class?

Viewed 17

I want a custom format of my loggings, so I implemented the following class:

public class LoggingLayout extends AbstractStringLayout {

    public LoggingLayout() {
        super(StandardCharsets.UTF_8);
    }



    @Override
    public String toSerializable(LogEvent event) {
        // Create formatted string here...
    }
}

But I can not get the configuration working. This is it so far:

<Configuration strict="true" xmlns="http://logging.apache.org/log4j/2.0/config"
           packages="com.path.to.loggingDir">

<Appenders>
    <Appender type="Console" name="STDOUT">
        <Layout type="LoggingLayout" />
    </Appender>
</Appenders>

<Loggers>
    <Root level="info">
        <AppenderRef ref="STDOUT" />
    </Root>
</Loggers>

I defined the package which contains the custom LoggingLayout, but even with that I get the error:

main ERROR Console contains an invalid element or attribute "LoggingLayout"

Why is that?

EDIT: Please notice, that I am using STRICT xml. All other answers I saw so far are not using strict xml, so this question is not a duplicate.

0 Answers
Related