/** * Redirects {@code java.util.logging} to Apache Commons Logging do not log below INFO level. */ public static synchronized void redirectToApacheCommons() { redirectToApacheCommons(Level.INFO); }
/** * Mark the beginning of an action initiated by the caller. */ public static void startFrom(final String callerThread, final String message) { startFrom(callerThread, message, DEFAULT_COLOR); }
public EventBundleRunner(List<EventListenerDescriptor> listeners, EventBundle bundle) { this.listeners = listeners; this.bundle = bundle; callerThread = SequenceTracer.getThreadName(); }
/** * Mark the beginning of an action */ public static void start(String message, String color) { if (!log.isDebugEnabled()) { return; } final String tn = getThreadName(); log.debug(PREFIX + tn + " -> " + tn + ": " + format(message) + "\n" + PREFIX + "activate " + tn + " " + color); }
/** * Mark the beginning of an action initiated by the caller. */ public static void startFrom(final String callerThread, final String message, final String color) { if (!log.isDebugEnabled()) { return; } final String tn = getThreadName(); log.debug(PREFIX + sanitize(callerThread) + " o--> " + tn + ": Initiate\n" + PREFIX + tn + " -> " + tn + ": " + format(message) + "\n" + PREFIX + "activate " + tn + " " + color); }
@Override public boolean awaitCompletion(String queueId, long duration, TimeUnit unit) throws InterruptedException { if (!isStarted()) { return true; } SequenceTracer.start("awaitCompletion on " + (queueId == null ? "all queues" : queueId)); long durationInMs = TimeUnit.MILLISECONDS.convert(duration, unit); long deadline = getTimestampAfter(durationInMs); int pause = (int) Math.min(durationInMs, 500L); log.debug("awaitForCompletion {} ms", durationInMs); do { if (noScheduledOrRunningWork(queueId)) { completionSynchronizer.signalCompletedWork(); SequenceTracer.stop("done"); return true; } completionSynchronizer.waitForCompletedWork(pause); } while (System.currentTimeMillis() < deadline); log.info("awaitCompletion timeout after {} ms", durationInMs); SequenceTracer.destroy("timeout after " + durationInMs + " ms"); return false; }
/** * Mark the beginning of an action */ public static void start(String message) { start(message, DEFAULT_COLOR); }
private static String format(String message) { String ret = sanitize(message).replace(", ", ",\\n"); ret = insertNewLine(ret); return ret; }
/** * Redirects {@code java.util.logging} to Apache Commons Logging do not log below the threshold level. * * @since 5.4.2 */ public static synchronized void redirectToApacheCommons(Level threshold) { if (activeHandler != null) { return; } try { Logger rootLogger = LogManager.getLogManager().getLogger(""); for (Handler handler : rootLogger.getHandlers()) { rootLogger.removeHandler(handler); } activeHandler = new LogHandler(); activeHandler.setLevel(threshold); rootLogger.addHandler(activeHandler); rootLogger.setLevel(threshold); log.info("Redirecting java.util.logging to Apache Commons Logging, threshold is " + threshold.toString()); } catch (SecurityException e) { log.error("Handler setup failed", e); } }
/** * Get the thread name sanitized for plantuml */ public static String getThreadName() { return sanitize(Thread.currentThread().getName()); }
@Override public void publish(LogRecord record) { if (holder.get() != null) { return; } holder.set(record); try { doPublish(record); } finally { holder.remove(); } }
/** * Mark the end of the previous action. */ public static void stop(String message) { if (!log.isDebugEnabled()) { return; } final String tn = getThreadName(); log.debug(PREFIX + tn + " -> " + tn + ": " + format(message) + "\n" + PREFIX + "deactivate " + tn); }
public EventBundleBulkRunner(List<EventListenerDescriptor> listeners, EventBundle bundle) { this.listeners = listeners; this.bundle = bundle; callerThread = SequenceTracer.getThreadName(); }
/** * Mark the last action as failure */ public static void destroy(String message) { if (!log.isDebugEnabled()) { return; } final String tn = getThreadName(); log.debug(PREFIX + tn + " -> " + tn + ": " + format(message) + "\n" + PREFIX + "destroy " + tn); }
public AbstractWork(String id) { this.id = id; progress = PROGRESS_INDETERMINATE; schedulingTime = System.currentTimeMillis(); callerThread = SequenceTracer.getThreadName(); }
/** * Link from source to current thread. */ public static void addRelation(String source, String message) { if (!log.isDebugEnabled()) { return; } log.debug(PREFIX + source + " --> " + getThreadName() + ": " + format(message)); }
/** * Mark an event. */ public static void mark(String message) { if (!log.isDebugEnabled()) { return; } final String tn = getThreadName(); log.debug(PREFIX + tn + " -> " + tn + ": " + message); }
/** * Add a note on the current thread */ public static void addNote(String message) { if (!log.isDebugEnabled()) { return; } log.debug(PREFIX + "note right of " + getThreadName() + ": " + message); }
/** * Constructs a {@link Work} instance with a unique id. */ public AbstractWork() { // we user RANDOM to deal with these cases: // - several calls in the time granularity of nanoTime() // - several concurrent calls on different servers this(System.nanoTime() + "." + (RANDOM.nextInt() & 0x7fffffff)); callerThread = SequenceTracer.getThreadName(); }