You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ma...@apache.org on 2016/02/29 03:46:15 UTC
logging-log4j2 git commit: Extract common method.
Repository: logging-log4j2
Updated Branches:
refs/heads/master 06a28d523 -> 7e0392378
Extract common method.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/7e039237
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/7e039237
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/7e039237
Branch: refs/heads/master
Commit: 7e0392378ed3c96c94c2eddddbc7da227ba8d9b9
Parents: 06a28d5
Author: Matt Sicker <bo...@gmail.com>
Authored: Sun Feb 28 20:46:10 2016 -0600
Committer: Matt Sicker <bo...@gmail.com>
Committed: Sun Feb 28 20:46:10 2016 -0600
----------------------------------------------------------------------
.../logging/log4j/core/filter/TimeFilter.java | 35 +++++++++-----------
1 file changed, 16 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7e039237/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/TimeFilter.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/TimeFilter.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/TimeFilter.java
index 159bc41..bd0fa18 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/TimeFilter.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/TimeFilter.java
@@ -113,29 +113,26 @@ public final class TimeFilter extends AbstractFilter {
@PluginAttribute("timezone") final String tz,
@PluginAttribute("onMatch") final Result match,
@PluginAttribute("onMismatch") final Result mismatch) {
- final SimpleDateFormat stf = new SimpleDateFormat("HH:mm:ss");
- long s = 0;
- if (start != null) {
- stf.setTimeZone(TimeZone.getTimeZone("UTC"));
- try {
- s = stf.parse(start).getTime();
- } catch (final ParseException ex) {
- LOGGER.warn("Error parsing start value " + start, ex);
- }
- }
- long e = Long.MAX_VALUE;
- if (end != null) {
- stf.setTimeZone(TimeZone.getTimeZone("UTC"));
- try {
- e = stf.parse(end).getTime();
- } catch (final ParseException ex) {
- LOGGER.warn("Error parsing start value " + end, ex);
- }
- }
+ final long s = parseTimestamp(start, 0);
+ final long e = parseTimestamp(end, Long.MAX_VALUE);
final TimeZone timezone = tz == null ? TimeZone.getDefault() : TimeZone.getTimeZone(tz);
final Result onMatch = match == null ? Result.NEUTRAL : match;
final Result onMismatch = mismatch == null ? Result.DENY : mismatch;
return new TimeFilter(s, e, timezone, onMatch, onMismatch);
}
+ private static long parseTimestamp(final String timestamp, final long defaultValue) {
+ if (timestamp == null) {
+ return defaultValue;
+ }
+ final SimpleDateFormat stf = new SimpleDateFormat("HH:mm:ss");
+ stf.setTimeZone(TimeZone.getTimeZone("UTC"));
+ try {
+ return stf.parse(timestamp).getTime();
+ } catch (ParseException e) {
+ LOGGER.warn("Error parsing TimeFilter timestamp value {}", timestamp, e);
+ return defaultValue;
+ }
+ }
+
}