Refine search
@Override public FileAppender<ILoggingEvent> createAppender(String appenderName) { RollingFileAppender<ILoggingEvent> appender = new RollingFileAppender<>(); appender.setContext(context); appender.setName(appenderName); String filePath = new File(logsDir, filenamePrefix + ".log").getAbsolutePath(); appender.setFile(filePath); TimeBasedRollingPolicy rollingPolicy = new TimeBasedRollingPolicy(); rollingPolicy.setContext(context); rollingPolicy.setFileNamePattern(StringUtils.replace(filePath, filenamePrefix + ".log", filenamePrefix + ".%d{" + datePattern + "}.log")); rollingPolicy.setMaxHistory(maxFiles); rollingPolicy.setParent(appender); rollingPolicy.start(); appender.setRollingPolicy(rollingPolicy); return appender; } }
protected FileAppender<E> buildAppender(LoggerContext context) { if (archive) { final RollingFileAppender<E> appender = new RollingFileAppender<>(); appender.setContext(context); appender.setFile(currentLogFilename); appender.setBufferSize(new FileSize(bufferSize.toBytes())); final TimeBasedRollingPolicy<E> rollingPolicy; if (maxFileSize == null) { rollingPolicy = new TimeBasedRollingPolicy<>(); rollingPolicy.setTotalSizeCap(new FileSize(totalSizeCap.toBytes())); rollingPolicy.setContext(context); rollingPolicy.setFileNamePattern(archivedLogFilenamePattern); rollingPolicy.setMaxHistory(archivedFileCount); appender.setRollingPolicy(rollingPolicy); rollingPolicy.setParent(appender); rollingPolicy.start(); return appender;
RollingFileAppender<ILoggingEvent> appender = new RollingFileAppender<>(); appender.setEncoder(encoder); appender.setFile(file); TimeBasedRollingPolicy<ILoggingEvent> rolling = new TimeBasedRollingPolicy<>(); rolling.setContext(context); rolling.setParent(appender); rolling.setFileNamePattern(getFileWithPattern("%d")); rolling.setMaxHistory(maxNumberLogs.get()); } else { rolling.setMaxHistory(1); sizeBased.setTimeBasedRollingPolicy(rolling); rolling.setTimeBasedFileNamingAndTriggeringPolicy(sizeBased); rolling.start(); if (rolling.getTimeBasedFileNamingAndTriggeringPolicy() != null) { rolling.getTimeBasedFileNamingAndTriggeringPolicy().start(); appender.setRollingPolicy(rolling);
/** Create and return synchronous the rolling file appender. * @param context the context of logger. */ private RollingFileAppender<ILoggingEvent> getRollingFileAppender(LoggerContext context) throws InitializationException { if (archivedLogFilenamePattern == null || archivedLogFilenamePattern.trim().isEmpty()) { throw new InitializationException("Configuration property logging.appenders.archivedLogFilenamePattern cannot be null."); } RollingFileAppender<ILoggingEvent> appender = new RollingFileAppender<ILoggingEvent>(); appender.setFile(currentLogFilename); appender.setAppend(true); TimeBasedFileNamingAndTriggeringPolicy<ILoggingEvent> triggerPolicy = new DefaultTimeBasedFileNamingAndTriggeringPolicy<ILoggingEvent>(); triggerPolicy.setContext(context); TimeBasedRollingPolicy<ILoggingEvent> rollPolicy = new TimeBasedRollingPolicy<ILoggingEvent>(); rollPolicy.setContext(context); rollPolicy.setParent(appender); rollPolicy.setFileNamePattern(archivedLogFilenamePattern); rollPolicy.setMaxHistory(archivedFileCount); rollPolicy.setTimeBasedFileNamingAndTriggeringPolicy(triggerPolicy); rollPolicy.start(); appender.setRollingPolicy(rollPolicy); return appender; }
@SuppressWarnings("unchecked") public void setUpTimeBasedTriggeringPolicy(RollingFileAppender<Object> rfa) { String datePattern = "yyyy-MM-dd'T'HH_mm_ss_SSS"; TimeBasedRollingPolicy<Object> tbrp = new TimeBasedRollingPolicy(); tbrp.setFileNamePattern(outputDirStr + "test-%d{" + datePattern + "}"); tbrp.setContext(context); tbrp.setParent(rfa); tbrp.start(); rfa.setRollingPolicy(tbrp); rfa.start(); }
@SuppressWarnings("unchecked") static LoggerContext buildLoggerContext(String stamp, String filename, boolean safetyMode) { LoggerContext loggerContext = new LoggerContext(); RollingFileAppender<ILoggingEvent> rfa = new RollingFileAppender<ILoggingEvent>(); PatternLayoutEncoder patternLayout = new PatternLayoutEncoder(); patternLayout.setPattern(stamp + " %5p - %-50m%n"); patternLayout.setContext(loggerContext); patternLayout.start(); rfa.setEncoder(patternLayout); rfa.setAppend(true); rfa.setPrudent(safetyMode); rfa.setContext(loggerContext); TimeBasedRollingPolicy<ILoggingEvent> tbrp = new TimeBasedRollingPolicy(); tbrp.setContext(loggerContext); tbrp.setFileNamePattern(filename+"-%d{"+DATE_PATTERN+"}.log"); tbrp.setParent(rfa); tbrp.start(); rfa.setRollingPolicy(tbrp); rfa.start(); ch.qos.logback.classic.Logger root = loggerContext .getLogger(Logger.ROOT_LOGGER_NAME); root.addAppender(rfa); return loggerContext; }
private void buildRollingFileAppender(ConfigParameters cp) { rfa.setContext(context); rfa.setEncoder(encoder); tbrp.setContext(context); tbrp.setFileNamePattern(cp.fileNamePattern); tbrp.setMaxHistory(cp.maxHistory); tbrp.setTotalSizeCap(new FileSize(cp.sizeCap)); tbrp.setParent(rfa); tbrp.setCleanHistoryOnStart(false); tbrp.timeBasedFileNamingAndTriggeringPolicy = tbfnatp; tbrp.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(cp.simulatedTime); tbrp.start(); rfa.setRollingPolicy(tbrp); rfa.start(); }
new RollingFileAppender<ILoggingEvent>() : new FileAppender<ILoggingEvent>(); triggeringPolicy.setContext(context); final TimeBasedRollingPolicy<ILoggingEvent> rollingPolicy = new TimeBasedRollingPolicy<>(); rollingPolicy.setContext(context); rollingPolicy.setFileNamePattern(fileConfiguration.getArchivedLogFilenamePattern()); rollingPolicy.setTimeBasedFileNamingAndTriggeringPolicy(triggeringPolicy); triggeringPolicy.setTimeBasedRollingPolicy(rollingPolicy); rollingPolicy.setMaxHistory(fileConfiguration.getArchivedFileCount()); ((RollingFileAppender<ILoggingEvent>) appender).setRollingPolicy(rollingPolicy); ((RollingFileAppender<ILoggingEvent>) appender).setTriggeringPolicy(triggeringPolicy); rollingPolicy.setParent(appender); rollingPolicy.start();
@Override protected Appender<Object> getConfiguredAppender() { rfa.setContext(context); tbrp .setFileNamePattern(CoreTestConstants.OUTPUT_DIR_PREFIX + "toto-%d.log"); tbrp.start(); rfa.setRollingPolicy(tbrp); rfa.start(); return rfa; }
@Test public void testPrudentModeLogicalImplications() { rfa.setContext(context); // prudent mode will force "file" property to be null rfa.setFile("some non null value"); rfa.setAppend(false); rfa.setPrudent(true); tbrp .setFileNamePattern(CoreTestConstants.OUTPUT_DIR_PREFIX + "toto-%d.log"); tbrp.start(); rfa.setRollingPolicy(tbrp); rfa.start(); assertTrue(rfa.isAppend()); assertNull(rfa.rawFileProperty()); assertTrue(rfa.isStarted()); }
TimeBasedRollingPolicy<HttpRequestEvent> rollingPolicy = new TimeBasedRollingPolicy<>(); rollingPolicy.setContext(context); rollingPolicy.setMaxHistory(maxHistory); rollingPolicy.setTimeBasedFileNamingAndTriggeringPolicy(triggeringPolicy); rollingPolicy.setParent(fileAppender); rollingPolicy.setFileNamePattern(filename + "-%d{yyyy-MM-dd}.%i.log"); if (compressionEnabled) { rollingPolicy.setFileNamePattern(rollingPolicy.getFileNamePattern() + ".gz"); asyncAppender.addAppender(fileAppender); rollingPolicy.start(); triggeringPolicy.start(); fileAppender.start();
@Test public void testPrudentModeLogicalImplicationsOnCompression() { rfa.setContext(context); rfa.setAppend(false); rfa.setPrudent(true); tbrp.setFileNamePattern(CoreTestConstants.OUTPUT_DIR_PREFIX + "toto-%d.log.zip"); tbrp.start(); rfa.setRollingPolicy(tbrp); rfa.start(); StatusChecker checker = new StatusChecker(context); assertFalse(rfa.isStarted()); assertEquals(Status.ERROR, checker.getHighestLevel(0)); }
@Test public void stopTimeBasedRollingPolicy() { rfa.setContext(context); tbrp.setFileNamePattern(CoreTestConstants.OUTPUT_DIR_PREFIX + "toto-%d.log.zip"); tbrp.start(); rfa.setRollingPolicy(tbrp); rfa.start(); StatusPrinter.print(context); assertTrue(tbrp.isStarted()); assertTrue(rfa.isStarted()); rfa.stop(); assertFalse(rfa.isStarted()); assertFalse(tbrp.isStarted()); }
private RollingPolicy rollingPolicy(final CharSequence baseName, final Context context) { final TimeBasedRollingPolicy<ILoggingEvent> rollingPolicy = new TimeBasedRollingPolicy<>(); rollingPolicy.setContext(context); rollingPolicy.setFileNamePattern(filePath(baseName, "%d{yyyy-MM-dd}.%i.log")); rollingPolicy.setTimeBasedFileNamingAndTriggeringPolicy(sizedBasedNaming(context)); rollingPolicy.setMaxHistory(maxHistory); return rollingPolicy; }
rollingFileAppender.setAppend(true); TimeBasedRollingPolicy rollingPolicy = new TimeBasedRollingPolicy(); rollingPolicy.setContext(loggerContext); rollingPolicy.setParent(rollingFileAppender); rollingPolicy.setFileNamePattern(logFileName + "-%d{yyyy-MM-dd}.log"); rollingPolicy.setMaxHistory(maxHistory); rollingPolicy.start();
@Before public void setUp() { rfa.setContext(context); tbrp.setContext(context); timeBasedFNATP.setContext(context); rfa.setRollingPolicy(tbrp); tbrp.setParent(rfa); tbrp.setTimeBasedFileNamingAndTriggeringPolicy(timeBasedFNATP); timeBasedFNATP.setTimeBasedRollingPolicy(tbrp); }
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); }
@Before public void setUp() throws Exception { // noStartTest fails if the context is set in setUp // rfa.setContext(context); rfa.setEncoder(new DummyEncoder<Object>()); rfa.setName("test"); tbrp.setContext(context); tbrp.setParent(rfa); }
determineCompressionMode(); } else { addWarn(FNP_NOT_SET); addWarn(CoreConstants.SEE_FNP_NOT_SET); throw new IllegalStateException(FNP_NOT_SET + CoreConstants.SEE_FNP_NOT_SET); fileNamePatternStr, compressionMode), this.context); addInfo("Will use the pattern " + fileNamePatternWCS + " for the active file"); String zipEntryFileNamePatternStr = transformFileNamePattern2ZipEntry(fileNamePatternStr); zipEntryFileNamePattern = new FileNamePattern(zipEntryFileNamePatternStr, context); archiveRemover.setMaxHistory(maxHistory); if(cleanHistoryOnStart) { addInfo("Cleaning on start up"); archiveRemover.clean(new Date(timeBasedFileNamingAndTriggeringPolicy.getCurrentTime()));
@Test public void multiDate() { // Tuesday December 20th 17:59:01 CET 2011 long startTime = 1324400341553L; tbrp.setFileNamePattern("foo-%d{yyyy-MM, AUX}/%d{mm}.log"); tbrp.start(); timeBasedFNATP.setCurrentTime(startTime); timeBasedFNATP.start(); timeBasedFNATP.setCurrentTime(startTime+MILLIS_IN_MINUTE); timeBasedFNATP.isTriggeringEvent(null, null); String elapsedPeriodsFileName = timeBasedFNATP.getElapsedPeriodsFileName(); assertEquals("foo-2011-12/59.log", elapsedPeriodsFileName); }