public void getMDCCopy() { logRecord.copyMdc(); }
/** * Change an MDC value on this record. If the MDC has not yet been copied, this method will copy it. * * @param key the key to set * @param value the value to set it to * @return the old value, if any */ public String putMdc(String key, String value) { copyMdc(); final Object oldValue = mdcCopy.put(key, value); return oldValue == null ? null : oldValue.toString(); }
/** * Remove an MDC value on this record. If the MDC has not yet been copied, this method will copy it. * * @param key the key to remove * @return the old value, if any */ public String removeMdc(String key) { copyMdc(); final Object oldValue = mdcCopy.remove(key); return oldValue == null ? null : oldValue.toString(); }
/** * Copy all fields and prepare this object to be passed to another thread or to be serialized. Calling this method * more than once has no additional effect and will not incur extra copies. */ public void copyAll() { copyMdc(); calculateCaller(); getFormattedMessage(); }
protected void doPublish(final ExtLogRecord record) { synchronized (buffer) { if (isLoggable(record)) { // 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(); } if (buffer.size() == limit) { buffer.removeFirst(); } buffer.addLast(record); } for (Handler handler : getHandlers()) { handler.publish(record); } } }
@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); } } } }