Java Code Examples for ch.qos.logback.core.FileAppender#getFile()
The following examples show how to use
ch.qos.logback.core.FileAppender#getFile() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LogUtils.java From konduit-serving with Apache License 2.0 | 5 votes |
/** * Gets the file where the logs are. * @return the logs file. */ public static File getEndpointLogsFile() { Logger rootLogger = (Logger) LoggerFactory.getLogger(ROOT_LOGGER); FileAppender<ILoggingEvent> fileAppender = (FileAppender<ILoggingEvent>) rootLogger.getAppender("FILE"); if(fileAppender != null) { return new File(fileAppender.getFile()); } else { return null; } }
Example 2
Source File: TaskLogHome.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
/** * Get the home (absolute path) of the task logs on disk * * @return the task log home, null if it couldn't be found (usually due to missing appender in logback.xml) */ @Nullable public static String getTaskLogHome() { LoggerContext loggerContext = (LoggerContext) StaticLoggerBinder.getSingleton().getLoggerFactory(); Appender<ILoggingEvent> appender = loggerContext.getLogger(ROOT_LOGGER_NAME).getAppender("tasklogfile"); if (!(appender instanceof SiftingAppender)) { // We are forgiving if the task log appender does not exist. It could be that a user had a customized logback.xml // as of 3.4.1 when task logging was introduced. We don't want to block application start in this scenario. log.error("Could not find a Logback SiftingAppender named 'tasklogfile' in the logback configuration. " + "Please check that the 'tasklogfile' appender exists in logback.xml"); return null; } SiftingAppender siftingAppender = (SiftingAppender) appender; // this will create a new appender which ultimately creates a temp.log within the tasks log folder FileAppender<ILoggingEvent> tempFileAppender = (FileAppender<ILoggingEvent>) siftingAppender.getAppenderTracker() .getOrCreate("temp", 0L); // Note that at full execution speed the temp.log may not actually exist yet, but we don't actually need it to File file = new File(tempFileAppender.getFile()); String taskLogsFolder = file.getParent(); // no need to keep the temp.log file around tempFileAppender.stop(); // stop the appender to release file lock (windows) FileUtils.deleteQuietly(file); return taskLogsFolder; }
Example 3
Source File: LoggingUtil.java From ha-bridge with Apache License 2.0 | 3 votes |
/** * 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; }
Example 4
Source File: LoggingUtil.java From ha-bridge with Apache License 2.0 | 3 votes |
/** * Get the log file. * * @param logFileName The name of the log file * @return The actual file */ public static File getLogFile(final String logFileName) { if (logFileName == null) { throw new IllegalArgumentException("logFileName cannot be null."); } final LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); 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()); if (logFile.getName().equalsIgnoreCase(logFileName)) { return logFile; } } } return null; }