@Test public void testAppenderActiveAfterGetTaskLogHome() throws Exception { String timeMillis = String.valueOf(System.currentTimeMillis()); String taskTypeId = "appendTaskTest".concat(timeMillis); String infoLogMsg = "info".concat(timeMillis); String errorLogMsg = "error".concat(timeMillis); Logger logger = LoggerFactory.getLogger(SeparateTaskLogTaskLogger.class); SeparateTaskLogTaskLogger taskLogger = new SeparateTaskLogTaskLogger(logger, createTaskInfo(taskTypeId)); logger.info("logger initialized"); logger.error("initialize error"); TaskLogHome.getTaskLogHome(); taskLogger.start(); logger.info(infoLogMsg); logger.error(errorLogMsg, new RuntimeException("runtimeException")); taskLogger.finish(); String logFileContents = getLogFileContents(taskTypeId); assertThat(logFileContents, StringContains.containsString("logger initialized")); assertThat(logFileContents, StringContains.containsString("initialize error")); assertThat(logFileContents, StringContains.containsString(infoLogMsg)); assertThat(logFileContents, StringContains.containsString(errorLogMsg)); assertThat(logFileContents, StringContains.containsString("runtimeException")); }
@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)) { 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; FileAppender<ILoggingEvent> tempFileAppender = (FileAppender<ILoggingEvent>) siftingAppender.getAppenderTracker() .getOrCreate("temp", 0L); File file = new File(tempFileAppender.getFile()); String taskLogsFolder = file.getParent(); tempFileAppender.stop(); FileUtils.deleteQuietly(file); return taskLogsFolder; }
TaskLogHome { @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)) { 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; FileAppender<ILoggingEvent> tempFileAppender = (FileAppender<ILoggingEvent>) siftingAppender.getAppenderTracker() .getOrCreate("temp", 0L); File file = new File(tempFileAppender.getFile()); String taskLogsFolder = file.getParent(); tempFileAppender.stop(); FileUtils.deleteQuietly(file); return taskLogsFolder; } }
TaskLogHome { @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)) { 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; FileAppender<ILoggingEvent> tempFileAppender = (FileAppender<ILoggingEvent>) siftingAppender.getAppenderTracker() .getOrCreate("temp", 0L); File file = new File(tempFileAppender.getFile()); String taskLogsFolder = file.getParent(); tempFileAppender.stop(); FileUtils.deleteQuietly(file); return taskLogsFolder; } private  TaskLogHome(); }
TaskLogHome { @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)) { 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; FileAppender<ILoggingEvent> tempFileAppender = (FileAppender<ILoggingEvent>) siftingAppender.getAppenderTracker() .getOrCreate("temp", 0L); File file = new File(tempFileAppender.getFile()); String taskLogsFolder = file.getParent(); tempFileAppender.stop(); FileUtils.deleteQuietly(file); return taskLogsFolder; } private  TaskLogHome(); @Nullable static String getTaskLogHome(); }
TaskLogHome { @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)) { 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; FileAppender<ILoggingEvent> tempFileAppender = (FileAppender<ILoggingEvent>) siftingAppender.getAppenderTracker() .getOrCreate("temp", 0L); File file = new File(tempFileAppender.getFile()); String taskLogsFolder = file.getParent(); tempFileAppender.stop(); FileUtils.deleteQuietly(file); return taskLogsFolder; } private  TaskLogHome(); @Nullable static String getTaskLogHome();  }