Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.apache.logging.log4j.core.util.UuidUtil;

/**
* Formats the event sequence number.
* Formats a UUID.
*/
@Plugin(name = "UuidPatternConverter", category = PatternConverter.CATEGORY)
@ConverterKeys({"u", "uuid"})
Expand All @@ -39,10 +39,19 @@ private UuidPatternConverter(final boolean isRandom) {
}

/**
* Obtains an instance of SequencePatternConverter.
* Creates an instance of {@link UuidPatternConverter}.
* <p>
* The {@code RANDOM} option generates a Type 4 (pseudo-randomly generated) UUID.
* The UUID is generated using a cryptographically strong pseudo-random number generator.
* <p>
* The {@code TIME} option generates a Type 1 (date and time based) UUID using the local network interface's MAC address.
* To ensure uniqueness across multiple JVMs and/or class loaders on the same host, a random number between 0 and 16384 will be associated with each instance of the UUID generator class, and included in each time-based UUID generated.
* See {@link UuidUtil#UUID_SEQUENCE} how to seed the UUID generation with an integer value.
* Because time-based UUIDs contain the MAC address and timestamp, they should be used with care.
*
* @param options options, currently ignored, may be null.
* @return instance of SequencePatternConverter.
* @param options An array containing either {@code RANDOM} or {@code TIME}.
* If empty, {@code TIME} will be used.
* @return a new {@link UuidPatternConverter} instance
*/
public static UuidPatternConverter newInstance(final String[] options) {
if (options.length == 0) {
Expand Down
10 changes: 7 additions & 3 deletions src/site/antora/modules/ROOT/pages/manual/pattern-layout.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1339,15 +1339,19 @@ Includes either a random or a time-based UUID
.link:../javadoc/log4j-core/org/apache/logging/log4j/core/pattern/UuidPatternConverter.html[`UuidPatternConverter`] specifier grammar
[source,text]
----
u{RANDOM|TIME}
uuid{RANDOM|TIME}
u[{RANDOM|TIME}]
uuid[{RANDOM|TIME}]
----

The time-based UUID is a Type 1 UUID generated using the MAC address of each host
The random UUID is a type 4 UUID. The UUID is generated using a cryptographically strong pseudo-random number generator.

The time-based UUID is a Type 1 (date and time based) UUID generated using the MAC address of each host.
To ensure uniqueness across multiple JVMs and/or class loaders on the same host, a random number between 0 and 16,384 will be associated with each instance of the UUID generator class, and included in each time-based UUID generated.
See also xref:manual/systemproperties.adoc#log4j2.uuidSequence[`log4j2.uuidSequence`].
Because time-based UUIDs contain the MAC address and timestamp, they should be used with care.

TIME is the default.

[#format-modifiers]
=== Format modifiers

Expand Down