/** * 获取文件路径 * @return */ @Override public String getFile() { LogHelper.info("", "日志地址开始:" + super.fileName, "LogbackRollingFileAppender"); String path = Platform.getServerPath(); return path+super.getFile(); }
private static final String LOG4J_ROLLING_FILE_NAME_TOKEN = "Launcher"; /* * Change the name of the the log file as configured through log4j.xml * by replacing the placeholder file name token ("Launcher") with the * a new "actionName". */ private static void log4jConfig(String actionName) { org.apache.log4j.Logger rootLogger = LogManager.getRootLogger(); RollingFileAppender fileAppender = (RollingFileAppender)rootLogger.getAppender("fileAppender"); // <param name="FileNamePattern" value="/var/log/Launcher.log.%d{yyyy-MM-dd}.gz"/> String currentLogFile = fileAppender.getFile(); String newLogPattern = currentLogFile.replace(LOG4J_ROLLING_FILE_NAME_TOKEN, actionName); fileAppender.setFile(newLogPattern); TimeBasedRollingPolicy timeBasedRollingPolicy = (TimeBasedRollingPolicy) fileAppender.getRollingPolicy(); String fileNamePattern = timeBasedRollingPolicy.getFileNamePattern(); String newFileNamePattern = fileNamePattern.replace(LOG4J_ROLLING_FILE_NAME_TOKEN, actionName);; timeBasedRollingPolicy.setFileNamePattern(newFileNamePattern); timeBasedRollingPolicy.activateOptions(); fileAppender.activateOptions(); LOG.info(" Redirected launcher log output to log pattern: " + newFileNamePattern); }
PatternLayoutEncoder encoder = (PatternLayoutEncoder) rollingApp.getEncoder(); app.setEncoderPattern(encoder.getPattern()); app.setFileName(rollingApp.getFile()); if (rollingApp.getRollingPolicy() instanceof FixedWindowRollingPolicy) { FixedWindowRollingPolicy rollingPolicy = (FixedWindowRollingPolicy) rollingApp
private void doRestart(String testId, String patternPart, boolean fileOptionIsSet, int waitDuration) { // change the timestamp of the currently actively file File activeFile = new File(rfa1.getFile()); activeFile.setLastModified(currentTime); incCurrentTime(waitDuration); String filePatternStr = randomOutputDir + patternPart + "-%d{" + DATE_PATTERN_WITH_SECONDS + ", GMT}"; String fileName = fileOptionIsSet ? testId2FileName(testId) : null; initRFA(rfa2, fileName); initTRBP(rfa2, tbrp2, filePatternStr, currentTime); for (int i = 0; i < 3; i++) { rfa2.doAppend("World---" + i); addExpectedFileNamedIfItsTime_ByDate(filePatternStr); incCurrentTime(400); tbrp2.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime); add(tbrp2.compressionFuture); add(tbrp2.cleanUpFuture); } rfa2.stop(); }