/** * Returns the formatted message. * @return the formatted message. */ @Override public String getFormattedMessage() { final StringBuilder sb = getBuffer(); formatTo(sb); final String result = sb.toString(); StringBuilders.trimToMaxSize(sb, Constants.MAX_REUSABLE_MESSAGE_SIZE); return result; }
/** * Returns the formatted message. * @return the formatted message. */ @Override public String getFormattedMessage() { if (formattedMessage == null) { final StringBuilder buffer = getThreadLocalStringBuilder(); formatTo(buffer); formattedMessage = buffer.toString(); StringBuilders.trimToMaxSize(buffer, Constants.MAX_REUSABLE_MESSAGE_SIZE); } return formattedMessage; }
@Test public void trimToMaxSize() throws Exception { final StringBuilder sb = new StringBuilder(); final char[] value = new char[4 * 1024]; sb.append(value); assertTrue("needs trimming", sb.length() > Constants.MAX_REUSABLE_MESSAGE_SIZE); StringBuilders.trimToMaxSize(sb, Constants.MAX_REUSABLE_MESSAGE_SIZE); assertTrue("trimmed OK", sb.length() <= Constants.MAX_REUSABLE_MESSAGE_SIZE); }
@Test public void trimToMaxSizeWithLargeCapacity() throws Exception { final StringBuilder sb = new StringBuilder(); final char[] value = new char[4 * 1024]; sb.append(value); sb.setLength(0); assertTrue("needs trimming", sb.capacity() > Constants.MAX_REUSABLE_MESSAGE_SIZE); StringBuilders.trimToMaxSize(sb, Constants.MAX_REUSABLE_MESSAGE_SIZE); assertTrue("trimmed OK", sb.capacity() <= Constants.MAX_REUSABLE_MESSAGE_SIZE); }
private static void trimToMaxSize(final StringBuilder stringBuilder) { StringBuilders.trimToMaxSize(stringBuilder, Constants.MAX_REUSABLE_MESSAGE_SIZE); } }
protected static void trimToMaxSize(final StringBuilder stringBuilder) { StringBuilders.trimToMaxSize(stringBuilder, MAX_STRING_BUILDER_SIZE); }
private StringBuilder getStringBuilder() { StringBuilder result = threadLocalStringBuilder.get(); if (result == null) { result = new StringBuilder(); threadLocalStringBuilder.set(result); } StringBuilders.trimToMaxSize(result, MAX_BUFFER_SIZE); result.setLength(0); return result; }
/** * Returns the formatted message. * @return the formatted message. */ @Override public String getFormattedMessage() { final StringBuilder sb = getBuffer(); formatTo(sb); final String result = sb.toString(); StringBuilders.trimToMaxSize(sb, Constants.MAX_REUSABLE_MESSAGE_SIZE); return result; }
/** * Returns the formatted message. * @return the formatted message. */ @Override public String getFormattedMessage() { if (formattedMessage == null) { final StringBuilder buffer = getThreadLocalStringBuilder(); formatTo(buffer); formattedMessage = buffer.toString(); StringBuilders.trimToMaxSize(buffer, Constants.MAX_REUSABLE_MESSAGE_SIZE); } return formattedMessage; }
/** * Release references held by ring buffer to allow objects to be garbage-collected. */ public void clear() { this.asyncLogger = null; this.loggerName = null; this.marker = null; this.fqcn = null; this.level = null; this.message = null; this.thrown = null; this.thrownProxy = null; this.contextStack = null; this.location = null; if (contextData != null) { if (contextData.isFrozen()) { // came from CopyOnWrite thread context contextData = null; } else { contextData.clear(); } } // ensure that excessively long char[] arrays are not kept in memory forever StringBuilders.trimToMaxSize(messageText, Constants.MAX_REUSABLE_MESSAGE_SIZE); if (parameters != null) { for (int i = 0; i < parameters.length; i++) { parameters[i] = null; } } }
StringBuilders.trimToMaxSize(messageText, Constants.MAX_REUSABLE_MESSAGE_SIZE);