org.apache.logging.log4j.core.util.UuidUtil Java Examples
The following examples show how to use
org.apache.logging.log4j.core.util.UuidUtil.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RequestContext.java From audit-log-plugin with MIT License | 5 votes |
public static String getRequestId() { String uuidStr = ThreadContext.get(REQUEST_ID); if (uuidStr == null) { ThreadContext.put(REQUEST_ID, UuidUtil.getTimeBasedUuid().toString()); uuidStr = ThreadContext.get(REQUEST_ID); } return uuidStr; }
Example #2
Source File: RequestContextTest.java From logging-log4j-audit with Apache License 2.0 | 5 votes |
@Test public void testRequestContext() { RequestContext.getRequestId(); String sessionId = UuidUtil.getTimeBasedUuid().toString(); RequestContext.setSessionId(sessionId); String loginId = "testuser"; RequestContext.setLoginId(loginId); assertEquals("Incorrect loginId", loginId, RequestContext.getLoginId()); String hostName = "myhost"; RequestContext.setHostName(hostName); assertEquals("Incorrect host name", hostName, RequestContext.getHostName()); String ipAddress = "127.0.0.1"; RequestContext.setIpAddress(ipAddress); assertEquals("Incorrect LoginId", ipAddress, RequestContext.getIpAddress()); RequestContext requestContext = RequestContext.save(); RequestContext.clear(); assertNull(RequestContext.getSessionId()); assertNull(RequestContext.getLoginId()); assertNull(RequestContext.getHostName()); assertNull(RequestContext.getIpAddress()); requestContext.restore(); assertEquals(sessionId, RequestContext.getSessionId()); assertEquals(loginId, RequestContext.getLoginId()); assertEquals(hostName, RequestContext.getHostName()); assertEquals(ipAddress, RequestContext.getIpAddress()); }
Example #3
Source File: RequestContext.java From logging-log4j-audit with Apache License 2.0 | 5 votes |
public static String getRequestId() { String uuidStr = ThreadContext.get(REQUEST_ID); UUID uuid; if (uuidStr == null) { uuid = UuidUtil.getTimeBasedUuid(); ThreadContext.put(REQUEST_ID, uuid.toString()); } return uuidStr; }
Example #4
Source File: UuidGeneratorBenchmark.java From logging-log4j2 with Apache License 2.0 | 4 votes |
@Benchmark public UUID timeBasedUUID() { return UuidUtil.getTimeBasedUuid(); }
Example #5
Source File: RequestContext.java From logging-log4j2 with Apache License 2.0 | 4 votes |
public static void initialize() { ThreadContext.clearMap(); ThreadContext.put(REQUEST_ID, UuidUtil.getTimeBasedUuid().toString()); }
Example #6
Source File: UuidPatternConverter.java From logging-log4j2 with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ @Override public void format(final LogEvent event, final StringBuilder toAppendTo) { final UUID uuid = isRandom ? UUID.randomUUID() : UuidUtil.getTimeBasedUuid(); toAppendTo.append(uuid.toString()); }