001package apps.util;
002
003import java.io.File;
004import java.util.ArrayList;
005import java.util.Enumeration;
006
007import jmri.util.problemreport.LogProblemReportProvider;
008
009import org.apache.log4j.*;
010import org.openide.util.lookup.ServiceProvider;
011
012/**
013 * Provide Log4J information in the problem report.
014 *
015 * @author Randall Wood Copyright 2020
016 */
017@ServiceProvider(service = LogProblemReportProvider.class)
018public class Log4JProblemReportProvider implements LogProblemReportProvider {
019
020    @Override
021    public File[] getFiles() {
022        ArrayList<File> list = new ArrayList<>();
023        // search for an appender that stores a file
024        for (Enumeration<?> en = Logger.getRootLogger().getAllAppenders(); en.hasMoreElements();) {
025            // does this have a file?
026            Object a = en.nextElement();
027            // see if it's one of the ones we know
028            log.debug("check appender {}", a);
029            if (a instanceof FileAppender) {
030                FileAppender f = (FileAppender) a;
031                log.debug("find file: {}", f.getFile());
032                list.add(new File(f.getFile()));
033            }
034        }
035        return list.toArray(new File[list.size()]);
036    }
037
038    private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(Log4JProblemReportProvider.class);
039}