@Test public void testDontInterpretBackslashAsEscape() { final PatternProcessor pp = new PatternProcessor("c:\\test\\new/app-%d{HH-mm-ss}.log"); final Calendar cal = Calendar.getInstance(); cal.set(Calendar.HOUR_OF_DAY, 16); cal.set(Calendar.MINUTE, 02); cal.set(Calendar.SECOND, 15); final StringBuilder buf = new StringBuilder(); pp.formatFileName(buf, cal.getTime(), 23); assertEquals("c:\\test\\new/app-16-02-15.log", buf.toString()); }
manager.getPatternProcessor().formatFileName(subst, buf, fileIndex); final String currentFileName = manager.getFileName();
manager.getPatternProcessor().formatFileName(subst, buf, lowIndex); manager.getPatternProcessor().formatFileName(subst, buf, i + 1);
manager.getPatternProcessor().formatFileName(subst, buf, highIndex); manager.getPatternProcessor().formatFileName(subst, buf, i - 1); buf.setLength(0); manager.getPatternProcessor().formatFileName(subst, buf, i - 1);
/** * Formats file name. * @param subst The StrSubstitutor. * @param buf string buffer to which formatted file name is appended, may not be null. * @param obj object to be evaluated in formatting, may not be null. */ public final void formatFileName(final StrSubstitutor subst, final StringBuilder buf, final Object obj) { formatFileName(subst, buf, false, obj); }
/** * Format file name. * @param buf string buffer to which formatted file name is appended, may not be null. * @param obj object to be evaluated in formatting, may not be null. */ public final void formatFileName(final StringBuilder buf, final boolean useCurrentTime, final Object obj) { long time = useCurrentTime ? currentFileTime : prevFileTime; if (time == 0) { time = System.currentTimeMillis(); } formatFileName(buf, new Date(time), obj); }
@Override public String getCurrentFileName(final RollingFileManager manager) { if (currentFileName == null) { final SortedMap<Integer, Path> eligibleFiles = getEligibleFiles(manager); final int fileIndex = eligibleFiles.size() > 0 ? (nextIndex > 0 ? nextIndex : eligibleFiles.size()) : 1; final StringBuilder buf = new StringBuilder(255); manager.getPatternProcessor().formatFileName(strSubstitutor, buf, true, fileIndex); final int suffixLength = suffixLength(buf.toString()); final String name = suffixLength > 0 ? buf.substring(0, buf.length() - suffixLength) : buf.toString(); currentFileName = name; } return currentFileName; }
protected SortedMap<Integer, Path> getEligibleFiles(final RollingFileManager manager, final boolean isAscending) { final StringBuilder buf = new StringBuilder(); final String pattern = manager.getPatternProcessor().getPattern(); manager.getPatternProcessor().formatFileName(strSubstitutor, buf, NotANumber.NAN); return getEligibleFiles(buf.toString(), pattern, isAscending); }
/** * Formats file name. * @param subst The StrSubstitutor. * @param buf string buffer to which formatted file name is appended, may not be null. * @param obj object to be evaluated in formatting, may not be null. */ public final void formatFileName(final StrSubstitutor subst, final StringBuilder buf, final boolean useCurrentTime, final Object obj) { // LOG4J2-628: we deliberately use System time, not the log4j.Clock time // for creating the file name of rolled-over files. final long time = useCurrentTime && currentFileTime != 0 ? currentFileTime : prevFileTime != 0 ? prevFileTime : System.currentTimeMillis(); formatFileName(buf, new Date(time), obj); final LogEvent event = new Log4jLogEvent.Builder().setTimeMillis(time).build(); final String fileName = subst.replace(event, buf); buf.setLength(0); buf.append(fileName); }
buf.setLength(0); manager.getPatternProcessor().formatFileName(strSubstitutor, buf, entry.getKey() - 1); final String currentName = entry.getValue().toFile().getName(); String renameTo = buf.toString();
buf.setLength(0); manager.getPatternProcessor().formatFileName(strSubstitutor, buf, entry.getKey() + 1); final String currentName = entry.getValue().toFile().getName(); String renameTo = buf.toString();
manager.getPatternProcessor().formatFileName(strSubstitutor, buf, fileIndex); final String currentFileName = manager.getFileName(); if (tempCompressedFilePattern != null) { buf.delete(0, buf.length()); tempCompressedFilePattern.formatFileName(strSubstitutor, buf, fileIndex); final String tmpCompressedName = buf.toString(); final File tmpCompressedNameFile = new File(tmpCompressedName);
if (tempCompressedFilePattern != null) { final StringBuilder buf = new StringBuilder(); tempCompressedFilePattern.formatFileName(strSubstitutor, buf, fileIndex); final String tmpCompressedName = buf.toString(); final File tmpCompressedNameFile = new File(tmpCompressedName);