"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "log4j-core/src/main/java/org/apache/logging/log4j/core/filter/TimeFilter.java" between
apache-log4j-2.11.1-src.tar.gz and apache-log4j-2.11.2-src.tar.gz

About: Apache Log4j 2 is a logging library for Java. Source distribution (Java).

TimeFilter.java  (apache-log4j-2.11.1-src):TimeFilter.java  (apache-log4j-2.11.2-src)
skipping to change at line 65 skipping to change at line 65
/** /**
* Length of second in milliseconds. * Length of second in milliseconds.
*/ */
private static final long SECOND_MS = 1000; private static final long SECOND_MS = 1000;
/** /**
* Starting offset from midnight in milliseconds. * Starting offset from midnight in milliseconds.
*/ */
private final long start; private final long start;
/** /**
* Ending offset from midnight in milliseconds. * Ending offset from midnight in milliseconds.
*/ */
private final long end; private final long end;
/** /**
* Timezone. * Timezone.
*/ */
private final TimeZone timezone; private final TimeZone timeZone;
private long midnightToday; private long midnightToday;
private long midnightTomorrow; private long midnightTomorrow;
private TimeFilter(final long start, final long end, final TimeZone tz, fina l Result onMatch, private TimeFilter(final long start, final long end, final TimeZone timeZone , final Result onMatch,
final Result onMismatch) { final Result onMismatch) {
super(onMatch, onMismatch); super(onMatch, onMismatch);
this.start = start; this.start = start;
this.end = end; this.end = end;
timezone = tz; this.timeZone = timeZone;
initMidnight(start); initMidnight(start);
} }
/** /**
* Initializes the midnight boundaries to midnight in the specified time zon e. * Initializes the midnight boundaries to midnight in the specified time zon e.
* @param now a time in milliseconds since the epoch, used to pinpoint the c urrent date * @param now a time in milliseconds since the epoch, used to pinpoint the c urrent date
*/ */
void initMidnight(final long now) { void initMidnight(final long now) {
final Calendar calendar = Calendar.getInstance(timezone); final Calendar calendar = Calendar.getInstance(timeZone);
calendar.setTimeInMillis(now); calendar.setTimeInMillis(now);
calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0); calendar.set(Calendar.MILLISECOND, 0);
midnightToday = calendar.getTimeInMillis(); midnightToday = calendar.getTimeInMillis();
calendar.add(Calendar.DATE, 1); calendar.add(Calendar.DATE, 1);
midnightTomorrow = calendar.getTimeInMillis(); midnightTomorrow = calendar.getTimeInMillis();
} }
skipping to change at line 215 skipping to change at line 217
final Object p0, final Object p1, final Object p2, final Object p3, final Object p4, final Object p5, final Object p0, final Object p1, final Object p2, final Object p3, final Object p4, final Object p5,
final Object p6, final Object p7, final Object p8, final Object p9) { final Object p6, final Object p7, final Object p8, final Object p9) {
return filter(); return filter();
} }
@Override @Override
public String toString() { public String toString() {
final StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
sb.append("start=").append(start); sb.append("start=").append(start);
sb.append(", end=").append(end); sb.append(", end=").append(end);
sb.append(", timezone=").append(timezone.toString()); sb.append(", timezone=").append(timeZone.toString());
return sb.toString(); return sb.toString();
} }
/** /**
* Creates a TimeFilter. * Creates a TimeFilter.
* @param start The start time. * @param start The start time.
* @param end The end time. * @param end The end time.
* @param tz timezone. * @param tz timezone.
* @param match Action to perform if the time matches. * @param match Action to perform if the time matches.
* @param mismatch Action to perform if the action does not match. * @param mismatch Action to perform if the action does not match.
skipping to change at line 238 skipping to change at line 240
// TODO Consider refactoring to use AbstractFilter.AbstractFilterBuilder // TODO Consider refactoring to use AbstractFilter.AbstractFilterBuilder
@PluginFactory @PluginFactory
public static TimeFilter createFilter( public static TimeFilter createFilter(
@PluginAttribute("start") final String start, @PluginAttribute("start") final String start,
@PluginAttribute("end") final String end, @PluginAttribute("end") final String end,
@PluginAttribute("timezone") final String tz, @PluginAttribute("timezone") final String tz,
@PluginAttribute("onMatch") final Result match, @PluginAttribute("onMatch") final Result match,
@PluginAttribute("onMismatch") final Result mismatch) { @PluginAttribute("onMismatch") final Result mismatch) {
final long s = parseTimestamp(start, 0); final long s = parseTimestamp(start, 0);
final long e = parseTimestamp(end, Long.MAX_VALUE); final long e = parseTimestamp(end, Long.MAX_VALUE);
final TimeZone timezone = tz == null ? TimeZone.getDefault() : TimeZone. getTimeZone(tz); final TimeZone timeZone = tz == null ? TimeZone.getDefault() : TimeZone. getTimeZone(tz);
final Result onMatch = match == null ? Result.NEUTRAL : match; final Result onMatch = match == null ? Result.NEUTRAL : match;
final Result onMismatch = mismatch == null ? Result.DENY : mismatch; final Result onMismatch = mismatch == null ? Result.DENY : mismatch;
return new TimeFilter(s, e, timezone, onMatch, onMismatch); return new TimeFilter(s, e, timeZone, onMatch, onMismatch);
} }
private static long parseTimestamp(final String timestamp, final long defaul tValue) { private static long parseTimestamp(final String timestamp, final long defaul tValue) {
if (timestamp == null) { if (timestamp == null) {
return defaultValue; return defaultValue;
} }
final SimpleDateFormat stf = new SimpleDateFormat("HH:mm:ss"); final SimpleDateFormat stf = new SimpleDateFormat("HH:mm:ss");
stf.setTimeZone(TimeZone.getTimeZone("UTC")); stf.setTimeZone(TimeZone.getTimeZone("UTC"));
try { try {
return stf.parse(timestamp).getTime(); return stf.parse(timestamp).getTime();
 End of changes. 9 change blocks. 
7 lines changed or deleted 9 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)