logback icon indicating copy to clipboard operation
logback copied to clipboard

asyncAppender cannot refer to itself

Open Jazzylol opened this issue 4 years ago • 1 comments

When users configure appender, they often copy the existing configuration directly. Because the user is careless, the asynchronous appender often configures to point to itself, resulting in hang when the request thread writes the log, so the system cannot provide services. We hope that the wrong configuration can be ignored when adding appender, so as to improve the stability of logback.

config below:

image

test code:

public class TestLogbackHang {

public static void main(String[] args) throws Exception {
    load();
    Logger logger = LoggerFactory.getLogger("testLogger");

    for (int i = 0; i < 100; i++) {
        logger.info("back " + i);
    }

}

public static void load() throws IOException, JoranException {
    LoggerContext lc = (LoggerContext)LoggerFactory.getILoggerFactory();
    File externalConfigFile = new File("logback.xml");
    if (!externalConfigFile.exists()) {
        throw new IOException("Logback External Config File Parameter does not reference a file that exists");
    } else {
        if (!externalConfigFile.isFile()) {
            throw new IOException("Logback External Config File Parameter exists, but does not reference a file");
        } else {
            if (!externalConfigFile.canRead()) {
                throw new IOException("Logback External Config File exists and is a file, but cannot be read.");
            } else {
                JoranConfigurator configurator = new JoranConfigurator();
                configurator.setContext(lc);
                lc.reset();
                configurator.doConfigure("logback.xml");
                StatusPrinter.printInCaseOfErrorsOrWarnings(lc);
            }
        }
    }
}

}

process: image

Jazzylol avatar Nov 21 '20 15:11 Jazzylol

@ceki Can you assess the reasonableness of this requirement ?

Jazzylol avatar Nov 24 '20 03:11 Jazzylol