Skip to content

How do I pass an array (or Set) of Classes as appender's property from log4j2.xml configuration to custom appender class? #2024

Answered by yvasyliev
yvasyliev asked this question in Q&A
Discussion options

You must be logged in to vote

After some tries, I found solution that solves my task.

  1. IgnoredException.java
    @Plugin(name = "IgnoredException", category = Core.CATEGORY_NAME, elementType = Appender.ELEMENT_TYPE)
    public class IgnoredException {
        private final Class<? extends Throwable> exceptionClass;
    
        public IgnoredException(Class<? extends Throwable> exceptionClass) {
            this.exceptionClass = exceptionClass;
        }
    
        @PluginFactory
        public static IgnoredException createAppender(@PluginValue("value") String name) throws ClassNotFoundException {
            System.out.println("IgnoredException");
            return new IgnoredException(Class.forName(name).asSubclass(Throwable.class));
        }
    
        public Class<? e…

Replies: 3 comments 5 replies

Comment options

vy
Dec 1, 2023
Collaborator

You must be logged in to vote
1 reply
@yvasyliev
Comment options

Comment options

jvz
Dec 1, 2023
Collaborator

You must be logged in to vote
2 replies
@yvasyliev
Comment options

@jvz
Comment options

jvz Dec 1, 2023
Collaborator

Comment options

You must be logged in to vote
2 replies
@jvz
Comment options

jvz Dec 1, 2023
Collaborator

@yvasyliev
Comment options

Answer selected by yvasyliev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants