/** * Create a new LogBlock with the same body but updated uuid. * * @param uuid New uuid. * @return New LogBlock with updated uuid. */ public LogBlock withUuid(String uuid) { LogBlock newLogBlock = new LogBlock(uuid); body.entrySet().forEach(entry -> newLogBlock.body.put(entry.getKey(), entry.getValue())); return newLogBlock; }
/** * Creates a new and empty request log at the calling thread. */ private void init() { logId = UUID.randomUUID().toString(); info = new LogBlock(logId); // Trick to place Durations and Threads in front of the Json while keep using a LinkedHashMap. // The actual entries will be replaced later when export is called but the initial order will be respected info.add(Durations.class); info.add(Threads.class); info.add(Preface.class); getLoginfoOrder().stream().filter(entry -> !Objects.equals(entry, "Epilogue")).forEachOrdered( entry -> { try { @SuppressWarnings("unchecked") Class<LogInfo> cls = (Class<LogInfo>) Class.forName(entry); info.add(cls); } catch (ClassNotFoundException | ClassCastException e) { String msg = ErrorMessageFormat.LOGINFO_CLASS_INVALID.logFormat(entry); LOG.warn(msg, e); } } ); times.clear(); threadIds.clear(); threadIds.add(Thread.currentThread().getName()); MDC.put(ID_KEY, logId); }