org.apache.logging.log4j.util.PerformanceSensitive Java Examples
The following examples show how to use
org.apache.logging.log4j.util.PerformanceSensitive.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractLogger.java From logging-log4j2 with Apache License 2.0 | 6 votes |
@PerformanceSensitive // NOTE: This is a hot method. Current implementation compiles to 27 bytes of byte code. // This is within the 35 byte MaxInlineSize threshold. Modify with care! private void tryLogMessage(final String fqcn, final StackTraceElement location, final Level level, final Marker marker, final Message msg, final Throwable throwable) { try { log(level, marker, fqcn, location, msg, throwable); } catch (final Exception e) { // LOG4J2-1990 Log4j2 suppresses all exceptions that occur once application called the logger handleLogMessageException(e, fqcn, msg); } }
Example #2
Source File: MarkerManager.java From logging-log4j2 with Apache License 2.0 | 6 votes |
@PerformanceSensitive("allocation") private static void addParentInfo(final StringBuilder sb, final Marker... parents) { sb.append("[ "); boolean first = true; // noinspection ForLoopReplaceableByForEach for (int i = 0, parentsLength = parents.length; i < parentsLength; i++) { final Marker marker = parents[i]; if (!first) { sb.append(", "); } first = false; sb.append(marker.getName()); final Marker[] p = marker instanceof Log4jMarker ? ((Log4jMarker) marker).parents : marker.getParents(); if (p != null) { addParentInfo(sb, p); } } sb.append(" ]"); }
Example #3
Source File: MarkerManager.java From logging-log4j2 with Apache License 2.0 | 6 votes |
@PerformanceSensitive({"allocation", "unrolled"}) private static boolean checkParent(final Marker parent, final Marker marker) { if (parent == marker) { return true; } final Marker[] localParents = parent instanceof Log4jMarker ? ((Log4jMarker) parent).parents : parent .getParents(); if (localParents != null) { final int localParentsLength = localParents.length; if (localParentsLength == 1) { return checkParent(localParents[0], marker); } if (localParentsLength == 2) { return checkParent(localParents[0], marker) || checkParent(localParents[1], marker); } // noinspection ForLoopReplaceableByForEach for (int i = 0; i < localParentsLength; i++) { final Marker localParent = localParents[i]; if (checkParent(localParent, marker)) { return true; } } } return false; }
Example #4
Source File: MarkerManager.java From logging-log4j2 with Apache License 2.0 | 5 votes |
@PerformanceSensitive("allocation") private static boolean contains(final Marker parent, final Marker... localParents) { // performance tests showed a normal for loop is slightly faster than a for-each loop on some platforms // noinspection ForLoopReplaceableByForEach for (int i = 0, localParentsLength = localParents.length; i < localParentsLength; i++) { final Marker marker = localParents[i]; if (marker == parent) { return true; } } return false; }
Example #5
Source File: LoggerConfig.java From logging-log4j2 with Apache License 2.0 | 5 votes |
@PerformanceSensitive("allocation") protected void callAppenders(final LogEvent event) { final AppenderControl[] controls = appenders.get(); //noinspection ForLoopReplaceableByForEach for (int i = 0; i < controls.length; i++) { controls[i].callAppender(event); } }
Example #6
Source File: LoggerConfig.java From logging-log4j2 with Apache License 2.0 | 5 votes |
/** * Logs an event. * * @param loggerName The name of the Logger. * @param fqcn The fully qualified class name of the caller. * @param location the location of the caller. * @param marker A Marker or null if none is present. * @param level The event Level. * @param data The Message. * @param t A Throwable or null. */ @PerformanceSensitive("allocation") public void log(final String loggerName, final String fqcn, final StackTraceElement location, final Marker marker, final Level level, final Message data, final Throwable t) { List<Property> props = null; if (!propertiesRequireLookup) { props = properties; } else { if (properties != null) { props = new ArrayList<>(properties.size()); final LogEvent event = Log4jLogEvent.newBuilder() .setMessage(data) .setMarker(marker) .setLevel(level) .setLoggerName(loggerName) .setLoggerFqcn(fqcn) .setThrown(t) .build(); for (int i = 0; i < properties.size(); i++) { final Property prop = properties.get(i); final String value = prop.isValueNeedsLookup() // since LOG4J2-1575 ? config.getStrSubstitutor().replace(event, prop.getValue()) // : prop.getValue(); props.add(Property.createProperty(prop.getName(), value)); } } } final LogEvent logEvent = logEventFactory.createEvent(loggerName, marker, fqcn, location, level, data, props, t); try { log(logEvent, LoggerConfigPredicate.ALL); } finally { // LOG4J2-1583 prevent scrambled logs when logging calls are nested (logging in toString()) ReusableLogEventFactory.release(logEvent); } }
Example #7
Source File: LoggerConfig.java From logging-log4j2 with Apache License 2.0 | 5 votes |
/** * Logs an event. * * @param loggerName The name of the Logger. * @param fqcn The fully qualified class name of the caller. * @param marker A Marker or null if none is present. * @param level The event Level. * @param data The Message. * @param t A Throwable or null. */ @PerformanceSensitive("allocation") public void log(final String loggerName, final String fqcn, final Marker marker, final Level level, final Message data, final Throwable t) { List<Property> props = null; if (!propertiesRequireLookup) { props = properties; } else { if (properties != null) { props = new ArrayList<>(properties.size()); final LogEvent event = Log4jLogEvent.newBuilder() .setMessage(data) .setMarker(marker) .setLevel(level) .setLoggerName(loggerName) .setLoggerFqcn(fqcn) .setThrown(t) .build(); for (int i = 0; i < properties.size(); i++) { final Property prop = properties.get(i); final String value = prop.isValueNeedsLookup() // since LOG4J2-1575 ? config.getStrSubstitutor().replace(event, prop.getValue()) // : prop.getValue(); props.add(Property.createProperty(prop.getName(), value)); } } } StackTraceElement location = requiresLocation() ? StackLocatorUtil.calcLocation(fqcn) : null; final LogEvent logEvent = logEventFactory.createEvent(loggerName, marker, fqcn, location, level, data, props, t); try { log(logEvent, LoggerConfigPredicate.ALL); } finally { // LOG4J2-1583 prevent scrambled logs when logging calls are nested (logging in toString()) ReusableLogEventFactory.release(logEvent); } }
Example #8
Source File: AppenderControl.java From logging-log4j2 with Apache License 2.0 | 5 votes |
@PerformanceSensitive private boolean isRecursiveCall() { if (recursive.get() != null) { appenderErrorHandlerMessage("Recursive call to appender "); return true; } return false; }
Example #9
Source File: AbstractStyleNameConverter.java From logging-log4j2 with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override @PerformanceSensitive("allocation") public void format(final LogEvent event, final StringBuilder toAppendTo) { final int start = toAppendTo.length(); for (int i = 0; i < formatters.size(); i++) { final PatternFormatter formatter = formatters.get(i); formatter.format(event, toAppendTo); } if (toAppendTo.length() > start) { toAppendTo.insert(start, style); toAppendTo.append(AnsiEscape.getDefaultStyle()); } }
Example #10
Source File: IbisNdcPatternConverter.java From iaf with Apache License 2.0 | 5 votes |
@Override @PerformanceSensitive("allocation") public void format(final LogEvent event, final StringBuilder toAppendTo) { if(event.getContextStack().isEmpty()) toAppendTo.append("null"); else toAppendTo.append(event.getContextStack()); }
Example #11
Source File: MarkerManager.java From logging-log4j2 with Apache License 2.0 | 5 votes |
@Override @PerformanceSensitive({"allocation", "unrolled"}) public boolean isInstanceOf(final String markerName) { requireNonNull(markerName, "A marker name is required"); if (markerName.equals(this.getName())) { return true; } // Use a real marker for child comparisons. It is faster than comparing the names. final Marker marker = MARKERS.get(markerName); if (marker == null) { return false; } final Marker[] localParents = parents; if (localParents != null) { final int localParentsLength = localParents.length; if (localParentsLength == 1) { return checkParent(localParents[0], marker); } if (localParentsLength == 2) { return checkParent(localParents[0], marker) || checkParent(localParents[1], marker); } // noinspection ForLoopReplaceableByForEach for (int i = 0; i < localParentsLength; i++) { final Marker localParent = localParents[i]; if (checkParent(localParent, marker)) { return true; } } } return false; }
Example #12
Source File: MarkerManager.java From logging-log4j2 with Apache License 2.0 | 5 votes |
@Override @PerformanceSensitive({"allocation", "unrolled"}) public boolean isInstanceOf(final Marker marker) { requireNonNull(marker, "A marker parameter is required"); if (this == marker) { return true; } final Marker[] localParents = parents; if (localParents != null) { // With only one or two parents the for loop is slower. final int localParentsLength = localParents.length; if (localParentsLength == 1) { return checkParent(localParents[0], marker); } if (localParentsLength == 2) { return checkParent(localParents[0], marker) || checkParent(localParents[1], marker); } // noinspection ForLoopReplaceableByForEach for (int i = 0; i < localParentsLength; i++) { final Marker localParent = localParents[i]; if (checkParent(localParent, marker)) { return true; } } } return false; }
Example #13
Source File: AbstractLogger.java From logging-log4j2 with Apache License 2.0 | 5 votes |
@PerformanceSensitive // NOTE: This is a hot method. Current implementation compiles to 33 bytes of byte code. // This is within the 35 byte MaxInlineSize threshold. Modify with care! private void logMessageTrackRecursion(final String fqcn, final Level level, final Marker marker, final Message msg, final Throwable throwable) { try { incrementRecursionDepth(); // LOG4J2-1518, LOG4J2-2031 tryLogMessage(fqcn, getLocation(fqcn), level, marker, msg, throwable); } finally { decrementRecursionDepth(); } }
Example #14
Source File: AbstractLogger.java From logging-log4j2 with Apache License 2.0 | 5 votes |
@PerformanceSensitive // NOTE: This is a hot method. Current implementation compiles to 30 bytes of byte code. // This is within the 35 byte MaxInlineSize threshold. Modify with care! private void logMessageSafely(final String fqcn, final Level level, final Marker marker, final Message msg, final Throwable throwable) { try { logMessageTrackRecursion(fqcn, level, marker, msg, throwable); } finally { // LOG4J2-1583 prevent scrambled logs when logging calls are nested (logging in toString()) ReusableMessageFactory.release(msg); } }
Example #15
Source File: NdcPatternConverter.java From logging-log4j2 with Apache License 2.0 | 4 votes |
@Override @PerformanceSensitive("allocation") public void format(final LogEvent event, final StringBuilder toAppendTo) { toAppendTo.append(event.getContextStack()); }
Example #16
Source File: AppenderControl.java From logging-log4j2 with Apache License 2.0 | 4 votes |
@PerformanceSensitive private boolean isFilteredByAppenderControl(final LogEvent event) { final Filter filter = getFilter(); return filter != null && Filter.Result.DENY == filter.filter(event); }
Example #17
Source File: AppenderControl.java From logging-log4j2 with Apache License 2.0 | 4 votes |
@PerformanceSensitive private boolean isFilteredByLevel(final LogEvent event) { return level != null && intLevel < event.getLevel().intLevel(); }
Example #18
Source File: AbstractLogger.java From logging-log4j2 with Apache License 2.0 | 4 votes |
@PerformanceSensitive // NOTE: This is a hot method. Current implementation compiles to 15 bytes of byte code. // This is within the 35 byte MaxInlineSize threshold. Modify with care! private StackTraceElement getLocation(String fqcn) { return requiresLocation() ? StackLocatorUtil.calcLocation(fqcn) : null; }
Example #19
Source File: AnnotationVsMarkerInterface.java From logging-log4j2 with Apache License 2.0 | 4 votes |
@Benchmark @BenchmarkMode({Mode.Throughput, Mode.AverageTime, Mode.SampleTime, Mode.SingleShotTime}) @OutputTimeUnit(TimeUnit.NANOSECONDS) public Object annotationMissing() { return map.getClass().isAnnotationPresent(PerformanceSensitive.class); }