001package apps.util; 002 003import java.io.File; 004import java.util.*; 005 006import jmri.util.problemreport.LogProblemReportProvider; 007 008import org.apache.logging.log4j.LogManager; 009import org.apache.logging.log4j.core.Appender; 010import org.apache.logging.log4j.core.appender.FileAppender; 011import org.apache.logging.log4j.core.Logger; // not org.apache.logging.log4j.Logger 012 013import org.openide.util.lookup.ServiceProvider; 014 015/** 016 * Provide Log4J information in the problem report. 017 * 018 * @author Randall Wood Copyright 2020 019 */ 020@ServiceProvider(service = LogProblemReportProvider.class) 021public class Log4JProblemReportProvider implements LogProblemReportProvider { 022 023 @Override 024 public File[] getFiles() { 025 ArrayList<File> list = new ArrayList<>(); 026 // search for an appender that stores a file 027 Map<String,Appender> appenderMap = ((Logger) LogManager.getLogger()).getAppenders(); 028 appenderMap.forEach((key, a) -> { 029 if (a instanceof FileAppender) { 030 FileAppender f = (FileAppender) a; 031 log.debug("find file: {}", f.getFileName()); 032 list.add(new File(f.getFileName())); 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}