/** * Returns the currently registered streams. */ public static StreamSet current() { StreamRegistration reg = registration(false); if (reg == null) { return previous; } return reg.streams; }
/** * Check if there are streams registered for the current thread. */ public static boolean isRegistered() { return registration(false) != null; }
/** * Re-register streams for the current thread, and restore the previous if any. */ public static void deregister() { StreamRegistration cur = registration(true); registrations.set(cur.previous); if (log.isTraceEnabled()) { log.trace("De-registered: {}, using streams: {}", Thread.currentThread(), cur.previous == null ? "null" : cur.previous.streams); } }
/** * Register streams for the current thread. */ public static void register(final InputStream in, final PrintStream out, final PrintStream err) { ensureInstalled(); if (log.isTraceEnabled()) { log.trace("Registering: {} -> {}, {}, {}", new Object[] { Thread.currentThread(), in, out, err }); } StreamRegistration prev = registration(false); StreamSet set = new StreamSet(in, out, err); StreamRegistration next = new StreamRegistration(set, prev); registrations.set(next); }