protected synchronized boolean closeOutputStream() { flush(); final OutputStream stream = outputStream; // access volatile field only once per method if (stream == null || stream == System.out || stream == System.err) { return true; } try { stream.close(); } catch (final IOException ex) { logError("Unable to close stream", ex); return false; } return true; }
/** * Some output streams synchronize writes while others do not. Synchronizing here insures that * log events won't be intertwined. * @param bytes The serialized Log event. * @param offset The offset into the byte array. * @param length The number of bytes to write. * @param immediateFlush flushes immediately after writing. * @throws AppenderLoggingException if an error occurs. */ protected synchronized void write(final byte[] bytes, final int offset, final int length, final boolean immediateFlush) { if (immediateFlush && byteBuffer.position() == 0) { writeToDestination(bytes, offset, length); flushDestination(); return; } if (length >= byteBuffer.capacity()) { // if request length exceeds buffer capacity, flush the buffer and write the data directly flush(); writeToDestination(bytes, offset, length); } else { if (length > byteBuffer.remaining()) { flush(); } byteBuffer.put(bytes, offset, length); } if (immediateFlush) { flush(); } }
public static void flushAll() { final LoggerContext logCtx = ((LoggerContext) LogManager.getContext()); for(final org.apache.logging.log4j.core.Logger logger : logCtx.getLoggers()) { for(final Appender appender : logger.getAppenders().values()) { if(appender instanceof AbstractOutputStreamAppender) { ((AbstractOutputStreamAppender) appender).getManager().flush(); } } } } //
static void flushAll() { final LoggerContext logCtx = ((LoggerContext) LogManager.getContext()); for (final org.apache.logging.log4j.core.Logger logger : logCtx.getLoggers()) { for (final Appender appender : logger.getAppenders().values()) { if (appender instanceof AbstractOutputStreamAppender) { ((AbstractOutputStreamAppender) appender).getManager().flush(); } } } }
protected void directEncodeEvent(final LogEvent event) { getLayout().encode(event, manager); if (this.immediateFlush || event.isEndOfBatch()) { manager.flush(); } }