Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

appender can't be added to AsyncAppender after being detached. #725

Open
wsliliang opened this issue Nov 2, 2023 · 0 comments · May be fixed by #727
Open

appender can't be added to AsyncAppender after being detached. #725

wsliliang opened this issue Nov 2, 2023 · 0 comments · May be fixed by #727

Comments

@wsliliang
Copy link

1. behavior

appender can't be added to AsyncAppender after being detached.

2. reproduce and test case

add following test in AsyncAppenderBaseTest

    @Test
    @Timeout(value=2, unit = TimeUnit.SECONDS)
    public void appenderShouldBeAddedSuccessfullyAfterDetachedByReference() {
        asyncAppenderBase.addAppender(listAppender);
        asyncAppenderBase.start();
        asyncAppenderBase.doAppend(0);
        asyncAppenderBase.detachAppender(listAppender);
        asyncAppenderBase.addAppender(listAppender);
        asyncAppenderBase.doAppend(0);
        asyncAppenderBase.stop();
        verify(listAppender, 2);
    }

3. cause

the value of property "appenderCount" does't decrease in method "detachAppender", the value is 1 after first addAppender, and still 1 after detachAppender, so when addAppender again, it goes into "else".

  public void addAppender(Appender<E> newAppender) {
        if (appenderCount == 0) {
            appenderCount++;
            addInfo("Attaching appender named [" + newAppender.getName() + "] to AsyncAppender.");
            aai.addAppender(newAppender);
        } else {
            addWarn("One and only one appender may be attached to AsyncAppender.");
            addWarn("Ignoring additional appender named [" + newAppender.getName() + "]");
        }
    }
wsliliang added a commit to wsliliang/logback that referenced this issue Nov 2, 2023
wsliliang added a commit to wsliliang/logback that referenced this issue Nov 2, 2023
Signed-off-by: liliang <[email protected]>
@wsliliang wsliliang linked a pull request Nov 2, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant