/** * Write the log entry rolling over the file when required. * * @param event The LogEvent. */ @Override public void append(final LogEvent event) { // Unlike RandomAccessFileAppender, do not append log when stopped. if (isStopped()) { // Don't try to log anything when appender is stopped return; } // Leverage the nice batching behaviour of async Loggers/Appenders: // we can signal the file manager that it needs to flush the buffer // to disk at the end of a batch. // From a user's point of view, this means that all log events are // _always_ available in the log file, without incurring the overhead // of immediateFlush=true. getManager().setEndOfBatch(event.isEndOfBatch()); // FIXME manager's EndOfBatch threadlocal can be deleted // LOG4J2-1292 utilize gc-free Layout.encode() method: taken care of in superclass super.append(event); }
@SuppressWarnings("deprecation") static void assertEqualLogEvents(final LogEvent expected, final LogEvent actual, final boolean includeSource, final boolean includeContext, final boolean includeStacktrace) { assertEquals(expected.getClass(), actual.getClass()); assertEquals(includeContext ? expected.getContextData() : ContextDataFactory.createContextData(), actual.getContextData()); assertEquals(includeContext ? expected.getContextMap() : Collections.EMPTY_MAP, actual.getContextMap()); assertEquals(expected.getContextStack(), actual.getContextStack()); assertEquals(expected.getLevel(), actual.getLevel()); assertEquals(expected.getLoggerName(), actual.getLoggerName()); assertEquals(expected.getLoggerFqcn(), actual.getLoggerFqcn()); assertEquals(expected.getMarker(), actual.getMarker()); assertEquals(expected.getMessage(), actual.getMessage()); assertEquals(expected.getTimeMillis(), actual.getTimeMillis()); assertEquals(includeSource ? expected.getSource() : null, actual.getSource()); assertEquals(expected.getThreadName(), actual.getThreadName()); assertNotNull("original should have an exception", expected.getThrown()); assertNull("exception should not be serialized", actual.getThrown()); if (includeStacktrace) { // TODO should compare the rest of the ThrowableProxy assertEquals(expected.getThrownProxy(), actual.getThrownProxy()); } assertEquals(expected.isEndOfBatch(), actual.isEndOfBatch()); assertEquals(expected.isIncludeLocation(), actual.isIncludeLocation()); // original: non-null thrown & null thrownProxy // deserialized: null thrown & non-null thrownProxy assertNotEquals(expected.hashCode(), actual.hashCode()); assertNotEquals(expected, actual); }
assertEquals(contextData, e2.getContextData()); assertSame(contextStack, e2.getContextStack()); assertEquals(true, e2.isEndOfBatch()); assertEquals(true, e2.isIncludeLocation()); assertSame(Level.FATAL, e2.getLevel());
assertEquals(true, event2.isEndOfBatch()); assertEquals(true, event2.isIncludeLocation()); assertSame(Level.FATAL, event2.getLevel());
/** * Indicates whether this event is the last one in a batch. Annotated {@link Transient @Transient} so as to not be * included in the persisted entity. * * @return whether this event is the last one in a batch. */ @Override @Transient public final boolean isEndOfBatch() { return this.getWrappedEvent().isEndOfBatch(); }
protected void writeByteArrayToManager(final LogEvent event) { final byte[] bytes = getLayout().toByteArray(event); if (bytes != null && bytes.length > 0) { manager.write(bytes, this.immediateFlush || event.isEndOfBatch()); } } }
protected void directEncodeEvent(final LogEvent event) { getLayout().encode(event, manager); if (this.immediateFlush || event.isEndOfBatch()) { manager.flush(); } }
/** * This method manages buffering and writing of events. * * @param event The event to write to the database. */ public final synchronized void write(final LogEvent event) { if (this.bufferSize > 0) { this.buffer.add(event); if (this.buffer.size() >= this.bufferSize || event.isEndOfBatch()) { this.flush(); } } else { this.connectAndStart(); try { this.writeInternal(event); } finally { this.commitAndClose(); } } }
/** * Write the log entry rolling over the file when required. * * @param event The LogEvent. */ @Override public void append(final LogEvent event) { // Leverage the nice batching behaviour of async Loggers/Appenders: // we can signal the file manager that it needs to flush the buffer // to disk at the end of a batch. // From a user's point of view, this means that all log events are // _always_ available in the log file, without incurring the overhead // of immediateFlush=true. getManager().setEndOfBatch(event.isEndOfBatch()); // FIXME manager's EndOfBatch threadlocal can be deleted // LOG4J2-1292 utilize gc-free Layout.encode() method: taken care of in superclass super.append(event); }
/** * Write the log entry rolling over the file when required. * * @param event The LogEvent. */ @Override public void append(final LogEvent event) { // Leverage the nice batching behaviour of async Loggers/Appenders: // we can signal the file manager that it needs to flush the buffer // to disk at the end of a batch. // From a user's point of view, this means that all log events are // _always_ available in the log file, without incurring the overhead // of immediateFlush=true. getManager().setEndOfBatch(event.isEndOfBatch()); // FIXME manager's EndOfBatch threadlocal can be deleted super.append(event); // TODO should only call force() if immediateFlush && endOfBatch? }
&& !logEvent.isEndOfBatch()) { return;
/** * Actual writing occurs here. * <p> * Most subclasses will need to override this method. * </p> * * @param event * The LogEvent. */ @Override public void append(final LogEvent event) { readLock.lock(); try { final String str = getStringLayout().toSerializable(event); if (str.length() > 0) { manager.write(str); if (this.immediateFlush || event.isEndOfBatch()) { manager.flush(); } } } catch (final AppenderLoggingException ex) { error("Unable to write " + manager.getName() + " for appender " + getName() + ": " + ex); throw ex; } finally { readLock.unlock(); } }
/** * Write the log entry rolling over the file when required. * * @param event The LogEvent. */ @Override public void append(final LogEvent event) { final RollingRandomAccessFileManager manager = getManager(); manager.checkRollover(event); // Leverage the nice batching behaviour of async Loggers/Appenders: // we can signal the file manager that it needs to flush the buffer // to disk at the end of a batch. // From a user's point of view, this means that all log events are // _always_ available in the log file, without incurring the overhead // of immediateFlush=true. manager.setEndOfBatch(event.isEndOfBatch()); // FIXME manager's EndOfBatch threadlocal can be deleted // LOG4J2-1292 utilize gc-free Layout.encode() method: taken care of in superclass super.append(event); }
public LogEventProxy(final LogEvent event, final boolean includeLocation) { this.loggerFQCN = event.getLoggerFqcn(); this.marker = event.getMarker(); this.level = event.getLevel(); this.loggerName = event.getLoggerName(); final Message temp = event.getMessage(); message = temp instanceof ReusableMessage ? memento((ReusableMessage) temp) : temp; this.timeMillis = event.getTimeMillis(); this.thrown = event.getThrown(); this.thrownProxy = event.getThrownProxy(); this.contextData = memento(event.getContextData()); this.contextStack = event.getContextStack(); this.source = includeLocation ? event.getSource() : null; this.threadId = event.getThreadId(); this.threadName = event.getThreadName(); this.threadPriority = event.getThreadPriority(); this.isLocationRequired = includeLocation; this.isEndOfBatch = event.isEndOfBatch(); this.nanoTime = event.getNanoTime(); }
this.contextStack = other.getContextStack(); this.includeLocation = other.isIncludeLocation(); this.endOfBatch = other.isEndOfBatch(); this.nanoTime = other.getNanoTime();
this.threadName = event.getThreadName(); this.threadPriority = event.getThreadPriority(); this.endOfBatch = event.isEndOfBatch(); this.includeLocation = event.isIncludeLocation(); this.nanoTime = event.getNanoTime();