/** * Exports a snapshot of the request log of the current thread and also resets the request log for that thread. * * @return the log context of the current thread */ public static RequestLog dump() { RequestLog current = RLOG.get(); RequestLog copy = new RequestLog(current); current.clear(); RLOG.remove(); return copy; }
/** * Overwrite current thread's request log context. * It first clears the request log of the current thread and then fills it with the contents found in ctx * * @param ctx the log context to restore to current thread's request log */ public static void restore(RequestLog ctx) { RequestLog current = RLOG.get(); current.clear(); current.logId = ctx.logId; current.info = ctx.info; current.mostRecentTimer = ctx.mostRecentTimer; current.times.putAll(ctx.times); current.threadIds.addAll(ctx.threadIds); current.threadIds.add(Thread.currentThread().getName()); MDC.put(ID_KEY, current.logId); }
/** * Write the request log object of the current thread as JSON. * The thread's request log is cleared after a call to this method. */ public static void log() { RequestLog current = RLOG.get(); if (current.info == null) { LOG.warn("Attempted to log while request log object was uninitialized"); return; } LOG.info(export()); current.clear(); }