Repository: logging-log4j2 Updated Branches: refs/heads/LOG4J2-1883-instant-field 773012e52 -> 2b15f88b3
LOG4J2-1883 moved the new precise time-related classes from util to new package core.time Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/2b15f88b Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/2b15f88b Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/2b15f88b Branch: refs/heads/LOG4J2-1883-instant-field Commit: 2b15f88b390ff6249ef9fd15468e9a6c59073898 Parents: 773012e Author: rpopma <[email protected]> Authored: Fri Jan 26 21:16:20 2018 +0900 Committer: rpopma <[email protected]> Committed: Fri Jan 26 21:16:20 2018 +0900 ---------------------------------------------------------------------- .../logging/log4j/core/AbstractLogEvent.java | 4 +- .../org/apache/logging/log4j/core/LogEvent.java | 2 +- .../db/jpa/AbstractLogEventWrapperEntity.java | 2 +- .../appender/db/jpa/BasicLogEventEntity.java | 2 +- .../converter/InstantAttributeConverter.java | 5 +- .../log4j/core/async/RingBufferLogEvent.java | 2 + .../logging/log4j/core/impl/Log4jLogEvent.java | 2 + .../log4j/core/impl/MutableLogEvent.java | 2 + .../log4j/core/jackson/Initializers.java | 2 +- .../log4j/core/jackson/InstantMixIn.java | 4 +- .../log4j/core/jackson/LogEventJsonMixIn.java | 2 +- .../jackson/LogEventWithContextListMixIn.java | 2 +- .../core/pattern/DatePatternConverter.java | 4 +- .../log4j/core/time/FixedPreciseClock.java | 62 +++++ .../apache/logging/log4j/core/time/Instant.java | 75 ++++++ .../logging/log4j/core/time/MutableInstant.java | 160 +++++++++++++ .../logging/log4j/core/time/PreciseClock.java | 35 +++ .../logging/log4j/core/util/ClockFactory.java | 1 + .../log4j/core/util/FixedPreciseClock.java | 62 ----- .../apache/logging/log4j/core/util/Instant.java | 74 ------ .../logging/log4j/core/util/MutableInstant.java | 159 ------------- .../logging/log4j/core/util/PreciseClock.java | 33 --- .../core/util/datetime/FixedDateFormat.java | 2 +- .../appender/db/jpa/LogEventEntityTest.java | 4 +- .../core/appender/db/jpa/TestBaseEntity.java | 2 +- .../InstantAttributeConverterTest.java | 5 +- .../core/async/RingBufferLogEventTest.java | 2 +- .../core/pattern/DatePatternConverterTest.java | 4 +- .../log4j/core/time/MutableInstantTest.java | 231 +++++++++++++++++++ .../log4j/core/util/MutableInstantTest.java | 230 ------------------ .../log4j/flume/appender/FlumeEvent.java | 2 +- 31 files changed, 593 insertions(+), 585 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2b15f88b/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractLogEvent.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractLogEvent.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractLogEvent.java index bc7d1b4..b9dd2bb 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractLogEvent.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/AbstractLogEvent.java @@ -24,8 +24,8 @@ import org.apache.logging.log4j.Marker; import org.apache.logging.log4j.ThreadContext; import org.apache.logging.log4j.ThreadContext.ContextStack; import org.apache.logging.log4j.core.impl.ThrowableProxy; -import org.apache.logging.log4j.core.util.Instant; -import org.apache.logging.log4j.core.util.MutableInstant; +import org.apache.logging.log4j.core.time.Instant; +import org.apache.logging.log4j.core.time.MutableInstant; import org.apache.logging.log4j.message.Message; import org.apache.logging.log4j.util.ReadOnlyStringMap; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2b15f88b/log4j-core/src/main/java/org/apache/logging/log4j/core/LogEvent.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/LogEvent.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/LogEvent.java index 0f72050..0879f40 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/LogEvent.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/LogEvent.java @@ -24,7 +24,7 @@ import org.apache.logging.log4j.Level; import org.apache.logging.log4j.Marker; import org.apache.logging.log4j.ThreadContext; import org.apache.logging.log4j.core.impl.ThrowableProxy; -import org.apache.logging.log4j.core.util.Instant; +import org.apache.logging.log4j.core.time.Instant; import org.apache.logging.log4j.message.Message; import org.apache.logging.log4j.util.ReadOnlyStringMap; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2b15f88b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/AbstractLogEventWrapperEntity.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/AbstractLogEventWrapperEntity.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/AbstractLogEventWrapperEntity.java index 6c736c6..8504f7a 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/AbstractLogEventWrapperEntity.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/AbstractLogEventWrapperEntity.java @@ -26,7 +26,7 @@ import org.apache.logging.log4j.Level; import org.apache.logging.log4j.Marker; import org.apache.logging.log4j.ThreadContext; import org.apache.logging.log4j.core.AbstractLogEvent; -import org.apache.logging.log4j.core.util.Instant; +import org.apache.logging.log4j.core.time.Instant; import org.apache.logging.log4j.util.ReadOnlyStringMap; import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.core.appender.db.jpa.converter.ContextDataAttributeConverter; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2b15f88b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/BasicLogEventEntity.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/BasicLogEventEntity.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/BasicLogEventEntity.java index 492aa61..fa52501 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/BasicLogEventEntity.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/BasicLogEventEntity.java @@ -28,7 +28,7 @@ import org.apache.logging.log4j.ThreadContext; import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.core.appender.db.jpa.converter.*; import org.apache.logging.log4j.core.impl.ThrowableProxy; -import org.apache.logging.log4j.core.util.Instant; +import org.apache.logging.log4j.core.time.Instant; import org.apache.logging.log4j.message.Message; /** http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2b15f88b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/converter/InstantAttributeConverter.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/converter/InstantAttributeConverter.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/converter/InstantAttributeConverter.java index 408d972..9e0120e 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/converter/InstantAttributeConverter.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/db/jpa/converter/InstantAttributeConverter.java @@ -16,9 +16,8 @@ */ package org.apache.logging.log4j.core.appender.db.jpa.converter; -import org.apache.logging.log4j.core.util.Instant; -import org.apache.logging.log4j.core.util.MutableInstant; -import org.apache.logging.log4j.message.Message; +import org.apache.logging.log4j.core.time.Instant; +import org.apache.logging.log4j.core.time.MutableInstant; import org.apache.logging.log4j.status.StatusLogger; import org.apache.logging.log4j.util.Strings; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2b15f88b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java index af06e47..9e51815 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java @@ -28,6 +28,8 @@ import org.apache.logging.log4j.core.impl.ContextDataFactory; import org.apache.logging.log4j.core.impl.Log4jLogEvent; import org.apache.logging.log4j.core.impl.ThrowableProxy; import org.apache.logging.log4j.core.util.*; +import org.apache.logging.log4j.core.time.Instant; +import org.apache.logging.log4j.core.time.MutableInstant; import org.apache.logging.log4j.message.Message; import org.apache.logging.log4j.message.ParameterizedMessage; import org.apache.logging.log4j.message.ReusableMessage; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2b15f88b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java index 23a8dc0..2fe5a9b 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java @@ -30,6 +30,8 @@ import org.apache.logging.log4j.Marker; import org.apache.logging.log4j.ThreadContext; import org.apache.logging.log4j.core.ContextDataInjector; import org.apache.logging.log4j.core.util.*; +import org.apache.logging.log4j.core.time.Instant; +import org.apache.logging.log4j.core.time.MutableInstant; import org.apache.logging.log4j.util.ReadOnlyStringMap; import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.core.async.RingBufferLogEvent; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2b15f88b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java index ec807d3..d03223f 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java @@ -27,6 +27,8 @@ import org.apache.logging.log4j.ThreadContext; import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.core.async.InternalAsyncUtil; import org.apache.logging.log4j.core.util.*; +import org.apache.logging.log4j.core.time.Instant; +import org.apache.logging.log4j.core.time.MutableInstant; import org.apache.logging.log4j.message.*; import org.apache.logging.log4j.util.ReadOnlyStringMap; import org.apache.logging.log4j.util.StackLocatorUtil; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2b15f88b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Initializers.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Initializers.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Initializers.java index 18e30e2..3bc3447 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Initializers.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/Initializers.java @@ -27,7 +27,7 @@ import org.apache.logging.log4j.message.ObjectMessage; import com.fasterxml.jackson.databind.Module.SetupContext; import com.fasterxml.jackson.databind.module.SimpleModule; -import org.apache.logging.log4j.core.util.Instant; +import org.apache.logging.log4j.core.time.Instant; /** * Initialization utils. http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2b15f88b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/InstantMixIn.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/InstantMixIn.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/InstantMixIn.java index 44b9a6d..216534b 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/InstantMixIn.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/InstantMixIn.java @@ -19,11 +19,9 @@ package org.apache.logging.log4j.core.jackson; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; -import org.apache.logging.log4j.Level; import org.apache.logging.log4j.Marker; -import org.apache.logging.log4j.core.util.Instant; +import org.apache.logging.log4j.core.time.Instant; /** * Jackson mix-in for {@link Instant}. http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2b15f88b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/LogEventJsonMixIn.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/LogEventJsonMixIn.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/LogEventJsonMixIn.java index 6c27295..bbb024d 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/LogEventJsonMixIn.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/LogEventJsonMixIn.java @@ -21,7 +21,7 @@ import java.util.Map; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.Marker; import org.apache.logging.log4j.ThreadContext.ContextStack; -import org.apache.logging.log4j.core.util.Instant; +import org.apache.logging.log4j.core.time.Instant; import org.apache.logging.log4j.util.ReadOnlyStringMap; import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.core.impl.ThrowableProxy; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2b15f88b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/LogEventWithContextListMixIn.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/LogEventWithContextListMixIn.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/LogEventWithContextListMixIn.java index b71fcfc..12b61fa 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/LogEventWithContextListMixIn.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/jackson/LogEventWithContextListMixIn.java @@ -21,7 +21,7 @@ import java.util.Map; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.Marker; import org.apache.logging.log4j.ThreadContext.ContextStack; -import org.apache.logging.log4j.core.util.Instant; +import org.apache.logging.log4j.core.time.Instant; import org.apache.logging.log4j.util.ReadOnlyStringMap; import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.core.impl.ThrowableProxy; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2b15f88b/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/DatePatternConverter.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/DatePatternConverter.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/DatePatternConverter.java index 3b5ce67..ca65d4d 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/DatePatternConverter.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/DatePatternConverter.java @@ -25,8 +25,8 @@ import java.util.concurrent.atomic.AtomicReference; import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.core.config.plugins.Plugin; import org.apache.logging.log4j.core.util.Constants; -import org.apache.logging.log4j.core.util.Instant; -import org.apache.logging.log4j.core.util.MutableInstant; +import org.apache.logging.log4j.core.time.Instant; +import org.apache.logging.log4j.core.time.MutableInstant; import org.apache.logging.log4j.core.util.datetime.FastDateFormat; import org.apache.logging.log4j.core.util.datetime.FixedDateFormat; import org.apache.logging.log4j.core.util.datetime.FixedDateFormat.FixedFormat; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2b15f88b/log4j-core/src/main/java/org/apache/logging/log4j/core/time/FixedPreciseClock.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/time/FixedPreciseClock.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/time/FixedPreciseClock.java new file mode 100644 index 0000000..21edc80 --- /dev/null +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/time/FixedPreciseClock.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache license, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the license for the specific language governing permissions and + * limitations under the license. + */ +package org.apache.logging.log4j.core.time; + +/** + * Implementation of the {@code PreciseClock} interface that always returns a fixed time value. + * @since 2.11 + */ +public class FixedPreciseClock implements PreciseClock { + private final long currentTimeMillis; + private final int nanosOfMillisecond; + + /** + * Constructs a {@code FixedPreciseClock} that always returns the epoch. + */ + public FixedPreciseClock() { + this(0); + } + + /** + * Constructs a {@code FixedPreciseClock} that always returns the specified time in milliseconds since the epoch. + * @param currentTimeMillis milliseconds since the epoch + */ + public FixedPreciseClock(final long currentTimeMillis) { + this(currentTimeMillis, 0); + } + + /** + * Constructs a {@code FixedPreciseClock} that always returns the specified time in milliseconds since the epoch + * and nanosecond of the millisecond. + * @param currentTimeMillis milliseconds since the epoch + * @param nanosOfMillisecond nanosecond of the specified millisecond + */ + public FixedPreciseClock(final long currentTimeMillis, final int nanosOfMillisecond) { + this.currentTimeMillis = currentTimeMillis; + this.nanosOfMillisecond = nanosOfMillisecond; + } + + @Override + public void init(final MutableInstant instant) { + instant.initFromEpochMilli(currentTimeMillis, nanosOfMillisecond); + } + + @Override + public long currentTimeMillis() { + return currentTimeMillis; + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2b15f88b/log4j-core/src/main/java/org/apache/logging/log4j/core/time/Instant.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/time/Instant.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/time/Instant.java new file mode 100644 index 0000000..ab50da1 --- /dev/null +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/time/Instant.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache license, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the license for the specific language governing permissions and + * limitations under the license. + */ +package org.apache.logging.log4j.core.time; + +import org.apache.logging.log4j.core.util.Clock; +import org.apache.logging.log4j.util.StringBuilderFormattable; + +/** + * Models a point in time, suitable for event timestamps. + * <p> + * Provides methods for obtaining high precision time information similar to the + * <a href="https://docs.oracle.com/javase/9/docs/api/java/time/Instant.html">Instant</a> class introduced in Java 8, + * while also supporting the legacy millisecond precision API. + * </p><p> + * Depending on the platform, time sources ({@link Clock} implementations) may produce high precision or millisecond + * precision time values. At the same time, some time value consumers (for example timestamp formatters) may only be + * able to consume time values of millisecond precision, while some others may require a high precision time value. + * </p><p> + * This class bridges these two time APIs. + * </p> + * @since 2.11 + */ +public interface Instant extends StringBuilderFormattable { + /** + * Gets the number of seconds from the Java epoch of 1970-01-01T00:00:00Z. + * <p> + * The epoch second count is a simple incrementing count of seconds where second 0 is 1970-01-01T00:00:00Z. + * The nanosecond part of the day is returned by {@link #getNanoOfSecond()}. + * </p> + * @return the seconds from the epoch of 1970-01-01T00:00:00Z + */ + long getEpochSecond(); + + /** + * Gets the number of nanoseconds, later along the time-line, from the start of the second. + * <p> + * The nanosecond-of-second value measures the total number of nanoseconds from the second returned by {@link #getEpochSecond()}. + * </p> + * @return the nanoseconds within the second, always positive, never exceeds {@code 999,999,999} + */ + int getNanoOfSecond(); + + /** + * Gets the number of milliseconds from the Java epoch of 1970-01-01T00:00:00Z. + * <p> + * The epoch millisecond count is a simple incrementing count of milliseconds where millisecond 0 is 1970-01-01T00:00:00Z. + * The nanosecond part of the day is returned by {@link #getNanoOfMillisecond()}. + * </p> + * @return the milliseconds from the epoch of 1970-01-01T00:00:00Z + */ + long getEpochMillisecond(); + + /** + * Gets the number of nanoseconds, later along the time-line, from the start of the millisecond. + * <p> + * The nanosecond-of-millisecond value measures the total number of nanoseconds from the millisecond returned by {@link #getEpochMillisecond()}. + * </p> + * @return the nanoseconds within the millisecond, always positive, never exceeds {@code 999,999} + */ + int getNanoOfMillisecond(); +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2b15f88b/log4j-core/src/main/java/org/apache/logging/log4j/core/time/MutableInstant.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/time/MutableInstant.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/time/MutableInstant.java new file mode 100644 index 0000000..2e49a96 --- /dev/null +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/time/MutableInstant.java @@ -0,0 +1,160 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache license, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the license for the specific language governing permissions and + * limitations under the license. + */ +package org.apache.logging.log4j.core.time; + +import org.apache.logging.log4j.core.util.Clock; +import org.apache.logging.log4j.util.PerformanceSensitive; + +import java.io.Serializable; + +/** + * An instantaneous point on the time line, used for high-precision log event timestamps. + * Modelled on <a href="https://docs.oracle.com/javase/9/docs/api/index.html?java/time/class-use/Instant.html">java.time.Instant</a>, + * except that this version is mutable to prevent allocating temporary objects that need to be garbage-collected later. + * <p> + * Instances of this class are <em>not</em> thread-safe and should not be shared between threads. + * </p> + * + * @since 2.11 + */ +@PerformanceSensitive("allocation") +public class MutableInstant implements Instant, Serializable { + + private static final int MILLIS_PER_SECOND = 1000; + private static final int NANOS_PER_MILLI = 1000_000; + private static final int NANOS_PER_SECOND = MILLIS_PER_SECOND * NANOS_PER_MILLI; + + private long epochSecond; + private int nanoOfSecond; + + @Override + public long getEpochSecond() { + return epochSecond; + } + + @Override + public int getNanoOfSecond() { + return nanoOfSecond; + } + + @Override + public long getEpochMillisecond() { + final int millis = nanoOfSecond / NANOS_PER_MILLI; + long epochMillisecond = epochSecond * MILLIS_PER_SECOND + millis; + return epochMillisecond; + } + + @Override + public int getNanoOfMillisecond() { + final int millis = nanoOfSecond / NANOS_PER_MILLI; + int nanoOfMillisecond = nanoOfSecond - (millis * NANOS_PER_MILLI); // cheaper than nanoOfSecond % NANOS_PER_MILLI + return nanoOfMillisecond; + } + + public void initFrom(final Instant other) { + this.epochSecond = other.getEpochSecond(); + this.nanoOfSecond = other.getNanoOfSecond(); + } + + /** + * Updates the fields of this {@code MutableInstant} from the specified epoch millis. + * @param epochMilli the number of milliseconds from the Java epoch of 1970-01-01T00:00:00Z + * @param nanoOfMillisecond the number of nanoseconds, later along the time-line, from the start of the millisecond + */ + public void initFromEpochMilli(final long epochMilli, final int nanoOfMillisecond) { + validateNanoOfMillisecond(nanoOfMillisecond); + this.epochSecond = epochMilli / MILLIS_PER_SECOND; + this.nanoOfSecond = (int) (epochMilli - (epochSecond * MILLIS_PER_SECOND)) * NANOS_PER_MILLI + nanoOfMillisecond; + } + + private void validateNanoOfMillisecond(final int nanoOfMillisecond) { + if (nanoOfMillisecond < 0 || nanoOfMillisecond >= NANOS_PER_MILLI) { + throw new IllegalArgumentException("Invalid nanoOfMillisecond " + nanoOfMillisecond); + } + } + + public void initFrom(final Clock clock) { + if (clock instanceof PreciseClock) { + ((PreciseClock) clock).init(this); + } else { + initFromEpochMilli(clock.currentTimeMillis(), 0); + } + } + + /** + * Updates the fields of this {@code MutableInstant} from the specified instant components. + * @param epochSecond the number of seconds from the Java epoch of 1970-01-01T00:00:00Z + * @param nano the number of nanoseconds, later along the time-line, from the start of the second + */ + public void initFromEpochSecond(final long epochSecond, final int nano) { + validateNanoOfSecond(nano); + this.epochSecond = epochSecond; + this.nanoOfSecond = nano; + } + + private void validateNanoOfSecond(final int nano) { + if (nano < 0 || nano >= NANOS_PER_SECOND) { + throw new IllegalArgumentException("Invalid nanoOfSecond " + nano); + } + } + + /** + * Updates the elements of the specified {@code long[]} result array from the specified instant components. + * @param epochSecond (input) the number of seconds from the Java epoch of 1970-01-01T00:00:00Z + * @param nano (input) the number of nanoseconds, later along the time-line, from the start of the second + * @param result (output) a two-element array to store the result: the first element is the number of milliseconds + * from the Java epoch of 1970-01-01T00:00:00Z, + * the second element is the number of nanoseconds, later along the time-line, from the start of the millisecond + */ + public static void instantToMillisAndNanos(final long epochSecond, final int nano, final long[] result) { + int millis = nano / NANOS_PER_MILLI; + result[0] = epochSecond * MILLIS_PER_SECOND + millis; + result[1] = nano - (millis * NANOS_PER_MILLI); // cheaper than nanoOfSecond % NANOS_PER_MILLI + } + + @Override + public boolean equals(final Object object) { + if (object == this) { + return true; + } + if (!(object instanceof MutableInstant)) { + return false; + } + MutableInstant other = (MutableInstant) object; + return epochSecond == other.epochSecond && nanoOfSecond == other.nanoOfSecond; + } + + @Override + public int hashCode() { + int result = 17; + result = 31 * result + (int) (epochSecond ^ (epochSecond >>> 32)); + result = 31 * result + nanoOfSecond; + return result; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(64); + formatTo(sb); + return sb.toString(); + } + + @Override + public void formatTo(final StringBuilder buffer) { + buffer.append("MutableInstant[epochSecond=").append(epochSecond).append(", nano=").append(nanoOfSecond).append("]"); + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2b15f88b/log4j-core/src/main/java/org/apache/logging/log4j/core/time/PreciseClock.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/time/PreciseClock.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/time/PreciseClock.java new file mode 100644 index 0000000..c2416f6 --- /dev/null +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/time/PreciseClock.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache license, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the license for the specific language governing permissions and + * limitations under the license. + */ +package org.apache.logging.log4j.core.time; + +import org.apache.logging.log4j.core.util.Clock; + +/** + * Extension of the {@link Clock} interface that is able to provide more accurate time information than milliseconds + * since the epoch. {@code PreciseClock} implementations are free to return millisecond-precision time + * if that is the most accurate time information available on this platform. + * @since 2.11 + */ +public interface PreciseClock extends Clock { + + /** + * Initializes the specified instant with time information as accurate as available on this platform. + * @param mutableInstant the container to be initialized with the accurate time information + * @since 2.11 + */ + void init(final MutableInstant mutableInstant); +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2b15f88b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/ClockFactory.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/ClockFactory.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/ClockFactory.java index 7ba3fcc..5f33041 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/ClockFactory.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/ClockFactory.java @@ -16,6 +16,7 @@ */ package org.apache.logging.log4j.core.util; +import org.apache.logging.log4j.core.time.PreciseClock; import org.apache.logging.log4j.status.StatusLogger; import org.apache.logging.log4j.util.PropertiesUtil; import org.apache.logging.log4j.util.Supplier; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2b15f88b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/FixedPreciseClock.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/FixedPreciseClock.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/FixedPreciseClock.java deleted file mode 100644 index 57ba2ec..0000000 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/FixedPreciseClock.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache license, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the license for the specific language governing permissions and - * limitations under the license. - */ -package org.apache.logging.log4j.core.util; - -/** - * Implementation of the {@code PreciseClock} interface that always returns a fixed time value. - * @since 2.11 - */ -public class FixedPreciseClock implements PreciseClock { - private final long currentTimeMillis; - private final int nanosOfMillisecond; - - /** - * Constructs a {@code FixedPreciseClock} that always returns the epoch. - */ - public FixedPreciseClock() { - this(0); - } - - /** - * Constructs a {@code FixedPreciseClock} that always returns the specified time in milliseconds since the epoch. - * @param currentTimeMillis milliseconds since the epoch - */ - public FixedPreciseClock(final long currentTimeMillis) { - this(currentTimeMillis, 0); - } - - /** - * Constructs a {@code FixedPreciseClock} that always returns the specified time in milliseconds since the epoch - * and nanosecond of the millisecond. - * @param currentTimeMillis milliseconds since the epoch - * @param nanosOfMillisecond nanosecond of the specified millisecond - */ - public FixedPreciseClock(final long currentTimeMillis, final int nanosOfMillisecond) { - this.currentTimeMillis = currentTimeMillis; - this.nanosOfMillisecond = nanosOfMillisecond; - } - - @Override - public void init(final MutableInstant instant) { - instant.initFromEpochMilli(currentTimeMillis, nanosOfMillisecond); - } - - @Override - public long currentTimeMillis() { - return currentTimeMillis; - } -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2b15f88b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Instant.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Instant.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Instant.java deleted file mode 100644 index baa9c80..0000000 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Instant.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache license, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the license for the specific language governing permissions and - * limitations under the license. - */ -package org.apache.logging.log4j.core.util; - -import org.apache.logging.log4j.util.StringBuilderFormattable; - -/** - * Models a point in time, suitable for event timestamps. - * <p> - * Provides methods for obtaining high precision time information similar to the - * <a href="https://docs.oracle.com/javase/9/docs/api/java/time/Instant.html">Instant</a> class introduced in Java 8, - * while also supporting the legacy millisecond precision API. - * </p><p> - * Depending on the platform, time sources ({@link Clock} implementations) may produce high precision or millisecond - * precision time values. At the same time, some time value consumers (for example timestamp formatters) may only be - * able to consume time values of millisecond precision, while some others may require a high precision time value. - * </p><p> - * This class bridges these two time APIs. - * </p> - * @since 2.11 - */ -public interface Instant extends StringBuilderFormattable { - /** - * Gets the number of seconds from the Java epoch of 1970-01-01T00:00:00Z. - * <p> - * The epoch second count is a simple incrementing count of seconds where second 0 is 1970-01-01T00:00:00Z. - * The nanosecond part of the day is returned by {@link #getNanoOfSecond()}. - * </p> - * @return the seconds from the epoch of 1970-01-01T00:00:00Z - */ - long getEpochSecond(); - - /** - * Gets the number of nanoseconds, later along the time-line, from the start of the second. - * <p> - * The nanosecond-of-second value measures the total number of nanoseconds from the second returned by {@link #getEpochSecond()}. - * </p> - * @return the nanoseconds within the second, always positive, never exceeds {@code 999,999,999} - */ - int getNanoOfSecond(); - - /** - * Gets the number of milliseconds from the Java epoch of 1970-01-01T00:00:00Z. - * <p> - * The epoch millisecond count is a simple incrementing count of milliseconds where millisecond 0 is 1970-01-01T00:00:00Z. - * The nanosecond part of the day is returned by {@link #getNanoOfMillisecond()}. - * </p> - * @return the milliseconds from the epoch of 1970-01-01T00:00:00Z - */ - long getEpochMillisecond(); - - /** - * Gets the number of nanoseconds, later along the time-line, from the start of the millisecond. - * <p> - * The nanosecond-of-millisecond value measures the total number of nanoseconds from the millisecond returned by {@link #getEpochMillisecond()}. - * </p> - * @return the nanoseconds within the millisecond, always positive, never exceeds {@code 999,999} - */ - int getNanoOfMillisecond(); -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2b15f88b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/MutableInstant.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/MutableInstant.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/MutableInstant.java deleted file mode 100644 index 6ce378b..0000000 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/MutableInstant.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache license, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the license for the specific language governing permissions and - * limitations under the license. - */ -package org.apache.logging.log4j.core.util; - -import org.apache.logging.log4j.util.PerformanceSensitive; - -import java.io.Serializable; - -/** - * An instantaneous point on the time line, used for high-precision log event timestamps. - * Modelled on <a href="https://docs.oracle.com/javase/9/docs/api/index.html?java/time/class-use/Instant.html">java.time.Instant</a>, - * except that this version is mutable to prevent allocating temporary objects that need to be garbage-collected later. - * <p> - * Instances of this class are <em>not</em> thread-safe and should not be shared between threads. - * </p> - * - * @since 2.11 - */ -@PerformanceSensitive("allocation") -public class MutableInstant implements Instant, Serializable { - - private static final int MILLIS_PER_SECOND = 1000; - private static final int NANOS_PER_MILLI = 1000_000; - private static final int NANOS_PER_SECOND = MILLIS_PER_SECOND * NANOS_PER_MILLI; - - private long epochSecond; - private int nanoOfSecond; - - @Override - public long getEpochSecond() { - return epochSecond; - } - - @Override - public int getNanoOfSecond() { - return nanoOfSecond; - } - - @Override - public long getEpochMillisecond() { - final int millis = nanoOfSecond / NANOS_PER_MILLI; - long epochMillisecond = epochSecond * MILLIS_PER_SECOND + millis; - return epochMillisecond; - } - - @Override - public int getNanoOfMillisecond() { - final int millis = nanoOfSecond / NANOS_PER_MILLI; - int nanoOfMillisecond = nanoOfSecond - (millis * NANOS_PER_MILLI); // cheaper than nanoOfSecond % NANOS_PER_MILLI - return nanoOfMillisecond; - } - - public void initFrom(final Instant other) { - this.epochSecond = other.getEpochSecond(); - this.nanoOfSecond = other.getNanoOfSecond(); - } - - /** - * Updates the fields of this {@code MutableInstant} from the specified epoch millis. - * @param epochMilli the number of milliseconds from the Java epoch of 1970-01-01T00:00:00Z - * @param nanoOfMillisecond the number of nanoseconds, later along the time-line, from the start of the millisecond - */ - public void initFromEpochMilli(final long epochMilli, final int nanoOfMillisecond) { - validateNanoOfMillisecond(nanoOfMillisecond); - this.epochSecond = epochMilli / MILLIS_PER_SECOND; - this.nanoOfSecond = (int) (epochMilli - (epochSecond * MILLIS_PER_SECOND)) * NANOS_PER_MILLI + nanoOfMillisecond; - } - - private void validateNanoOfMillisecond(final int nanoOfMillisecond) { - if (nanoOfMillisecond < 0 || nanoOfMillisecond >= NANOS_PER_MILLI) { - throw new IllegalArgumentException("Invalid nanoOfMillisecond " + nanoOfMillisecond); - } - } - - public void initFrom(final Clock clock) { - if (clock instanceof PreciseClock) { - ((PreciseClock) clock).init(this); - } else { - initFromEpochMilli(clock.currentTimeMillis(), 0); - } - } - - /** - * Updates the fields of this {@code MutableInstant} from the specified instant components. - * @param epochSecond the number of seconds from the Java epoch of 1970-01-01T00:00:00Z - * @param nano the number of nanoseconds, later along the time-line, from the start of the second - */ - public void initFromEpochSecond(final long epochSecond, final int nano) { - validateNanoOfSecond(nano); - this.epochSecond = epochSecond; - this.nanoOfSecond = nano; - } - - private void validateNanoOfSecond(final int nano) { - if (nano < 0 || nano >= NANOS_PER_SECOND) { - throw new IllegalArgumentException("Invalid nanoOfSecond " + nano); - } - } - - /** - * Updates the elements of the specified {@code long[]} result array from the specified instant components. - * @param epochSecond (input) the number of seconds from the Java epoch of 1970-01-01T00:00:00Z - * @param nano (input) the number of nanoseconds, later along the time-line, from the start of the second - * @param result (output) a two-element array to store the result: the first element is the number of milliseconds - * from the Java epoch of 1970-01-01T00:00:00Z, - * the second element is the number of nanoseconds, later along the time-line, from the start of the millisecond - */ - public static void instantToMillisAndNanos(final long epochSecond, final int nano, final long[] result) { - int millis = nano / NANOS_PER_MILLI; - result[0] = epochSecond * MILLIS_PER_SECOND + millis; - result[1] = nano - (millis * NANOS_PER_MILLI); // cheaper than nanoOfSecond % NANOS_PER_MILLI - } - - @Override - public boolean equals(final Object object) { - if (object == this) { - return true; - } - if (!(object instanceof MutableInstant)) { - return false; - } - MutableInstant other = (MutableInstant) object; - return epochSecond == other.epochSecond && nanoOfSecond == other.nanoOfSecond; - } - - @Override - public int hashCode() { - int result = 17; - result = 31 * result + (int) (epochSecond ^ (epochSecond >>> 32)); - result = 31 * result + nanoOfSecond; - return result; - } - - @Override - public String toString() { - final StringBuilder sb = new StringBuilder(64); - formatTo(sb); - return sb.toString(); - } - - @Override - public void formatTo(final StringBuilder buffer) { - buffer.append("MutableInstant[epochSecond=").append(epochSecond).append(", nano=").append(nanoOfSecond).append("]"); - } -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2b15f88b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/PreciseClock.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/PreciseClock.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/PreciseClock.java deleted file mode 100644 index 366c1c4..0000000 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/PreciseClock.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache license, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the license for the specific language governing permissions and - * limitations under the license. - */ -package org.apache.logging.log4j.core.util; - -/** - * Extension of the {@link Clock} interface that is able to provide more accurate time information than milliseconds - * since the epoch. {@code PreciseClock} implementations are free to return millisecond-precision time - * if that is the most accurate time information available on this platform. - * @since 2.11 - */ -public interface PreciseClock extends Clock { - - /** - * Initializes the specified instant with time information as accurate as available on this platform. - * @param mutableInstant the container to be initialized with the accurate time information - * @since 2.11 - */ - void init(final MutableInstant mutableInstant); -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2b15f88b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/datetime/FixedDateFormat.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/datetime/FixedDateFormat.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/datetime/FixedDateFormat.java index 0d29178..f814b62 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/datetime/FixedDateFormat.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/datetime/FixedDateFormat.java @@ -17,7 +17,7 @@ package org.apache.logging.log4j.core.util.datetime; -import org.apache.logging.log4j.core.util.Instant; +import org.apache.logging.log4j.core.time.Instant; import java.util.Arrays; import java.util.Calendar; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2b15f88b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jpa/LogEventEntityTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jpa/LogEventEntityTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jpa/LogEventEntityTest.java index 823cee3..b70c754 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jpa/LogEventEntityTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jpa/LogEventEntityTest.java @@ -24,8 +24,8 @@ import org.apache.logging.log4j.Marker; import org.apache.logging.log4j.ThreadContext.ContextStack; import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.core.impl.ThrowableProxy; -import org.apache.logging.log4j.core.util.Instant; -import org.apache.logging.log4j.core.util.MutableInstant; +import org.apache.logging.log4j.core.time.Instant; +import org.apache.logging.log4j.core.time.MutableInstant; import org.apache.logging.log4j.message.Message; import org.junit.Assert; import org.junit.Test; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2b15f88b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jpa/TestBaseEntity.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jpa/TestBaseEntity.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jpa/TestBaseEntity.java index 3739731..2171de4 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jpa/TestBaseEntity.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jpa/TestBaseEntity.java @@ -35,7 +35,7 @@ import org.apache.logging.log4j.Level; import org.apache.logging.log4j.Marker; import org.apache.logging.log4j.ThreadContext; import org.apache.logging.log4j.core.appender.db.jpa.converter.InstantAttributeConverter; -import org.apache.logging.log4j.core.util.Instant; +import org.apache.logging.log4j.core.time.Instant; import org.apache.logging.log4j.util.ReadOnlyStringMap; import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.core.appender.db.jpa.converter.LevelAttributeConverter; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2b15f88b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jpa/converter/InstantAttributeConverterTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jpa/converter/InstantAttributeConverterTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jpa/converter/InstantAttributeConverterTest.java index ab2324f..f4970a9 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jpa/converter/InstantAttributeConverterTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jpa/converter/InstantAttributeConverterTest.java @@ -17,9 +17,8 @@ package org.apache.logging.log4j.core.appender.db.jpa.converter; import org.apache.logging.log4j.categories.Appenders; -import org.apache.logging.log4j.core.util.Instant; -import org.apache.logging.log4j.core.util.MutableInstant; -import org.apache.logging.log4j.message.Message; +import org.apache.logging.log4j.core.time.Instant; +import org.apache.logging.log4j.core.time.MutableInstant; import org.apache.logging.log4j.status.StatusLogger; import org.junit.Before; import org.junit.Test; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2b15f88b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/RingBufferLogEventTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/RingBufferLogEventTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/RingBufferLogEventTest.java index 82fab17..dfb0a35 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/RingBufferLogEventTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/RingBufferLogEventTest.java @@ -31,7 +31,7 @@ import org.apache.logging.log4j.ThreadContext.ContextStack; import org.apache.logging.log4j.categories.AsyncLoggers; import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.core.util.DummyNanoClock; -import org.apache.logging.log4j.core.util.FixedPreciseClock; +import org.apache.logging.log4j.core.time.FixedPreciseClock; import org.apache.logging.log4j.util.FilteredObjectInputStream; import org.apache.logging.log4j.util.StringMap; import org.apache.logging.log4j.core.impl.ThrowableProxy; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2b15f88b/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/DatePatternConverterTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/DatePatternConverterTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/DatePatternConverterTest.java index e6be56a..728254a 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/DatePatternConverterTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/pattern/DatePatternConverterTest.java @@ -28,8 +28,8 @@ import java.util.TimeZone; import org.apache.logging.log4j.core.AbstractLogEvent; import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.core.util.Constants; -import org.apache.logging.log4j.core.util.Instant; -import org.apache.logging.log4j.core.util.MutableInstant; +import org.apache.logging.log4j.core.time.Instant; +import org.apache.logging.log4j.core.time.MutableInstant; import org.apache.logging.log4j.core.util.datetime.FixedDateFormat; import org.junit.Test; import org.junit.runner.RunWith; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2b15f88b/log4j-core/src/test/java/org/apache/logging/log4j/core/time/MutableInstantTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/time/MutableInstantTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/time/MutableInstantTest.java new file mode 100644 index 0000000..e18c35f --- /dev/null +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/time/MutableInstantTest.java @@ -0,0 +1,231 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache license, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the license for the specific language governing permissions and + * limitations under the license. + */ +package org.apache.logging.log4j.core.time; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; + +public class MutableInstantTest { + + @Test + public void testGetEpochSecond() { + MutableInstant instant = new MutableInstant(); + assertEquals("initial", 0, instant.getEpochSecond()); + + instant.initFromEpochSecond(123, 456); + assertEquals("returns directly set value", 123, instant.getEpochSecond()); + + instant.initFromEpochMilli(123456, 789012); + assertEquals("returns converted value when initialized from milllis", 123, instant.getEpochSecond()); + + MutableInstant other = new MutableInstant(); + other.initFromEpochSecond(788, 456); + instant.initFrom(other); + + assertEquals("returns ref value when initialized from instant", 788, instant.getEpochSecond()); + } + + @Test + public void testGetNanoOfSecond() { + MutableInstant instant = new MutableInstant(); + assertEquals("initial", 0, instant.getNanoOfSecond()); + + instant.initFromEpochSecond(123, 456); + assertEquals("returns directly set value", 456, instant.getNanoOfSecond()); + + instant.initFromEpochMilli(123456, 789012); + assertEquals("returns converted value when initialized from milllis", 456789012, instant.getNanoOfSecond()); + + MutableInstant other = new MutableInstant(); + other.initFromEpochSecond(788, 456); + instant.initFrom(other); + + assertEquals("returns ref value when initialized from instant", 456, instant.getNanoOfSecond()); + } + + @Test + public void testGetEpochMillisecond() { + MutableInstant instant = new MutableInstant(); + assertEquals("initial", 0, instant.getEpochMillisecond()); + + instant.initFromEpochMilli(123, 456); + assertEquals("returns directly set value", 123, instant.getEpochMillisecond()); + + instant.initFromEpochSecond(123, 456789012); + assertEquals("returns converted value when initialized from seconds", 123456, instant.getEpochMillisecond()); + + MutableInstant other = new MutableInstant(); + other.initFromEpochMilli(788, 456); + instant.initFrom(other); + + assertEquals("returns ref value when initialized from instant", 788, instant.getEpochMillisecond()); + } + + @Test + public void getGetNanoOfMillisecond() { + MutableInstant instant = new MutableInstant(); + assertEquals("initial", 0, instant.getNanoOfMillisecond()); + + instant.initFromEpochMilli(123, 456); + assertEquals("returns directly set value", 456, instant.getNanoOfMillisecond()); + + instant.initFromEpochSecond(123, 456789012); + assertEquals("returns converted value when initialized from milllis", 789012, instant.getNanoOfMillisecond()); + + MutableInstant other = new MutableInstant(); + other.initFromEpochMilli(788, 456); + instant.initFrom(other); + + assertEquals("returns ref value when initialized from instant", 456, instant.getNanoOfMillisecond()); + } + + @Test(expected = NullPointerException.class) + public void testInitFromInstantRejectsNull() { + new MutableInstant().initFrom((Instant) null); + } + + @Test + public void testInitFromInstantCopiesValues() { + MutableInstant other = new MutableInstant(); + other.initFromEpochSecond(788, 456); + assertEquals("epochSec", 788, other.getEpochSecond()); + assertEquals("NanosOfSec", 456, other.getNanoOfSecond()); + + MutableInstant instant = new MutableInstant(); + instant.initFrom(other); + + assertEquals("epochSec", 788, instant.getEpochSecond()); + assertEquals("NanoOfSec", 456, instant.getNanoOfSecond()); + } + + @Test + public void testInitFromEpochMillis() { + MutableInstant instant = new MutableInstant(); + instant.initFromEpochMilli(123456, 789012); + assertEquals("epochSec", 123, instant.getEpochSecond()); + assertEquals("NanoOfSec", 456789012, instant.getNanoOfSecond()); + assertEquals("epochMilli", 123456, instant.getEpochMillisecond()); + assertEquals("NanoOfMilli", 789012, instant.getNanoOfMillisecond()); + } + + @Test(expected = IllegalArgumentException.class) + public void testInitFromEpochMillisRejectsNegativeNanoOfMilli() { + MutableInstant instant = new MutableInstant(); + instant.initFromEpochMilli(123456, -1); + } + + @Test(expected = IllegalArgumentException.class) + public void testInitFromEpochMillisRejectsTooLargeNanoOfMilli() { + MutableInstant instant = new MutableInstant(); + instant.initFromEpochMilli(123456, 1000_000); + } + + @Test + public void testInitFromEpochMillisAcceptsTooMaxNanoOfMilli() { + MutableInstant instant = new MutableInstant(); + instant.initFromEpochMilli(123456, 999_999); + assertEquals("NanoOfMilli", 999_999, instant.getNanoOfMillisecond()); + } + + @Test + public void testInitFromEpochSecond() { + MutableInstant instant = new MutableInstant(); + instant.initFromEpochSecond(123, 456789012); + assertEquals("epochSec", 123, instant.getEpochSecond()); + assertEquals("NanoOfSec", 456789012, instant.getNanoOfSecond()); + assertEquals("epochMilli", 123456, instant.getEpochMillisecond()); + assertEquals("NanoOfMilli", 789012, instant.getNanoOfMillisecond()); + } + + @Test(expected = IllegalArgumentException.class) + public void testInitFromEpochSecondRejectsNegativeNanoOfMilli() { + MutableInstant instant = new MutableInstant(); + instant.initFromEpochSecond(123456, -1); + } + + @Test(expected = IllegalArgumentException.class) + public void testInitFromEpochSecondRejectsTooLargeNanoOfMilli() { + MutableInstant instant = new MutableInstant(); + instant.initFromEpochSecond(123456, 1000_000_000); + } + + @Test + public void testInitFromEpochSecondAcceptsTooMaxNanoOfMilli() { + MutableInstant instant = new MutableInstant(); + instant.initFromEpochSecond(123456, 999_999_999); + assertEquals("NanoOfSec", 999_999_999, instant.getNanoOfSecond()); + } + + @Test + public void testInstantToMillisAndNanos() { + long[] values = new long[2]; + MutableInstant.instantToMillisAndNanos(123456, 999_999_999, values); + assertEquals(123456_999, values[0]); + assertEquals(999_999, values[1]); + } + + @Test + public void testInitFromClock() { + MutableInstant instant = new MutableInstant(); + + PreciseClock clock = new FixedPreciseClock(123456, 789012); + instant.initFrom(clock); + + assertEquals(123456, instant.getEpochMillisecond()); + assertEquals(789012, instant.getNanoOfMillisecond()); + assertEquals(123, instant.getEpochSecond()); + assertEquals(456789012, instant.getNanoOfSecond()); + } + + @Test + public void testEquals() { + MutableInstant instant = new MutableInstant(); + instant.initFromEpochSecond(123, 456789012); + + MutableInstant instant2 = new MutableInstant(); + instant2.initFromEpochMilli(123456, 789012); + + assertEquals(instant, instant2); + } + + @Test + public void testHashCode() { + MutableInstant instant = new MutableInstant(); + instant.initFromEpochSecond(123, 456789012); + + MutableInstant instant2 = new MutableInstant(); + instant2.initFromEpochMilli(123456, 789012); + + assertEquals(instant.hashCode(), instant2.hashCode()); + + + instant2.initFromEpochMilli(123456, 789013); + assertNotEquals(instant.hashCode(), instant2.hashCode()); + } + + @Test + public void testToString() { + MutableInstant instant = new MutableInstant(); + instant.initFromEpochSecond(123, 456789012); + assertEquals("MutableInstant[epochSecond=123, nano=456789012]", instant.toString()); + + instant.initFromEpochMilli(123456, 789012); + assertEquals("MutableInstant[epochSecond=123, nano=456789012]", instant.toString()); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2b15f88b/log4j-core/src/test/java/org/apache/logging/log4j/core/util/MutableInstantTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/util/MutableInstantTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/util/MutableInstantTest.java deleted file mode 100644 index 7bd6e6a..0000000 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/util/MutableInstantTest.java +++ /dev/null @@ -1,230 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache license, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the license for the specific language governing permissions and - * limitations under the license. - */ -package org.apache.logging.log4j.core.util; - -import org.junit.Test; - -import static org.junit.Assert.*; - -public class MutableInstantTest { - - @Test - public void testGetEpochSecond() { - MutableInstant instant = new MutableInstant(); - assertEquals("initial", 0, instant.getEpochSecond()); - - instant.initFromEpochSecond(123, 456); - assertEquals("returns directly set value", 123, instant.getEpochSecond()); - - instant.initFromEpochMilli(123456, 789012); - assertEquals("returns converted value when initialized from milllis", 123, instant.getEpochSecond()); - - MutableInstant other = new MutableInstant(); - other.initFromEpochSecond(788, 456); - instant.initFrom(other); - - assertEquals("returns ref value when initialized from instant", 788, instant.getEpochSecond()); - } - - @Test - public void testGetNanoOfSecond() { - MutableInstant instant = new MutableInstant(); - assertEquals("initial", 0, instant.getNanoOfSecond()); - - instant.initFromEpochSecond(123, 456); - assertEquals("returns directly set value", 456, instant.getNanoOfSecond()); - - instant.initFromEpochMilli(123456, 789012); - assertEquals("returns converted value when initialized from milllis", 456789012, instant.getNanoOfSecond()); - - MutableInstant other = new MutableInstant(); - other.initFromEpochSecond(788, 456); - instant.initFrom(other); - - assertEquals("returns ref value when initialized from instant", 456, instant.getNanoOfSecond()); - } - - @Test - public void testGetEpochMillisecond() { - MutableInstant instant = new MutableInstant(); - assertEquals("initial", 0, instant.getEpochMillisecond()); - - instant.initFromEpochMilli(123, 456); - assertEquals("returns directly set value", 123, instant.getEpochMillisecond()); - - instant.initFromEpochSecond(123, 456789012); - assertEquals("returns converted value when initialized from seconds", 123456, instant.getEpochMillisecond()); - - MutableInstant other = new MutableInstant(); - other.initFromEpochMilli(788, 456); - instant.initFrom(other); - - assertEquals("returns ref value when initialized from instant", 788, instant.getEpochMillisecond()); - } - - @Test - public void getGetNanoOfMillisecond() { - MutableInstant instant = new MutableInstant(); - assertEquals("initial", 0, instant.getNanoOfMillisecond()); - - instant.initFromEpochMilli(123, 456); - assertEquals("returns directly set value", 456, instant.getNanoOfMillisecond()); - - instant.initFromEpochSecond(123, 456789012); - assertEquals("returns converted value when initialized from milllis", 789012, instant.getNanoOfMillisecond()); - - MutableInstant other = new MutableInstant(); - other.initFromEpochMilli(788, 456); - instant.initFrom(other); - - assertEquals("returns ref value when initialized from instant", 456, instant.getNanoOfMillisecond()); - } - - @Test(expected = NullPointerException.class) - public void testInitFromInstantRejectsNull() { - new MutableInstant().initFrom((Instant) null); - } - - @Test - public void testInitFromInstantCopiesValues() { - MutableInstant other = new MutableInstant(); - other.initFromEpochSecond(788, 456); - assertEquals("epochSec", 788, other.getEpochSecond()); - assertEquals("NanosOfSec", 456, other.getNanoOfSecond()); - - MutableInstant instant = new MutableInstant(); - instant.initFrom(other); - - assertEquals("epochSec", 788, instant.getEpochSecond()); - assertEquals("NanoOfSec", 456, instant.getNanoOfSecond()); - } - - @Test - public void testInitFromEpochMillis() { - MutableInstant instant = new MutableInstant(); - instant.initFromEpochMilli(123456, 789012); - assertEquals("epochSec", 123, instant.getEpochSecond()); - assertEquals("NanoOfSec", 456789012, instant.getNanoOfSecond()); - assertEquals("epochMilli", 123456, instant.getEpochMillisecond()); - assertEquals("NanoOfMilli", 789012, instant.getNanoOfMillisecond()); - } - - @Test(expected = IllegalArgumentException.class) - public void testInitFromEpochMillisRejectsNegativeNanoOfMilli() { - MutableInstant instant = new MutableInstant(); - instant.initFromEpochMilli(123456, -1); - } - - @Test(expected = IllegalArgumentException.class) - public void testInitFromEpochMillisRejectsTooLargeNanoOfMilli() { - MutableInstant instant = new MutableInstant(); - instant.initFromEpochMilli(123456, 1000_000); - } - - @Test - public void testInitFromEpochMillisAcceptsTooMaxNanoOfMilli() { - MutableInstant instant = new MutableInstant(); - instant.initFromEpochMilli(123456, 999_999); - assertEquals("NanoOfMilli", 999_999, instant.getNanoOfMillisecond()); - } - - @Test - public void testInitFromEpochSecond() { - MutableInstant instant = new MutableInstant(); - instant.initFromEpochSecond(123, 456789012); - assertEquals("epochSec", 123, instant.getEpochSecond()); - assertEquals("NanoOfSec", 456789012, instant.getNanoOfSecond()); - assertEquals("epochMilli", 123456, instant.getEpochMillisecond()); - assertEquals("NanoOfMilli", 789012, instant.getNanoOfMillisecond()); - } - - @Test(expected = IllegalArgumentException.class) - public void testInitFromEpochSecondRejectsNegativeNanoOfMilli() { - MutableInstant instant = new MutableInstant(); - instant.initFromEpochSecond(123456, -1); - } - - @Test(expected = IllegalArgumentException.class) - public void testInitFromEpochSecondRejectsTooLargeNanoOfMilli() { - MutableInstant instant = new MutableInstant(); - instant.initFromEpochSecond(123456, 1000_000_000); - } - - @Test - public void testInitFromEpochSecondAcceptsTooMaxNanoOfMilli() { - MutableInstant instant = new MutableInstant(); - instant.initFromEpochSecond(123456, 999_999_999); - assertEquals("NanoOfSec", 999_999_999, instant.getNanoOfSecond()); - } - - @Test - public void testInstantToMillisAndNanos() { - long[] values = new long[2]; - MutableInstant.instantToMillisAndNanos(123456, 999_999_999, values); - assertEquals(123456_999, values[0]); - assertEquals(999_999, values[1]); - } - - @Test - public void testInitFromClock() { - MutableInstant instant = new MutableInstant(); - - PreciseClock clock = new FixedPreciseClock(123456, 789012); - instant.initFrom(clock); - - assertEquals(123456, instant.getEpochMillisecond()); - assertEquals(789012, instant.getNanoOfMillisecond()); - assertEquals(123, instant.getEpochSecond()); - assertEquals(456789012, instant.getNanoOfSecond()); - } - - @Test - public void testEquals() { - MutableInstant instant = new MutableInstant(); - instant.initFromEpochSecond(123, 456789012); - - MutableInstant instant2 = new MutableInstant(); - instant2.initFromEpochMilli(123456, 789012); - - assertEquals(instant, instant2); - } - - @Test - public void testHashCode() { - MutableInstant instant = new MutableInstant(); - instant.initFromEpochSecond(123, 456789012); - - MutableInstant instant2 = new MutableInstant(); - instant2.initFromEpochMilli(123456, 789012); - - assertEquals(instant.hashCode(), instant2.hashCode()); - - - instant2.initFromEpochMilli(123456, 789013); - assertNotEquals(instant.hashCode(), instant2.hashCode()); - } - - @Test - public void testToString() { - MutableInstant instant = new MutableInstant(); - instant.initFromEpochSecond(123, 456789012); - assertEquals("MutableInstant[epochSecond=123, nano=456789012]", instant.toString()); - - instant.initFromEpochMilli(123456, 789012); - assertEquals("MutableInstant[epochSecond=123, nano=456789012]", instant.toString()); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2b15f88b/log4j-flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/FlumeEvent.java ---------------------------------------------------------------------- diff --git a/log4j-flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/FlumeEvent.java b/log4j-flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/FlumeEvent.java index 73cd43e..cee5d9c 100644 --- a/log4j-flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/FlumeEvent.java +++ b/log4j-flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/FlumeEvent.java @@ -32,7 +32,7 @@ import org.apache.logging.log4j.ThreadContext; import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.core.impl.Log4jLogEvent; import org.apache.logging.log4j.core.impl.ThrowableProxy; -import org.apache.logging.log4j.core.util.Instant; +import org.apache.logging.log4j.core.time.Instant; import org.apache.logging.log4j.core.util.Patterns; import org.apache.logging.log4j.core.util.UuidUtil; import org.apache.logging.log4j.message.MapMessage;
