/** * {@inheritDoc} * <p> * Note that once this is invoked the handler will be activated and the messages will no longer be queued. * </p> */ @Override public Handler[] setHandlers(final Handler[] newHandlers) throws SecurityException { final Handler[] result = super.setHandlers(newHandlers); activate(); return result; }
private synchronized void activate() { // Always attempt to drain the queue ExtLogRecord record; while ((record = logRecords.pollFirst()) != null) { if (isEnabled() && isLoggable(record)) { publishToChildren(record); } } activated = true; }
@Override public final void close() throws SecurityException { checkAccess(this); synchronized (this) { if (!logRecords.isEmpty()) { Formatter formatter = getFormatter(); if (formatter == null) { formatter = new PatternFormatter("%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c] (%t) %s%e%n"); } StandardOutputStreams.printError("The DelayedHandler was closed before any children handlers were " + "configured. Messages will be written to stderr."); // Always attempt to drain the queue ExtLogRecord record; while ((record = logRecords.pollFirst()) != null) { StandardOutputStreams.printError(formatter.format(record)); } } } activated = false; super.close(); }
@Override protected void doPublish(final ExtLogRecord record) { // If activated just delegate if (activated) { publishToChildren(record); super.doPublish(record); } else { synchronized (this) { // Check one more time to see if we've been activated before queuing the messages if (activated) { publishToChildren(record); super.doPublish(record); } else { // Determine if we need to calculate the caller information before we queue the record if (isCallerCalculationRequired()) { // prepare record to move to another thread record.copyAll(); } else { // Disable the caller calculation since it's been determined we won't be using it record.disableCallerCalculation(); // Copy the MDC over record.copyMdc(); // In case serialization is required by a child handler record.getFormattedMessage(); } logRecords.addLast(record); } } } }
final Handler[] children = delayedHandler.getHandlers(); if (children == null || children.length == 0) { throw LoggingLogger.ROOT_LOGGER.invalidType(SocketHandler.class, null);
final Handler[] children = delayedHandler.getHandlers(); if (children == null || children.length == 0) { throw LoggingLogger.ROOT_LOGGER.invalidType(SocketHandler.class, null);
/** * {@inheritDoc} * <p> * Note that once this is invoked the handler will be activated and the messages will no longer be queued. If more * than one child handler is required the {@link #setHandlers(Handler[])} should be used. * </p> * * @see #setHandlers(Handler[]) */ @Override public void addHandler(final Handler handler) throws SecurityException { super.addHandler(handler); activate(); }