Search in sources :

Example 1 with LogFileInfo

use of com.bwssystems.logservices.LogFileInfo in project ha-bridge by bwssytems.

the class LoggingUtil method getLogFileInfos.

/**
 * Get the logfile information for the roor logger.
 *
 * @return List of LogFileInfo obejcts
 */
public static List<LogFileInfo> getLogFileInfos() {
    final LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    final List<LogFileInfo> logFileInfos = new ArrayList<LogFileInfo>();
    final Logger logger = lc.getLogger(Logger.ROOT_LOGGER_NAME);
    final Iterator<Appender<ILoggingEvent>> it = logger.iteratorForAppenders();
    while (it.hasNext()) {
        final Appender<ILoggingEvent> appender = it.next();
        if (appender instanceof FileAppender) {
            final FileAppender<ILoggingEvent> fileAppender = (FileAppender<ILoggingEvent>) appender;
            final File logFile = new File(fileAppender.getFile());
            final LogFileInfo logFileInfo = new LogFileInfo();
            logFileInfo.setFileName(logFile.getName());
            logFileInfo.setFileLastChanged(new Date(logFile.lastModified()));
            logFileInfo.setFileSize(logFile.length());
            logFileInfos.add(logFileInfo);
        }
    }
    return logFileInfos;
}
Also used : FileAppender(ch.qos.logback.core.FileAppender) Appender(ch.qos.logback.core.Appender) FileAppender(ch.qos.logback.core.FileAppender) ArrayList(java.util.ArrayList) Logger(ch.qos.logback.classic.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggerContext(ch.qos.logback.classic.LoggerContext) LogFileInfo(com.bwssystems.logservices.LogFileInfo) Date(java.util.Date) File(java.io.File)

Aggregations

Logger (ch.qos.logback.classic.Logger)1 LoggerContext (ch.qos.logback.classic.LoggerContext)1 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)1 Appender (ch.qos.logback.core.Appender)1 FileAppender (ch.qos.logback.core.FileAppender)1 LogFileInfo (com.bwssystems.logservices.LogFileInfo)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1