diff --git a/text-logger-slf4j/src/main/java/net/kyori/adventure/text/logger/slf4j/ComponentLogContextInjector.java b/text-logger-slf4j/src/main/java/net/kyori/adventure/text/logger/slf4j/ComponentLogContextInjector.java new file mode 100644 index 0000000000..d698de0fac --- /dev/null +++ b/text-logger-slf4j/src/main/java/net/kyori/adventure/text/logger/slf4j/ComponentLogContextInjector.java @@ -0,0 +1,55 @@ +/* + * This file is part of adventure, licensed under the MIT License. + * + * Copyright (c) 2017-2025 KyoriPowered + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package net.kyori.adventure.text.logger.slf4j; + +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Injects context for component-aware log calls. + * + * @since 4.27.0 + */ +@ApiStatus.Internal +public interface ComponentLogContextInjector { + /** + * Begin injection of context for a component log record. + * + * @param record the current log record + * @return a scope to close when logging is complete, or {@code null} + * @since 4.27.0 + */ + @Nullable Scope begin(final @NotNull ComponentLogRecord record); + + /** + * A context scope that is closed after a log operation completes. + * + * @since 4.27.0 + */ + interface Scope extends AutoCloseable { + @Override + void close(); + } +} diff --git a/text-logger-slf4j/src/main/java/net/kyori/adventure/text/logger/slf4j/ComponentLogRecord.java b/text-logger-slf4j/src/main/java/net/kyori/adventure/text/logger/slf4j/ComponentLogRecord.java new file mode 100644 index 0000000000..d1ddd9f199 --- /dev/null +++ b/text-logger-slf4j/src/main/java/net/kyori/adventure/text/logger/slf4j/ComponentLogRecord.java @@ -0,0 +1,133 @@ +/* + * This file is part of adventure, licensed under the MIT License. + * + * Copyright (c) 2017-2025 KyoriPowered + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package net.kyori.adventure.text.logger.slf4j; + +import net.kyori.adventure.text.Component; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.slf4j.Marker; +import org.slf4j.event.Level; + +/** + * A single component logger call captured for context injection. + * + * @since 4.27.0 + */ +@ApiStatus.Internal +public final class ComponentLogRecord { + private final @NotNull Level level; + private final @Nullable Marker marker; + private final @Nullable Component componentFormatOrMessage; + private final @Nullable String stringFormatOrMessage; + private final @Nullable Object[] arguments; + private final @Nullable Throwable throwable; + + /** + * Create a new log record for context injection. + * + * @param level the log level + * @param marker the log marker, if any + * @param componentFormatOrMessage the component format or message, if any + * @param stringFormatOrMessage the string format or message, if any + * @param arguments the log arguments, if any + * @param throwable the associated throwable, if any + * @since 4.27.0 + */ + public ComponentLogRecord( + final @NotNull Level level, + final @Nullable Marker marker, + final @Nullable Component componentFormatOrMessage, + final @Nullable String stringFormatOrMessage, + final @Nullable Object[] arguments, + final @Nullable Throwable throwable + ) { + this.level = level; + this.marker = marker; + this.componentFormatOrMessage = componentFormatOrMessage; + this.stringFormatOrMessage = stringFormatOrMessage; + this.arguments = arguments; + this.throwable = throwable; + } + + /** + * Get the level for this record. + * + * @return the log level + * @since 4.27.0 + */ + public @NotNull Level level() { + return this.level; + } + + /** + * Get the marker associated with this record. + * + * @return the marker, if present + * @since 4.27.0 + */ + public @Nullable Marker marker() { + return this.marker; + } + + /** + * Get the component format or message associated with this record. + * + * @return the component format or message, if present + * @since 4.27.0 + */ + public @Nullable Component componentFormatOrMessage() { + return this.componentFormatOrMessage; + } + + /** + * Get the string format or message associated with this record. + * + * @return the string format or message, if present + * @since 4.27.0 + */ + public @Nullable String stringFormatOrMessage() { + return this.stringFormatOrMessage; + } + + /** + * Get the argument array associated with this record. + * + * @return the argument array, if present + * @since 4.27.0 + */ + public @Nullable Object[] arguments() { + return this.arguments; + } + + /** + * Get the throwable associated with this record. + * + * @return the throwable, if present + * @since 4.27.0 + */ + public @Nullable Throwable throwable() { + return this.throwable; + } +} diff --git a/text-logger-slf4j/src/main/java/net/kyori/adventure/text/logger/slf4j/ComponentLoggerProvider.java b/text-logger-slf4j/src/main/java/net/kyori/adventure/text/logger/slf4j/ComponentLoggerProvider.java index e1c86baa15..070b0dac5a 100644 --- a/text-logger-slf4j/src/main/java/net/kyori/adventure/text/logger/slf4j/ComponentLoggerProvider.java +++ b/text-logger-slf4j/src/main/java/net/kyori/adventure/text/logger/slf4j/ComponentLoggerProvider.java @@ -27,6 +27,7 @@ import net.kyori.adventure.text.Component; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; /** @@ -73,5 +74,24 @@ interface LoggerHelper { * @since 4.11.0 */ @NotNull ComponentLogger delegating(final @NotNull Logger base, final @NotNull Function serializer); + + /** + * Create a component logger based on one which delegates to an underlying plain {@link Logger} implementation. + * + *

This overload allows platforms to inject additional structured log context for each log call.

+ * + * @param base the base logger + * @param serializer the serializer to translate and format a component in a log message + * @param injector an optional structured context injector + * @return a new logger + * @since 4.27.0 + */ + default @NotNull ComponentLogger delegating( + final @NotNull Logger base, + final @NotNull Function serializer, + final @Nullable ComponentLogContextInjector injector + ) { + return this.delegating(base, serializer); + } } } diff --git a/text-logger-slf4j/src/main/java/net/kyori/adventure/text/logger/slf4j/Handler.java b/text-logger-slf4j/src/main/java/net/kyori/adventure/text/logger/slf4j/Handler.java index 583dfb04b4..542bb47421 100644 --- a/text-logger-slf4j/src/main/java/net/kyori/adventure/text/logger/slf4j/Handler.java +++ b/text-logger-slf4j/src/main/java/net/kyori/adventure/text/logger/slf4j/Handler.java @@ -32,6 +32,7 @@ import net.kyori.adventure.translation.GlobalTranslator; import net.kyori.adventure.util.Services; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -84,5 +85,14 @@ static final class LoggerHelperImpl implements ComponentLoggerProvider.LoggerHel public @NotNull ComponentLogger delegating(final @NotNull Logger base, final @NotNull Function serializer) { return new WrappingComponentLoggerImpl(base, serializer); } + + @Override + public @NotNull ComponentLogger delegating( + final @NotNull Logger base, + final @NotNull Function serializer, + final @Nullable ComponentLogContextInjector injector + ) { + return new WrappingComponentLoggerImpl(base, serializer, injector); + } } } diff --git a/text-logger-slf4j/src/main/java/net/kyori/adventure/text/logger/slf4j/WrappingComponentLoggerImpl.java b/text-logger-slf4j/src/main/java/net/kyori/adventure/text/logger/slf4j/WrappingComponentLoggerImpl.java index f51ea2965b..8cbcffd5c8 100644 --- a/text-logger-slf4j/src/main/java/net/kyori/adventure/text/logger/slf4j/WrappingComponentLoggerImpl.java +++ b/text-logger-slf4j/src/main/java/net/kyori/adventure/text/logger/slf4j/WrappingComponentLoggerImpl.java @@ -42,11 +42,21 @@ final class WrappingComponentLoggerImpl implements ComponentLogger { private final Logger logger; private final boolean isLocationAware; private final Function serializer; + private final @Nullable ComponentLogContextInjector injector; WrappingComponentLoggerImpl(final Logger backing, final Function serializer) { + this(backing, serializer, null); + } + + WrappingComponentLoggerImpl( + final Logger backing, + final Function serializer, + final @Nullable ComponentLogContextInjector injector + ) { this.serializer = serializer; this.logger = backing; this.isLocationAware = backing instanceof LocationAwareLogger; + this.injector = injector; } private String serialize(final Component input) { @@ -84,6 +94,32 @@ private Object[] maybeSerialize(final @Nullable Object@NotNull... args) { return writable; } + private ComponentLogContextInjector.@Nullable Scope beginContext( + final @NotNull Level level, + final @Nullable Marker marker, + final @Nullable Component componentFormatOrMessage, + final @Nullable String stringFormatOrMessage, + final @Nullable Object[] arguments, + final @Nullable Throwable throwable + ) { + if (this.injector == null) return null; + + try { + return this.injector.begin(new ComponentLogRecord(level, marker, componentFormatOrMessage, stringFormatOrMessage, arguments, throwable)); + } catch (final Throwable ignored) { + return null; + } + } + + private void closeContext(final ComponentLogContextInjector.@Nullable Scope scope) { + if (scope == null) return; + + try { + scope.close(); + } catch (final Throwable ignored) { + } + } + // Basic methods, plain delegation @Override @@ -166,17 +202,22 @@ public boolean isEnabledForLevel(final Level level) { public void trace(final @NotNull String format) { if (!this.isTraceEnabled()) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - null, - FQCN, - LocationAwareLogger.TRACE_INT, - format, - null, - null - ); - } else { - this.logger.trace(format); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.TRACE, null, null, format, null, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + null, + FQCN, + LocationAwareLogger.TRACE_INT, + format, + null, + null + ); + } else { + this.logger.trace(format); + } + } finally { + this.closeContext(scope); } } @@ -184,17 +225,22 @@ public void trace(final @NotNull String format) { public void trace(final @NotNull String format, final @Nullable Object arg) { if (!this.isTraceEnabled()) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - null, - FQCN, - LocationAwareLogger.TRACE_INT, - format, - new Object[] {this.maybeSerialize(arg)}, - null - ); - } else { - this.logger.trace(format, this.maybeSerialize(arg)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.TRACE, null, null, format, new Object[] {arg}, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + null, + FQCN, + LocationAwareLogger.TRACE_INT, + format, + new Object[] {this.maybeSerialize(arg)}, + null + ); + } else { + this.logger.trace(format, this.maybeSerialize(arg)); + } + } finally { + this.closeContext(scope); } } @@ -202,17 +248,22 @@ public void trace(final @NotNull String format, final @Nullable Object arg) { public void trace(final @NotNull String format, final @Nullable Object arg1, final @Nullable Object arg2) { if (!this.isTraceEnabled()) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - null, - FQCN, - LocationAwareLogger.TRACE_INT, - format, - new Object[] {this.maybeSerialize(arg1), this.maybeSerialize(arg2)}, - null - ); - } else { - this.logger.trace(format, this.maybeSerialize(arg1), this.maybeSerialize(arg2)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.TRACE, null, null, format, new Object[] {arg1, arg2}, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + null, + FQCN, + LocationAwareLogger.TRACE_INT, + format, + new Object[] {this.maybeSerialize(arg1), this.maybeSerialize(arg2)}, + null + ); + } else { + this.logger.trace(format, this.maybeSerialize(arg1), this.maybeSerialize(arg2)); + } + } finally { + this.closeContext(scope); } } @@ -220,17 +271,22 @@ public void trace(final @NotNull String format, final @Nullable Object arg1, fin public void trace(final @NotNull String format, final @Nullable Object @NotNull... arguments) { if (!this.isTraceEnabled()) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - null, - FQCN, - LocationAwareLogger.TRACE_INT, - format, - this.maybeSerialize(arguments), - null - ); - } else { - this.logger.trace(format, this.maybeSerialize(arguments)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.TRACE, null, null, format, arguments, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + null, + FQCN, + LocationAwareLogger.TRACE_INT, + format, + this.maybeSerialize(arguments), + null + ); + } else { + this.logger.trace(format, this.maybeSerialize(arguments)); + } + } finally { + this.closeContext(scope); } } @@ -238,17 +294,22 @@ public void trace(final @NotNull String format, final @Nullable Object @NotNull. public void trace(final @NotNull String msg, final @Nullable Throwable t) { if (!this.isTraceEnabled()) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - null, - FQCN, - LocationAwareLogger.TRACE_INT, - msg, - null, - UnpackedComponentThrowable.unpack(t, this.serializer) - ); - } else { - this.logger.trace(msg, UnpackedComponentThrowable.unpack(t, this.serializer)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.TRACE, null, null, msg, null, t); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + null, + FQCN, + LocationAwareLogger.TRACE_INT, + msg, + null, + UnpackedComponentThrowable.unpack(t, this.serializer) + ); + } else { + this.logger.trace(msg, UnpackedComponentThrowable.unpack(t, this.serializer)); + } + } finally { + this.closeContext(scope); } } @@ -256,17 +317,22 @@ public void trace(final @NotNull String msg, final @Nullable Throwable t) { public void trace(final @NotNull Marker marker, final @NotNull String msg) { if (!this.isTraceEnabled(marker)) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - marker, - FQCN, - LocationAwareLogger.TRACE_INT, - msg, - null, - null - ); - } else { - this.logger.trace(marker, msg); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.TRACE, marker, null, msg, null, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + marker, + FQCN, + LocationAwareLogger.TRACE_INT, + msg, + null, + null + ); + } else { + this.logger.trace(marker, msg); + } + } finally { + this.closeContext(scope); } } @@ -274,17 +340,22 @@ public void trace(final @NotNull Marker marker, final @NotNull String msg) { public void trace(final @NotNull Marker marker, final @NotNull String format, final @Nullable Object arg) { if (!this.isTraceEnabled(marker)) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - marker, - FQCN, - LocationAwareLogger.TRACE_INT, - format, - new Object[] {this.maybeSerialize(arg)}, - null - ); - } else { - this.logger.trace(marker, format, this.maybeSerialize(arg)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.TRACE, marker, null, format, new Object[] {arg}, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + marker, + FQCN, + LocationAwareLogger.TRACE_INT, + format, + new Object[] {this.maybeSerialize(arg)}, + null + ); + } else { + this.logger.trace(marker, format, this.maybeSerialize(arg)); + } + } finally { + this.closeContext(scope); } } @@ -292,17 +363,22 @@ public void trace(final @NotNull Marker marker, final @NotNull String format, fi public void trace(final @NotNull Marker marker, final @NotNull String format, final @Nullable Object arg1, final @Nullable Object arg2) { if (!this.isTraceEnabled(marker)) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - marker, - FQCN, - LocationAwareLogger.TRACE_INT, - format, - new Object[] {this.maybeSerialize(arg1), this.maybeSerialize(arg2)}, - null - ); - } else { - this.logger.trace(marker, format, this.maybeSerialize(arg1), this.maybeSerialize(arg2)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.TRACE, marker, null, format, new Object[] {arg1, arg2}, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + marker, + FQCN, + LocationAwareLogger.TRACE_INT, + format, + new Object[] {this.maybeSerialize(arg1), this.maybeSerialize(arg2)}, + null + ); + } else { + this.logger.trace(marker, format, this.maybeSerialize(arg1), this.maybeSerialize(arg2)); + } + } finally { + this.closeContext(scope); } } @@ -310,17 +386,22 @@ public void trace(final @NotNull Marker marker, final @NotNull String format, fi public void trace(final @NotNull Marker marker, final @NotNull String format, final @Nullable Object @NotNull... argArray) { if (!this.isTraceEnabled(marker)) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - marker, - FQCN, - LocationAwareLogger.TRACE_INT, - format, - this.maybeSerialize(argArray), - null - ); - } else { - this.logger.trace(marker, format, this.maybeSerialize(argArray)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.TRACE, marker, null, format, argArray, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + marker, + FQCN, + LocationAwareLogger.TRACE_INT, + format, + this.maybeSerialize(argArray), + null + ); + } else { + this.logger.trace(marker, format, this.maybeSerialize(argArray)); + } + } finally { + this.closeContext(scope); } } @@ -328,17 +409,22 @@ public void trace(final @NotNull Marker marker, final @NotNull String format, fi public void trace(final @NotNull Marker marker, final @NotNull String msg, final @Nullable Throwable t) { if (!this.isTraceEnabled(marker)) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - marker, - FQCN, - LocationAwareLogger.TRACE_INT, - msg, - null, - UnpackedComponentThrowable.unpack(t, this.serializer) - ); - } else { - this.logger.trace(marker, msg, UnpackedComponentThrowable.unpack(t, this.serializer)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.TRACE, marker, null, msg, null, t); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + marker, + FQCN, + LocationAwareLogger.TRACE_INT, + msg, + null, + UnpackedComponentThrowable.unpack(t, this.serializer) + ); + } else { + this.logger.trace(marker, msg, UnpackedComponentThrowable.unpack(t, this.serializer)); + } + } finally { + this.closeContext(scope); } } @@ -346,17 +432,22 @@ public void trace(final @NotNull Marker marker, final @NotNull String msg, final public void debug(final @NotNull String format) { if (!this.isDebugEnabled()) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - null, - FQCN, - LocationAwareLogger.DEBUG_INT, - format, - null, - null - ); - } else { - this.logger.debug(format); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.DEBUG, null, null, format, null, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + null, + FQCN, + LocationAwareLogger.DEBUG_INT, + format, + null, + null + ); + } else { + this.logger.debug(format); + } + } finally { + this.closeContext(scope); } } @@ -364,17 +455,22 @@ public void debug(final @NotNull String format) { public void debug(final @NotNull String format, final @Nullable Object arg) { if (!this.isDebugEnabled()) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - null, - FQCN, - LocationAwareLogger.DEBUG_INT, - format, - new Object[] {this.maybeSerialize(arg)}, - null - ); - } else { - this.logger.debug(format, this.maybeSerialize(arg)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.DEBUG, null, null, format, new Object[] {arg}, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + null, + FQCN, + LocationAwareLogger.DEBUG_INT, + format, + new Object[] {this.maybeSerialize(arg)}, + null + ); + } else { + this.logger.debug(format, this.maybeSerialize(arg)); + } + } finally { + this.closeContext(scope); } } @@ -382,17 +478,22 @@ public void debug(final @NotNull String format, final @Nullable Object arg) { public void debug(final @NotNull String format, final @Nullable Object arg1, final @Nullable Object arg2) { if (!this.isDebugEnabled()) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - null, - FQCN, - LocationAwareLogger.DEBUG_INT, - format, - new Object[] {this.maybeSerialize(arg1), this.maybeSerialize(arg2)}, - null - ); - } else { - this.logger.debug(format, this.maybeSerialize(arg1), this.maybeSerialize(arg2)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.DEBUG, null, null, format, new Object[] {arg1, arg2}, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + null, + FQCN, + LocationAwareLogger.DEBUG_INT, + format, + new Object[] {this.maybeSerialize(arg1), this.maybeSerialize(arg2)}, + null + ); + } else { + this.logger.debug(format, this.maybeSerialize(arg1), this.maybeSerialize(arg2)); + } + } finally { + this.closeContext(scope); } } @@ -400,17 +501,22 @@ public void debug(final @NotNull String format, final @Nullable Object arg1, fin public void debug(final @NotNull String format, final @Nullable Object @NotNull... arguments) { if (!this.isDebugEnabled()) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - null, - FQCN, - LocationAwareLogger.DEBUG_INT, - format, - this.maybeSerialize(arguments), - null - ); - } else { - this.logger.debug(format, this.maybeSerialize(arguments)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.DEBUG, null, null, format, arguments, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + null, + FQCN, + LocationAwareLogger.DEBUG_INT, + format, + this.maybeSerialize(arguments), + null + ); + } else { + this.logger.debug(format, this.maybeSerialize(arguments)); + } + } finally { + this.closeContext(scope); } } @@ -418,17 +524,22 @@ public void debug(final @NotNull String format, final @Nullable Object @NotNull. public void debug(final @NotNull String msg, final @Nullable Throwable t) { if (!this.isDebugEnabled()) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - null, - FQCN, - LocationAwareLogger.DEBUG_INT, - msg, - null, - UnpackedComponentThrowable.unpack(t, this.serializer) - ); - } else { - this.logger.debug(msg, UnpackedComponentThrowable.unpack(t, this.serializer)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.DEBUG, null, null, msg, null, t); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + null, + FQCN, + LocationAwareLogger.DEBUG_INT, + msg, + null, + UnpackedComponentThrowable.unpack(t, this.serializer) + ); + } else { + this.logger.debug(msg, UnpackedComponentThrowable.unpack(t, this.serializer)); + } + } finally { + this.closeContext(scope); } } @@ -436,17 +547,22 @@ public void debug(final @NotNull String msg, final @Nullable Throwable t) { public void debug(final @NotNull Marker marker, final @NotNull String msg) { if (!this.isDebugEnabled(marker)) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - marker, - FQCN, - LocationAwareLogger.DEBUG_INT, - msg, - null, - null - ); - } else { - this.logger.debug(marker, msg); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.DEBUG, marker, null, msg, null, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + marker, + FQCN, + LocationAwareLogger.DEBUG_INT, + msg, + null, + null + ); + } else { + this.logger.debug(marker, msg); + } + } finally { + this.closeContext(scope); } } @@ -454,17 +570,22 @@ public void debug(final @NotNull Marker marker, final @NotNull String msg) { public void debug(final @NotNull Marker marker, final @NotNull String format, final @Nullable Object arg) { if (!this.isDebugEnabled(marker)) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - marker, - FQCN, - LocationAwareLogger.DEBUG_INT, - format, - new Object[] {this.maybeSerialize(arg)}, - null - ); - } else { - this.logger.debug(marker, format, this.maybeSerialize(arg)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.DEBUG, marker, null, format, new Object[] {arg}, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + marker, + FQCN, + LocationAwareLogger.DEBUG_INT, + format, + new Object[] {this.maybeSerialize(arg)}, + null + ); + } else { + this.logger.debug(marker, format, this.maybeSerialize(arg)); + } + } finally { + this.closeContext(scope); } } @@ -472,17 +593,22 @@ public void debug(final @NotNull Marker marker, final @NotNull String format, fi public void debug(final @NotNull Marker marker, final @NotNull String format, final @Nullable Object arg1, final @Nullable Object arg2) { if (!this.isDebugEnabled(marker)) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - marker, - FQCN, - LocationAwareLogger.DEBUG_INT, - format, - new Object[] {this.maybeSerialize(arg1), this.maybeSerialize(arg2)}, - null - ); - } else { - this.logger.debug(marker, format, this.maybeSerialize(arg1), this.maybeSerialize(arg2)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.DEBUG, marker, null, format, new Object[] {arg1, arg2}, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + marker, + FQCN, + LocationAwareLogger.DEBUG_INT, + format, + new Object[] {this.maybeSerialize(arg1), this.maybeSerialize(arg2)}, + null + ); + } else { + this.logger.debug(marker, format, this.maybeSerialize(arg1), this.maybeSerialize(arg2)); + } + } finally { + this.closeContext(scope); } } @@ -490,17 +616,22 @@ public void debug(final @NotNull Marker marker, final @NotNull String format, fi public void debug(final @NotNull Marker marker, final @NotNull String format, final @Nullable Object @NotNull... argArray) { if (!this.isDebugEnabled(marker)) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - marker, - FQCN, - LocationAwareLogger.DEBUG_INT, - format, - this.maybeSerialize(argArray), - null - ); - } else { - this.logger.debug(marker, format, this.maybeSerialize(argArray)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.DEBUG, marker, null, format, argArray, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + marker, + FQCN, + LocationAwareLogger.DEBUG_INT, + format, + this.maybeSerialize(argArray), + null + ); + } else { + this.logger.debug(marker, format, this.maybeSerialize(argArray)); + } + } finally { + this.closeContext(scope); } } @@ -508,17 +639,22 @@ public void debug(final @NotNull Marker marker, final @NotNull String format, fi public void debug(final @NotNull Marker marker, final @NotNull String msg, final @Nullable Throwable t) { if (!this.isDebugEnabled(marker)) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - marker, - FQCN, - LocationAwareLogger.DEBUG_INT, - msg, - null, - UnpackedComponentThrowable.unpack(t, this.serializer) - ); - } else { - this.logger.debug(marker, msg, UnpackedComponentThrowable.unpack(t, this.serializer)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.DEBUG, marker, null, msg, null, t); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + marker, + FQCN, + LocationAwareLogger.DEBUG_INT, + msg, + null, + UnpackedComponentThrowable.unpack(t, this.serializer) + ); + } else { + this.logger.debug(marker, msg, UnpackedComponentThrowable.unpack(t, this.serializer)); + } + } finally { + this.closeContext(scope); } } @@ -526,17 +662,22 @@ public void debug(final @NotNull Marker marker, final @NotNull String msg, final public void info(final @NotNull String format) { if (!this.isInfoEnabled()) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - null, - FQCN, - LocationAwareLogger.INFO_INT, - format, - null, - null - ); - } else { - this.logger.info(format); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.INFO, null, null, format, null, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + null, + FQCN, + LocationAwareLogger.INFO_INT, + format, + null, + null + ); + } else { + this.logger.info(format); + } + } finally { + this.closeContext(scope); } } @@ -544,17 +685,22 @@ public void info(final @NotNull String format) { public void info(final @NotNull String format, final @Nullable Object arg) { if (!this.isInfoEnabled()) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - null, - FQCN, - LocationAwareLogger.INFO_INT, - format, - new Object[] {this.maybeSerialize(arg)}, - null - ); - } else { - this.logger.info(format, this.maybeSerialize(arg)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.INFO, null, null, format, new Object[] {arg}, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + null, + FQCN, + LocationAwareLogger.INFO_INT, + format, + new Object[] {this.maybeSerialize(arg)}, + null + ); + } else { + this.logger.info(format, this.maybeSerialize(arg)); + } + } finally { + this.closeContext(scope); } } @@ -562,17 +708,22 @@ public void info(final @NotNull String format, final @Nullable Object arg) { public void info(final @NotNull String format, final @Nullable Object arg1, final @Nullable Object arg2) { if (!this.isInfoEnabled()) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - null, - FQCN, - LocationAwareLogger.INFO_INT, - format, - new Object[] {this.maybeSerialize(arg1), this.maybeSerialize(arg2)}, - null - ); - } else { - this.logger.info(format, this.maybeSerialize(arg1), this.maybeSerialize(arg2)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.INFO, null, null, format, new Object[] {arg1, arg2}, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + null, + FQCN, + LocationAwareLogger.INFO_INT, + format, + new Object[] {this.maybeSerialize(arg1), this.maybeSerialize(arg2)}, + null + ); + } else { + this.logger.info(format, this.maybeSerialize(arg1), this.maybeSerialize(arg2)); + } + } finally { + this.closeContext(scope); } } @@ -580,17 +731,22 @@ public void info(final @NotNull String format, final @Nullable Object arg1, fina public void info(final @NotNull String format, final @Nullable Object @NotNull... arguments) { if (!this.isInfoEnabled()) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - null, - FQCN, - LocationAwareLogger.INFO_INT, - format, - this.maybeSerialize(arguments), - null - ); - } else { - this.logger.info(format, this.maybeSerialize(arguments)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.INFO, null, null, format, arguments, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + null, + FQCN, + LocationAwareLogger.INFO_INT, + format, + this.maybeSerialize(arguments), + null + ); + } else { + this.logger.info(format, this.maybeSerialize(arguments)); + } + } finally { + this.closeContext(scope); } } @@ -598,17 +754,22 @@ public void info(final @NotNull String format, final @Nullable Object @NotNull.. public void info(final @NotNull String msg, final @Nullable Throwable t) { if (!this.isInfoEnabled()) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - null, - FQCN, - LocationAwareLogger.INFO_INT, - msg, - null, - UnpackedComponentThrowable.unpack(t, this.serializer) - ); - } else { - this.logger.info(msg, UnpackedComponentThrowable.unpack(t, this.serializer)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.INFO, null, null, msg, null, t); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + null, + FQCN, + LocationAwareLogger.INFO_INT, + msg, + null, + UnpackedComponentThrowable.unpack(t, this.serializer) + ); + } else { + this.logger.info(msg, UnpackedComponentThrowable.unpack(t, this.serializer)); + } + } finally { + this.closeContext(scope); } } @@ -616,17 +777,22 @@ public void info(final @NotNull String msg, final @Nullable Throwable t) { public void info(final @NotNull Marker marker, final @NotNull String msg) { if (!this.isInfoEnabled(marker)) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - marker, - FQCN, - LocationAwareLogger.INFO_INT, - msg, - null, - null - ); - } else { - this.logger.info(marker, msg); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.INFO, marker, null, msg, null, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + marker, + FQCN, + LocationAwareLogger.INFO_INT, + msg, + null, + null + ); + } else { + this.logger.info(marker, msg); + } + } finally { + this.closeContext(scope); } } @@ -634,17 +800,22 @@ public void info(final @NotNull Marker marker, final @NotNull String msg) { public void info(final @NotNull Marker marker, final @NotNull String format, final @Nullable Object arg) { if (!this.isInfoEnabled(marker)) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - marker, - FQCN, - LocationAwareLogger.INFO_INT, - format, - new Object[] {this.maybeSerialize(arg)}, - null - ); - } else { - this.logger.info(marker, format, this.maybeSerialize(arg)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.INFO, marker, null, format, new Object[] {arg}, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + marker, + FQCN, + LocationAwareLogger.INFO_INT, + format, + new Object[] {this.maybeSerialize(arg)}, + null + ); + } else { + this.logger.info(marker, format, this.maybeSerialize(arg)); + } + } finally { + this.closeContext(scope); } } @@ -652,17 +823,22 @@ public void info(final @NotNull Marker marker, final @NotNull String format, fin public void info(final @NotNull Marker marker, final @NotNull String format, final @Nullable Object arg1, final @Nullable Object arg2) { if (!this.isInfoEnabled(marker)) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - marker, - FQCN, - LocationAwareLogger.INFO_INT, - format, - new Object[] {this.maybeSerialize(arg1), this.maybeSerialize(arg2)}, - null - ); - } else { - this.logger.info(marker, format, this.maybeSerialize(arg1), this.maybeSerialize(arg2)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.INFO, marker, null, format, new Object[] {arg1, arg2}, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + marker, + FQCN, + LocationAwareLogger.INFO_INT, + format, + new Object[] {this.maybeSerialize(arg1), this.maybeSerialize(arg2)}, + null + ); + } else { + this.logger.info(marker, format, this.maybeSerialize(arg1), this.maybeSerialize(arg2)); + } + } finally { + this.closeContext(scope); } } @@ -670,17 +846,22 @@ public void info(final @NotNull Marker marker, final @NotNull String format, fin public void info(final @NotNull Marker marker, final @NotNull String format, final @Nullable Object @NotNull... argArray) { if (!this.isInfoEnabled(marker)) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - marker, - FQCN, - LocationAwareLogger.INFO_INT, - format, - this.maybeSerialize(argArray), - null - ); - } else { - this.logger.info(marker, format, this.maybeSerialize(argArray)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.INFO, marker, null, format, argArray, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + marker, + FQCN, + LocationAwareLogger.INFO_INT, + format, + this.maybeSerialize(argArray), + null + ); + } else { + this.logger.info(marker, format, this.maybeSerialize(argArray)); + } + } finally { + this.closeContext(scope); } } @@ -688,17 +869,22 @@ public void info(final @NotNull Marker marker, final @NotNull String format, fin public void info(final @NotNull Marker marker, final @NotNull String msg, final @Nullable Throwable t) { if (!this.isInfoEnabled(marker)) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - marker, - FQCN, - LocationAwareLogger.INFO_INT, - msg, - null, - UnpackedComponentThrowable.unpack(t, this.serializer) - ); - } else { - this.logger.info(marker, msg, UnpackedComponentThrowable.unpack(t, this.serializer)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.INFO, marker, null, msg, null, t); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + marker, + FQCN, + LocationAwareLogger.INFO_INT, + msg, + null, + UnpackedComponentThrowable.unpack(t, this.serializer) + ); + } else { + this.logger.info(marker, msg, UnpackedComponentThrowable.unpack(t, this.serializer)); + } + } finally { + this.closeContext(scope); } } @@ -706,17 +892,22 @@ public void info(final @NotNull Marker marker, final @NotNull String msg, final public void warn(final @NotNull String format) { if (!this.isWarnEnabled()) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - null, - FQCN, - LocationAwareLogger.WARN_INT, - format, - null, - null - ); - } else { - this.logger.warn(format); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.WARN, null, null, format, null, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + null, + FQCN, + LocationAwareLogger.WARN_INT, + format, + null, + null + ); + } else { + this.logger.warn(format); + } + } finally { + this.closeContext(scope); } } @@ -724,17 +915,22 @@ public void warn(final @NotNull String format) { public void warn(final @NotNull String format, final @Nullable Object arg) { if (!this.isWarnEnabled()) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - null, - FQCN, - LocationAwareLogger.WARN_INT, - format, - new Object[] {this.maybeSerialize(arg)}, - null - ); - } else { - this.logger.warn(format, this.maybeSerialize(arg)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.WARN, null, null, format, new Object[] {arg}, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + null, + FQCN, + LocationAwareLogger.WARN_INT, + format, + new Object[] {this.maybeSerialize(arg)}, + null + ); + } else { + this.logger.warn(format, this.maybeSerialize(arg)); + } + } finally { + this.closeContext(scope); } } @@ -742,17 +938,22 @@ public void warn(final @NotNull String format, final @Nullable Object arg) { public void warn(final @NotNull String format, final @Nullable Object arg1, final @Nullable Object arg2) { if (!this.isWarnEnabled()) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - null, - FQCN, - LocationAwareLogger.WARN_INT, - format, - new Object[] {this.maybeSerialize(arg1), this.maybeSerialize(arg2)}, - null - ); - } else { - this.logger.warn(format, this.maybeSerialize(arg1), this.maybeSerialize(arg2)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.WARN, null, null, format, new Object[] {arg1, arg2}, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + null, + FQCN, + LocationAwareLogger.WARN_INT, + format, + new Object[] {this.maybeSerialize(arg1), this.maybeSerialize(arg2)}, + null + ); + } else { + this.logger.warn(format, this.maybeSerialize(arg1), this.maybeSerialize(arg2)); + } + } finally { + this.closeContext(scope); } } @@ -760,17 +961,22 @@ public void warn(final @NotNull String format, final @Nullable Object arg1, fina public void warn(final @NotNull String format, final @Nullable Object @NotNull... arguments) { if (!this.isWarnEnabled()) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - null, - FQCN, - LocationAwareLogger.WARN_INT, - format, - this.maybeSerialize(arguments), - null - ); - } else { - this.logger.warn(format, this.maybeSerialize(arguments)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.WARN, null, null, format, arguments, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + null, + FQCN, + LocationAwareLogger.WARN_INT, + format, + this.maybeSerialize(arguments), + null + ); + } else { + this.logger.warn(format, this.maybeSerialize(arguments)); + } + } finally { + this.closeContext(scope); } } @@ -778,17 +984,22 @@ public void warn(final @NotNull String format, final @Nullable Object @NotNull.. public void warn(final @NotNull String msg, final @Nullable Throwable t) { if (!this.isWarnEnabled()) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - null, - FQCN, - LocationAwareLogger.WARN_INT, - msg, - null, - UnpackedComponentThrowable.unpack(t, this.serializer) - ); - } else { - this.logger.warn(msg, UnpackedComponentThrowable.unpack(t, this.serializer)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.WARN, null, null, msg, null, t); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + null, + FQCN, + LocationAwareLogger.WARN_INT, + msg, + null, + UnpackedComponentThrowable.unpack(t, this.serializer) + ); + } else { + this.logger.warn(msg, UnpackedComponentThrowable.unpack(t, this.serializer)); + } + } finally { + this.closeContext(scope); } } @@ -796,17 +1007,22 @@ public void warn(final @NotNull String msg, final @Nullable Throwable t) { public void warn(final @NotNull Marker marker, final @NotNull String msg) { if (!this.isWarnEnabled(marker)) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - marker, - FQCN, - LocationAwareLogger.WARN_INT, - msg, - null, - null - ); - } else { - this.logger.warn(marker, msg); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.WARN, marker, null, msg, null, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + marker, + FQCN, + LocationAwareLogger.WARN_INT, + msg, + null, + null + ); + } else { + this.logger.warn(marker, msg); + } + } finally { + this.closeContext(scope); } } @@ -814,17 +1030,22 @@ public void warn(final @NotNull Marker marker, final @NotNull String msg) { public void warn(final @NotNull Marker marker, final @NotNull String format, final @Nullable Object arg) { if (!this.isWarnEnabled(marker)) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - marker, - FQCN, - LocationAwareLogger.WARN_INT, - format, - new Object[] {this.maybeSerialize(arg)}, - null - ); - } else { - this.logger.warn(marker, format, this.maybeSerialize(arg)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.WARN, marker, null, format, new Object[] {arg}, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + marker, + FQCN, + LocationAwareLogger.WARN_INT, + format, + new Object[] {this.maybeSerialize(arg)}, + null + ); + } else { + this.logger.warn(marker, format, this.maybeSerialize(arg)); + } + } finally { + this.closeContext(scope); } } @@ -832,17 +1053,22 @@ public void warn(final @NotNull Marker marker, final @NotNull String format, fin public void warn(final @NotNull Marker marker, final @NotNull String format, final @Nullable Object arg1, final @Nullable Object arg2) { if (!this.isWarnEnabled(marker)) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - marker, - FQCN, - LocationAwareLogger.WARN_INT, - format, - new Object[] {this.maybeSerialize(arg1), this.maybeSerialize(arg2)}, - null - ); - } else { - this.logger.warn(marker, format, this.maybeSerialize(arg1), this.maybeSerialize(arg2)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.WARN, marker, null, format, new Object[] {arg1, arg2}, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + marker, + FQCN, + LocationAwareLogger.WARN_INT, + format, + new Object[] {this.maybeSerialize(arg1), this.maybeSerialize(arg2)}, + null + ); + } else { + this.logger.warn(marker, format, this.maybeSerialize(arg1), this.maybeSerialize(arg2)); + } + } finally { + this.closeContext(scope); } } @@ -850,17 +1076,22 @@ public void warn(final @NotNull Marker marker, final @NotNull String format, fin public void warn(final @NotNull Marker marker, final @NotNull String format, final @Nullable Object @NotNull... argArray) { if (!this.isWarnEnabled(marker)) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - marker, - FQCN, - LocationAwareLogger.WARN_INT, - format, - this.maybeSerialize(argArray), - null - ); - } else { - this.logger.warn(marker, format, this.maybeSerialize(argArray)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.WARN, marker, null, format, argArray, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + marker, + FQCN, + LocationAwareLogger.WARN_INT, + format, + this.maybeSerialize(argArray), + null + ); + } else { + this.logger.warn(marker, format, this.maybeSerialize(argArray)); + } + } finally { + this.closeContext(scope); } } @@ -868,17 +1099,22 @@ public void warn(final @NotNull Marker marker, final @NotNull String format, fin public void warn(final @NotNull Marker marker, final @NotNull String msg, final @Nullable Throwable t) { if (!this.isWarnEnabled(marker)) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - marker, - FQCN, - LocationAwareLogger.WARN_INT, - msg, - null, - UnpackedComponentThrowable.unpack(t, this.serializer) - ); - } else { - this.logger.warn(marker, msg, UnpackedComponentThrowable.unpack(t, this.serializer)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.WARN, marker, null, msg, null, t); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + marker, + FQCN, + LocationAwareLogger.WARN_INT, + msg, + null, + UnpackedComponentThrowable.unpack(t, this.serializer) + ); + } else { + this.logger.warn(marker, msg, UnpackedComponentThrowable.unpack(t, this.serializer)); + } + } finally { + this.closeContext(scope); } } @@ -886,17 +1122,22 @@ public void warn(final @NotNull Marker marker, final @NotNull String msg, final public void error(final @NotNull String format) { if (!this.isErrorEnabled()) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - null, - FQCN, - LocationAwareLogger.ERROR_INT, - format, - null, - null - ); - } else { - this.logger.error(format); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.ERROR, null, null, format, null, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + null, + FQCN, + LocationAwareLogger.ERROR_INT, + format, + null, + null + ); + } else { + this.logger.error(format); + } + } finally { + this.closeContext(scope); } } @@ -904,17 +1145,22 @@ public void error(final @NotNull String format) { public void error(final @NotNull String format, final @Nullable Object arg) { if (!this.isErrorEnabled()) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - null, - FQCN, - LocationAwareLogger.ERROR_INT, - format, - new Object[] {this.maybeSerialize(arg)}, - null - ); - } else { - this.logger.error(format, this.maybeSerialize(arg)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.ERROR, null, null, format, new Object[] {arg}, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + null, + FQCN, + LocationAwareLogger.ERROR_INT, + format, + new Object[] {this.maybeSerialize(arg)}, + null + ); + } else { + this.logger.error(format, this.maybeSerialize(arg)); + } + } finally { + this.closeContext(scope); } } @@ -922,17 +1168,22 @@ public void error(final @NotNull String format, final @Nullable Object arg) { public void error(final @NotNull String format, final @Nullable Object arg1, final @Nullable Object arg2) { if (!this.isErrorEnabled()) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - null, - FQCN, - LocationAwareLogger.ERROR_INT, - format, - new Object[] {this.maybeSerialize(arg1), this.maybeSerialize(arg2)}, - null - ); - } else { - this.logger.error(format, this.maybeSerialize(arg1), this.maybeSerialize(arg2)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.ERROR, null, null, format, new Object[] {arg1, arg2}, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + null, + FQCN, + LocationAwareLogger.ERROR_INT, + format, + new Object[] {this.maybeSerialize(arg1), this.maybeSerialize(arg2)}, + null + ); + } else { + this.logger.error(format, this.maybeSerialize(arg1), this.maybeSerialize(arg2)); + } + } finally { + this.closeContext(scope); } } @@ -940,17 +1191,22 @@ public void error(final @NotNull String format, final @Nullable Object arg1, fin public void error(final @NotNull String format, final @Nullable Object @NotNull... arguments) { if (!this.isErrorEnabled()) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - null, - FQCN, - LocationAwareLogger.ERROR_INT, - format, - this.maybeSerialize(arguments), - null - ); - } else { - this.logger.error(format, this.maybeSerialize(arguments)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.ERROR, null, null, format, arguments, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + null, + FQCN, + LocationAwareLogger.ERROR_INT, + format, + this.maybeSerialize(arguments), + null + ); + } else { + this.logger.error(format, this.maybeSerialize(arguments)); + } + } finally { + this.closeContext(scope); } } @@ -958,17 +1214,22 @@ public void error(final @NotNull String format, final @Nullable Object @NotNull. public void error(final @NotNull String msg, final @Nullable Throwable t) { if (!this.isErrorEnabled()) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - null, - FQCN, - LocationAwareLogger.ERROR_INT, - msg, - null, - UnpackedComponentThrowable.unpack(t, this.serializer) - ); - } else { - this.logger.error(msg, UnpackedComponentThrowable.unpack(t, this.serializer)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.ERROR, null, null, msg, null, t); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + null, + FQCN, + LocationAwareLogger.ERROR_INT, + msg, + null, + UnpackedComponentThrowable.unpack(t, this.serializer) + ); + } else { + this.logger.error(msg, UnpackedComponentThrowable.unpack(t, this.serializer)); + } + } finally { + this.closeContext(scope); } } @@ -976,17 +1237,22 @@ public void error(final @NotNull String msg, final @Nullable Throwable t) { public void error(final @NotNull Marker marker, final @NotNull String msg) { if (!this.isErrorEnabled(marker)) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - marker, - FQCN, - LocationAwareLogger.ERROR_INT, - msg, - null, - null - ); - } else { - this.logger.error(marker, msg); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.ERROR, marker, null, msg, null, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + marker, + FQCN, + LocationAwareLogger.ERROR_INT, + msg, + null, + null + ); + } else { + this.logger.error(marker, msg); + } + } finally { + this.closeContext(scope); } } @@ -994,17 +1260,22 @@ public void error(final @NotNull Marker marker, final @NotNull String msg) { public void error(final @NotNull Marker marker, final @NotNull String format, final @Nullable Object arg) { if (!this.isErrorEnabled(marker)) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - marker, - FQCN, - LocationAwareLogger.ERROR_INT, - format, - new Object[] {this.maybeSerialize(arg)}, - null - ); - } else { - this.logger.error(marker, format, this.maybeSerialize(arg)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.ERROR, marker, null, format, new Object[] {arg}, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + marker, + FQCN, + LocationAwareLogger.ERROR_INT, + format, + new Object[] {this.maybeSerialize(arg)}, + null + ); + } else { + this.logger.error(marker, format, this.maybeSerialize(arg)); + } + } finally { + this.closeContext(scope); } } @@ -1012,17 +1283,22 @@ public void error(final @NotNull Marker marker, final @NotNull String format, fi public void error(final @NotNull Marker marker, final @NotNull String format, final @Nullable Object arg1, final @Nullable Object arg2) { if (!this.isErrorEnabled(marker)) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - marker, - FQCN, - LocationAwareLogger.ERROR_INT, - format, - new Object[] {this.maybeSerialize(arg1), this.maybeSerialize(arg2)}, - null - ); - } else { - this.logger.error(marker, format, this.maybeSerialize(arg1), this.maybeSerialize(arg2)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.ERROR, marker, null, format, new Object[] {arg1, arg2}, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + marker, + FQCN, + LocationAwareLogger.ERROR_INT, + format, + new Object[] {this.maybeSerialize(arg1), this.maybeSerialize(arg2)}, + null + ); + } else { + this.logger.error(marker, format, this.maybeSerialize(arg1), this.maybeSerialize(arg2)); + } + } finally { + this.closeContext(scope); } } @@ -1030,17 +1306,22 @@ public void error(final @NotNull Marker marker, final @NotNull String format, fi public void error(final @NotNull Marker marker, final @NotNull String format, final @Nullable Object @NotNull... argArray) { if (!this.isErrorEnabled(marker)) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - marker, - FQCN, - LocationAwareLogger.ERROR_INT, - format, - this.maybeSerialize(argArray), - null - ); - } else { - this.logger.error(marker, format, this.maybeSerialize(argArray)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.ERROR, marker, null, format, argArray, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + marker, + FQCN, + LocationAwareLogger.ERROR_INT, + format, + this.maybeSerialize(argArray), + null + ); + } else { + this.logger.error(marker, format, this.maybeSerialize(argArray)); + } + } finally { + this.closeContext(scope); } } @@ -1048,37 +1329,47 @@ public void error(final @NotNull Marker marker, final @NotNull String format, fi public void error(final @NotNull Marker marker, final @NotNull String msg, final @Nullable Throwable t) { if (!this.isErrorEnabled(marker)) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - marker, - FQCN, - LocationAwareLogger.ERROR_INT, - msg, - null, - UnpackedComponentThrowable.unpack(t, this.serializer) - ); - } else { - this.logger.error(marker, msg, UnpackedComponentThrowable.unpack(t, this.serializer)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.ERROR, marker, null, msg, null, t); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + marker, + FQCN, + LocationAwareLogger.ERROR_INT, + msg, + null, + UnpackedComponentThrowable.unpack(t, this.serializer) + ); + } else { + this.logger.error(marker, msg, UnpackedComponentThrowable.unpack(t, this.serializer)); + } + } finally { + this.closeContext(scope); } } - // Component-primary methods + // Component methods @Override public void trace(final @NotNull Component format) { if (!this.isTraceEnabled()) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - null, - FQCN, - LocationAwareLogger.TRACE_INT, - this.serialize(format), - null, - null - ); - } else { - this.logger.trace(this.serialize(format)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.TRACE, null, format, null, null, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + null, + FQCN, + LocationAwareLogger.TRACE_INT, + this.serialize(format), + null, + null + ); + } else { + this.logger.trace(this.serialize(format)); + } + } finally { + this.closeContext(scope); } } @@ -1086,17 +1377,22 @@ public void trace(final @NotNull Component format) { public void trace(final @NotNull Component format, final @Nullable Object arg) { if (!this.isTraceEnabled()) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - null, - FQCN, - LocationAwareLogger.TRACE_INT, - this.serialize(format), - new Object[] {this.maybeSerialize(arg)}, - null - ); - } else { - this.logger.trace(this.serialize(format), this.maybeSerialize(arg)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.TRACE, null, format, null, new Object[] {arg}, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + null, + FQCN, + LocationAwareLogger.TRACE_INT, + this.serialize(format), + new Object[] {this.maybeSerialize(arg)}, + null + ); + } else { + this.logger.trace(this.serialize(format), this.maybeSerialize(arg)); + } + } finally { + this.closeContext(scope); } } @@ -1104,17 +1400,22 @@ public void trace(final @NotNull Component format, final @Nullable Object arg) { public void trace(final @NotNull Component format, final @Nullable Object arg1, final @Nullable Object arg2) { if (!this.isTraceEnabled()) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - null, - FQCN, - LocationAwareLogger.TRACE_INT, - this.serialize(format), - new Object[] {this.maybeSerialize(arg1), this.maybeSerialize(arg2)}, - null - ); - } else { - this.logger.trace(this.serialize(format), this.maybeSerialize(arg1), this.maybeSerialize(arg2)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.TRACE, null, format, null, new Object[] {arg1, arg2}, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + null, + FQCN, + LocationAwareLogger.TRACE_INT, + this.serialize(format), + new Object[] {this.maybeSerialize(arg1), this.maybeSerialize(arg2)}, + null + ); + } else { + this.logger.trace(this.serialize(format), this.maybeSerialize(arg1), this.maybeSerialize(arg2)); + } + } finally { + this.closeContext(scope); } } @@ -1122,17 +1423,22 @@ public void trace(final @NotNull Component format, final @Nullable Object arg1, public void trace(final @NotNull Component format, final @Nullable Object @NotNull... arguments) { if (!this.isTraceEnabled()) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - null, - FQCN, - LocationAwareLogger.TRACE_INT, - this.serialize(format), - this.maybeSerialize(arguments), - null - ); - } else { - this.logger.trace(this.serialize(format), this.maybeSerialize(arguments)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.TRACE, null, format, null, arguments, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + null, + FQCN, + LocationAwareLogger.TRACE_INT, + this.serialize(format), + this.maybeSerialize(arguments), + null + ); + } else { + this.logger.trace(this.serialize(format), this.maybeSerialize(arguments)); + } + } finally { + this.closeContext(scope); } } @@ -1140,17 +1446,22 @@ public void trace(final @NotNull Component format, final @Nullable Object @NotNu public void trace(final @NotNull Component msg, final @Nullable Throwable t) { if (!this.isTraceEnabled()) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - null, - FQCN, - LocationAwareLogger.TRACE_INT, - this.serialize(msg), - null, - UnpackedComponentThrowable.unpack(t, this.serializer) - ); - } else { - this.logger.trace(this.serialize(msg), UnpackedComponentThrowable.unpack(t, this.serializer)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.TRACE, null, msg, null, null, t); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + null, + FQCN, + LocationAwareLogger.TRACE_INT, + this.serialize(msg), + null, + UnpackedComponentThrowable.unpack(t, this.serializer) + ); + } else { + this.logger.trace(this.serialize(msg), UnpackedComponentThrowable.unpack(t, this.serializer)); + } + } finally { + this.closeContext(scope); } } @@ -1158,17 +1469,22 @@ public void trace(final @NotNull Component msg, final @Nullable Throwable t) { public void trace(final @NotNull Marker marker, final @NotNull Component msg) { if (!this.isTraceEnabled(marker)) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - marker, - FQCN, - LocationAwareLogger.TRACE_INT, - this.serialize(msg), - null, - null - ); - } else { - this.logger.trace(marker, this.serialize(msg)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.TRACE, marker, msg, null, null, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + marker, + FQCN, + LocationAwareLogger.TRACE_INT, + this.serialize(msg), + null, + null + ); + } else { + this.logger.trace(marker, this.serialize(msg)); + } + } finally { + this.closeContext(scope); } } @@ -1176,17 +1492,22 @@ public void trace(final @NotNull Marker marker, final @NotNull Component msg) { public void trace(final @NotNull Marker marker, final @NotNull Component format, final @Nullable Object arg) { if (!this.isTraceEnabled(marker)) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - marker, - FQCN, - LocationAwareLogger.TRACE_INT, - this.serialize(format), - new Object[] {this.maybeSerialize(arg)}, - null - ); - } else { - this.logger.trace(marker, this.serialize(format), this.maybeSerialize(arg)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.TRACE, marker, format, null, new Object[] {arg}, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + marker, + FQCN, + LocationAwareLogger.TRACE_INT, + this.serialize(format), + new Object[] {this.maybeSerialize(arg)}, + null + ); + } else { + this.logger.trace(marker, this.serialize(format), this.maybeSerialize(arg)); + } + } finally { + this.closeContext(scope); } } @@ -1194,17 +1515,22 @@ public void trace(final @NotNull Marker marker, final @NotNull Component format, public void trace(final @NotNull Marker marker, final @NotNull Component format, final @Nullable Object arg1, final @Nullable Object arg2) { if (!this.isTraceEnabled(marker)) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - marker, - FQCN, - LocationAwareLogger.TRACE_INT, - this.serialize(format), - new Object[] {this.maybeSerialize(arg1), this.maybeSerialize(arg2)}, - null - ); - } else { - this.logger.trace(marker, this.serialize(format), this.maybeSerialize(arg1), this.maybeSerialize(arg2)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.TRACE, marker, format, null, new Object[] {arg1, arg2}, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + marker, + FQCN, + LocationAwareLogger.TRACE_INT, + this.serialize(format), + new Object[] {this.maybeSerialize(arg1), this.maybeSerialize(arg2)}, + null + ); + } else { + this.logger.trace(marker, this.serialize(format), this.maybeSerialize(arg1), this.maybeSerialize(arg2)); + } + } finally { + this.closeContext(scope); } } @@ -1212,17 +1538,22 @@ public void trace(final @NotNull Marker marker, final @NotNull Component format, public void trace(final @NotNull Marker marker, final @NotNull Component format, final @Nullable Object @NotNull... argArray) { if (!this.isTraceEnabled(marker)) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - marker, - FQCN, - LocationAwareLogger.TRACE_INT, - this.serialize(format), - this.maybeSerialize(argArray), - null - ); - } else { - this.logger.trace(marker, this.serialize(format), this.maybeSerialize(argArray)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.TRACE, marker, format, null, argArray, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + marker, + FQCN, + LocationAwareLogger.TRACE_INT, + this.serialize(format), + this.maybeSerialize(argArray), + null + ); + } else { + this.logger.trace(marker, this.serialize(format), this.maybeSerialize(argArray)); + } + } finally { + this.closeContext(scope); } } @@ -1230,17 +1561,22 @@ public void trace(final @NotNull Marker marker, final @NotNull Component format, public void trace(final @NotNull Marker marker, final @NotNull Component msg, final @Nullable Throwable t) { if (!this.isTraceEnabled(marker)) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - marker, - FQCN, - LocationAwareLogger.TRACE_INT, - this.serialize(msg), - null, - UnpackedComponentThrowable.unpack(t, this.serializer) - ); - } else { - this.logger.trace(marker, this.serialize(msg), UnpackedComponentThrowable.unpack(t, this.serializer)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.TRACE, marker, msg, null, null, t); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + marker, + FQCN, + LocationAwareLogger.TRACE_INT, + this.serialize(msg), + null, + UnpackedComponentThrowable.unpack(t, this.serializer) + ); + } else { + this.logger.trace(marker, this.serialize(msg), UnpackedComponentThrowable.unpack(t, this.serializer)); + } + } finally { + this.closeContext(scope); } } @@ -1248,17 +1584,22 @@ public void trace(final @NotNull Marker marker, final @NotNull Component msg, fi public void debug(final @NotNull Component format) { if (!this.isDebugEnabled()) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - null, - FQCN, - LocationAwareLogger.DEBUG_INT, - this.serialize(format), - null, - null - ); - } else { - this.logger.debug(this.serialize(format)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.DEBUG, null, format, null, null, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + null, + FQCN, + LocationAwareLogger.DEBUG_INT, + this.serialize(format), + null, + null + ); + } else { + this.logger.debug(this.serialize(format)); + } + } finally { + this.closeContext(scope); } } @@ -1266,17 +1607,22 @@ public void debug(final @NotNull Component format) { public void debug(final @NotNull Component format, final @Nullable Object arg) { if (!this.isDebugEnabled()) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - null, - FQCN, - LocationAwareLogger.DEBUG_INT, - this.serialize(format), - new Object[] {this.maybeSerialize(arg)}, - null - ); - } else { - this.logger.debug(this.serialize(format), this.maybeSerialize(arg)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.DEBUG, null, format, null, new Object[] {arg}, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + null, + FQCN, + LocationAwareLogger.DEBUG_INT, + this.serialize(format), + new Object[] {this.maybeSerialize(arg)}, + null + ); + } else { + this.logger.debug(this.serialize(format), this.maybeSerialize(arg)); + } + } finally { + this.closeContext(scope); } } @@ -1284,17 +1630,22 @@ public void debug(final @NotNull Component format, final @Nullable Object arg) { public void debug(final @NotNull Component format, final @Nullable Object arg1, final @Nullable Object arg2) { if (!this.isDebugEnabled()) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - null, - FQCN, - LocationAwareLogger.DEBUG_INT, - this.serialize(format), - new Object[] {this.maybeSerialize(arg1), this.maybeSerialize(arg2)}, - null - ); - } else { - this.logger.debug(this.serialize(format), this.maybeSerialize(arg1), this.maybeSerialize(arg2)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.DEBUG, null, format, null, new Object[] {arg1, arg2}, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + null, + FQCN, + LocationAwareLogger.DEBUG_INT, + this.serialize(format), + new Object[] {this.maybeSerialize(arg1), this.maybeSerialize(arg2)}, + null + ); + } else { + this.logger.debug(this.serialize(format), this.maybeSerialize(arg1), this.maybeSerialize(arg2)); + } + } finally { + this.closeContext(scope); } } @@ -1302,17 +1653,22 @@ public void debug(final @NotNull Component format, final @Nullable Object arg1, public void debug(final @NotNull Component format, final @Nullable Object @NotNull... arguments) { if (!this.isDebugEnabled()) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - null, - FQCN, - LocationAwareLogger.DEBUG_INT, - this.serialize(format), - this.maybeSerialize(arguments), - null - ); - } else { - this.logger.debug(this.serialize(format), this.maybeSerialize(arguments)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.DEBUG, null, format, null, arguments, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + null, + FQCN, + LocationAwareLogger.DEBUG_INT, + this.serialize(format), + this.maybeSerialize(arguments), + null + ); + } else { + this.logger.debug(this.serialize(format), this.maybeSerialize(arguments)); + } + } finally { + this.closeContext(scope); } } @@ -1320,17 +1676,22 @@ public void debug(final @NotNull Component format, final @Nullable Object @NotNu public void debug(final @NotNull Component msg, final @Nullable Throwable t) { if (!this.isDebugEnabled()) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - null, - FQCN, - LocationAwareLogger.DEBUG_INT, - this.serialize(msg), - null, - UnpackedComponentThrowable.unpack(t, this.serializer) - ); - } else { - this.logger.debug(this.serialize(msg), UnpackedComponentThrowable.unpack(t, this.serializer)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.DEBUG, null, msg, null, null, t); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + null, + FQCN, + LocationAwareLogger.DEBUG_INT, + this.serialize(msg), + null, + UnpackedComponentThrowable.unpack(t, this.serializer) + ); + } else { + this.logger.debug(this.serialize(msg), UnpackedComponentThrowable.unpack(t, this.serializer)); + } + } finally { + this.closeContext(scope); } } @@ -1338,17 +1699,22 @@ public void debug(final @NotNull Component msg, final @Nullable Throwable t) { public void debug(final @NotNull Marker marker, final @NotNull Component msg) { if (!this.isDebugEnabled(marker)) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - marker, - FQCN, - LocationAwareLogger.DEBUG_INT, - this.serialize(msg), - null, - null - ); - } else { - this.logger.debug(marker, this.serialize(msg)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.DEBUG, marker, msg, null, null, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + marker, + FQCN, + LocationAwareLogger.DEBUG_INT, + this.serialize(msg), + null, + null + ); + } else { + this.logger.debug(marker, this.serialize(msg)); + } + } finally { + this.closeContext(scope); } } @@ -1356,17 +1722,22 @@ public void debug(final @NotNull Marker marker, final @NotNull Component msg) { public void debug(final @NotNull Marker marker, final @NotNull Component format, final @Nullable Object arg) { if (!this.isDebugEnabled(marker)) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - marker, - FQCN, - LocationAwareLogger.DEBUG_INT, - this.serialize(format), - new Object[] {this.maybeSerialize(arg)}, - null - ); - } else { - this.logger.debug(marker, this.serialize(format), this.maybeSerialize(arg)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.DEBUG, marker, format, null, new Object[] {arg}, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + marker, + FQCN, + LocationAwareLogger.DEBUG_INT, + this.serialize(format), + new Object[] {this.maybeSerialize(arg)}, + null + ); + } else { + this.logger.debug(marker, this.serialize(format), this.maybeSerialize(arg)); + } + } finally { + this.closeContext(scope); } } @@ -1374,17 +1745,22 @@ public void debug(final @NotNull Marker marker, final @NotNull Component format, public void debug(final @NotNull Marker marker, final @NotNull Component format, final @Nullable Object arg1, final @Nullable Object arg2) { if (!this.isDebugEnabled(marker)) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - marker, - FQCN, - LocationAwareLogger.DEBUG_INT, - this.serialize(format), - new Object[] {this.maybeSerialize(arg1), this.maybeSerialize(arg2)}, - null - ); - } else { - this.logger.debug(marker, this.serialize(format), this.maybeSerialize(arg1), this.maybeSerialize(arg2)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.DEBUG, marker, format, null, new Object[] {arg1, arg2}, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + marker, + FQCN, + LocationAwareLogger.DEBUG_INT, + this.serialize(format), + new Object[] {this.maybeSerialize(arg1), this.maybeSerialize(arg2)}, + null + ); + } else { + this.logger.debug(marker, this.serialize(format), this.maybeSerialize(arg1), this.maybeSerialize(arg2)); + } + } finally { + this.closeContext(scope); } } @@ -1392,17 +1768,22 @@ public void debug(final @NotNull Marker marker, final @NotNull Component format, public void debug(final @NotNull Marker marker, final @NotNull Component format, final @Nullable Object @NotNull... argArray) { if (!this.isDebugEnabled(marker)) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - marker, - FQCN, - LocationAwareLogger.DEBUG_INT, - this.serialize(format), - this.maybeSerialize(argArray), - null - ); - } else { - this.logger.debug(marker, this.serialize(format), this.maybeSerialize(argArray)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.DEBUG, marker, format, null, argArray, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + marker, + FQCN, + LocationAwareLogger.DEBUG_INT, + this.serialize(format), + this.maybeSerialize(argArray), + null + ); + } else { + this.logger.debug(marker, this.serialize(format), this.maybeSerialize(argArray)); + } + } finally { + this.closeContext(scope); } } @@ -1410,17 +1791,22 @@ public void debug(final @NotNull Marker marker, final @NotNull Component format, public void debug(final @NotNull Marker marker, final @NotNull Component msg, final @Nullable Throwable t) { if (!this.isDebugEnabled(marker)) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - marker, - FQCN, - LocationAwareLogger.DEBUG_INT, - this.serialize(msg), - null, - UnpackedComponentThrowable.unpack(t, this.serializer) - ); - } else { - this.logger.debug(marker, this.serialize(msg), UnpackedComponentThrowable.unpack(t, this.serializer)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.DEBUG, marker, msg, null, null, t); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + marker, + FQCN, + LocationAwareLogger.DEBUG_INT, + this.serialize(msg), + null, + UnpackedComponentThrowable.unpack(t, this.serializer) + ); + } else { + this.logger.debug(marker, this.serialize(msg), UnpackedComponentThrowable.unpack(t, this.serializer)); + } + } finally { + this.closeContext(scope); } } @@ -1428,17 +1814,22 @@ public void debug(final @NotNull Marker marker, final @NotNull Component msg, fi public void info(final @NotNull Component format) { if (!this.isInfoEnabled()) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - null, - FQCN, - LocationAwareLogger.INFO_INT, - this.serialize(format), - null, - null - ); - } else { - this.logger.info(this.serialize(format)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.INFO, null, format, null, null, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + null, + FQCN, + LocationAwareLogger.INFO_INT, + this.serialize(format), + null, + null + ); + } else { + this.logger.info(this.serialize(format)); + } + } finally { + this.closeContext(scope); } } @@ -1446,17 +1837,22 @@ public void info(final @NotNull Component format) { public void info(final @NotNull Component format, final @Nullable Object arg) { if (!this.isInfoEnabled()) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - null, - FQCN, - LocationAwareLogger.INFO_INT, - this.serialize(format), - new Object[] {this.maybeSerialize(arg)}, - null - ); - } else { - this.logger.info(this.serialize(format), this.maybeSerialize(arg)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.INFO, null, format, null, new Object[] {arg}, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + null, + FQCN, + LocationAwareLogger.INFO_INT, + this.serialize(format), + new Object[] {this.maybeSerialize(arg)}, + null + ); + } else { + this.logger.info(this.serialize(format), this.maybeSerialize(arg)); + } + } finally { + this.closeContext(scope); } } @@ -1464,17 +1860,22 @@ public void info(final @NotNull Component format, final @Nullable Object arg) { public void info(final @NotNull Component format, final @Nullable Object arg1, final @Nullable Object arg2) { if (!this.isInfoEnabled()) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - null, - FQCN, - LocationAwareLogger.INFO_INT, - this.serialize(format), - new Object[] {this.maybeSerialize(arg1), this.maybeSerialize(arg2)}, - null - ); - } else { - this.logger.info(this.serialize(format), this.maybeSerialize(arg1), this.maybeSerialize(arg2)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.INFO, null, format, null, new Object[] {arg1, arg2}, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + null, + FQCN, + LocationAwareLogger.INFO_INT, + this.serialize(format), + new Object[] {this.maybeSerialize(arg1), this.maybeSerialize(arg2)}, + null + ); + } else { + this.logger.info(this.serialize(format), this.maybeSerialize(arg1), this.maybeSerialize(arg2)); + } + } finally { + this.closeContext(scope); } } @@ -1482,17 +1883,22 @@ public void info(final @NotNull Component format, final @Nullable Object arg1, f public void info(final @NotNull Component format, final @Nullable Object @NotNull... arguments) { if (!this.isInfoEnabled()) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - null, - FQCN, - LocationAwareLogger.INFO_INT, - this.serialize(format), - this.maybeSerialize(arguments), - null - ); - } else { - this.logger.info(this.serialize(format), this.maybeSerialize(arguments)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.INFO, null, format, null, arguments, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + null, + FQCN, + LocationAwareLogger.INFO_INT, + this.serialize(format), + this.maybeSerialize(arguments), + null + ); + } else { + this.logger.info(this.serialize(format), this.maybeSerialize(arguments)); + } + } finally { + this.closeContext(scope); } } @@ -1500,17 +1906,22 @@ public void info(final @NotNull Component format, final @Nullable Object @NotNul public void info(final @NotNull Component msg, final @Nullable Throwable t) { if (!this.isInfoEnabled()) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - null, - FQCN, - LocationAwareLogger.INFO_INT, - this.serialize(msg), - null, - UnpackedComponentThrowable.unpack(t, this.serializer) - ); - } else { - this.logger.info(this.serialize(msg), UnpackedComponentThrowable.unpack(t, this.serializer)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.INFO, null, msg, null, null, t); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + null, + FQCN, + LocationAwareLogger.INFO_INT, + this.serialize(msg), + null, + UnpackedComponentThrowable.unpack(t, this.serializer) + ); + } else { + this.logger.info(this.serialize(msg), UnpackedComponentThrowable.unpack(t, this.serializer)); + } + } finally { + this.closeContext(scope); } } @@ -1518,17 +1929,22 @@ public void info(final @NotNull Component msg, final @Nullable Throwable t) { public void info(final @NotNull Marker marker, final @NotNull Component msg) { if (!this.isInfoEnabled(marker)) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - marker, - FQCN, - LocationAwareLogger.INFO_INT, - this.serialize(msg), - null, - null - ); - } else { - this.logger.info(marker, this.serialize(msg)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.INFO, marker, msg, null, null, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + marker, + FQCN, + LocationAwareLogger.INFO_INT, + this.serialize(msg), + null, + null + ); + } else { + this.logger.info(marker, this.serialize(msg)); + } + } finally { + this.closeContext(scope); } } @@ -1536,17 +1952,22 @@ public void info(final @NotNull Marker marker, final @NotNull Component msg) { public void info(final @NotNull Marker marker, final @NotNull Component format, final @Nullable Object arg) { if (!this.isInfoEnabled(marker)) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - marker, - FQCN, - LocationAwareLogger.INFO_INT, - this.serialize(format), - new Object[] {this.maybeSerialize(arg)}, - null - ); - } else { - this.logger.info(marker, this.serialize(format), this.maybeSerialize(arg)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.INFO, marker, format, null, new Object[] {arg}, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + marker, + FQCN, + LocationAwareLogger.INFO_INT, + this.serialize(format), + new Object[] {this.maybeSerialize(arg)}, + null + ); + } else { + this.logger.info(marker, this.serialize(format), this.maybeSerialize(arg)); + } + } finally { + this.closeContext(scope); } } @@ -1554,17 +1975,22 @@ public void info(final @NotNull Marker marker, final @NotNull Component format, public void info(final @NotNull Marker marker, final @NotNull Component format, final @Nullable Object arg1, final @Nullable Object arg2) { if (!this.isInfoEnabled(marker)) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - marker, - FQCN, - LocationAwareLogger.INFO_INT, - this.serialize(format), - new Object[] {this.maybeSerialize(arg1), this.maybeSerialize(arg2)}, - null - ); - } else { - this.logger.info(marker, this.serialize(format), this.maybeSerialize(arg1), this.maybeSerialize(arg2)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.INFO, marker, format, null, new Object[] {arg1, arg2}, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + marker, + FQCN, + LocationAwareLogger.INFO_INT, + this.serialize(format), + new Object[] {this.maybeSerialize(arg1), this.maybeSerialize(arg2)}, + null + ); + } else { + this.logger.info(marker, this.serialize(format), this.maybeSerialize(arg1), this.maybeSerialize(arg2)); + } + } finally { + this.closeContext(scope); } } @@ -1572,17 +1998,22 @@ public void info(final @NotNull Marker marker, final @NotNull Component format, public void info(final @NotNull Marker marker, final @NotNull Component format, final @Nullable Object @NotNull... argArray) { if (!this.isInfoEnabled(marker)) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - marker, - FQCN, - LocationAwareLogger.INFO_INT, - this.serialize(format), - this.maybeSerialize(argArray), - null - ); - } else { - this.logger.info(marker, this.serialize(format), this.maybeSerialize(argArray)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.INFO, marker, format, null, argArray, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + marker, + FQCN, + LocationAwareLogger.INFO_INT, + this.serialize(format), + this.maybeSerialize(argArray), + null + ); + } else { + this.logger.info(marker, this.serialize(format), this.maybeSerialize(argArray)); + } + } finally { + this.closeContext(scope); } } @@ -1590,17 +2021,22 @@ public void info(final @NotNull Marker marker, final @NotNull Component format, public void info(final @NotNull Marker marker, final @NotNull Component msg, final @Nullable Throwable t) { if (!this.isInfoEnabled(marker)) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - marker, - FQCN, - LocationAwareLogger.INFO_INT, - this.serialize(msg), - null, - UnpackedComponentThrowable.unpack(t, this.serializer) - ); - } else { - this.logger.info(marker, this.serialize(msg), UnpackedComponentThrowable.unpack(t, this.serializer)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.INFO, marker, msg, null, null, t); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + marker, + FQCN, + LocationAwareLogger.INFO_INT, + this.serialize(msg), + null, + UnpackedComponentThrowable.unpack(t, this.serializer) + ); + } else { + this.logger.info(marker, this.serialize(msg), UnpackedComponentThrowable.unpack(t, this.serializer)); + } + } finally { + this.closeContext(scope); } } @@ -1608,17 +2044,22 @@ public void info(final @NotNull Marker marker, final @NotNull Component msg, fin public void warn(final @NotNull Component format) { if (!this.isWarnEnabled()) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - null, - FQCN, - LocationAwareLogger.WARN_INT, - this.serialize(format), - null, - null - ); - } else { - this.logger.warn(this.serialize(format)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.WARN, null, format, null, null, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + null, + FQCN, + LocationAwareLogger.WARN_INT, + this.serialize(format), + null, + null + ); + } else { + this.logger.warn(this.serialize(format)); + } + } finally { + this.closeContext(scope); } } @@ -1626,17 +2067,22 @@ public void warn(final @NotNull Component format) { public void warn(final @NotNull Component format, final @Nullable Object arg) { if (!this.isWarnEnabled()) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - null, - FQCN, - LocationAwareLogger.WARN_INT, - this.serialize(format), - new Object[] {this.maybeSerialize(arg)}, - null - ); - } else { - this.logger.warn(this.serialize(format), this.maybeSerialize(arg)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.WARN, null, format, null, new Object[] {arg}, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + null, + FQCN, + LocationAwareLogger.WARN_INT, + this.serialize(format), + new Object[] {this.maybeSerialize(arg)}, + null + ); + } else { + this.logger.warn(this.serialize(format), this.maybeSerialize(arg)); + } + } finally { + this.closeContext(scope); } } @@ -1644,17 +2090,22 @@ public void warn(final @NotNull Component format, final @Nullable Object arg) { public void warn(final @NotNull Component format, final @Nullable Object arg1, final @Nullable Object arg2) { if (!this.isWarnEnabled()) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - null, - FQCN, - LocationAwareLogger.WARN_INT, - this.serialize(format), - new Object[] {this.maybeSerialize(arg1), this.maybeSerialize(arg2)}, - null - ); - } else { - this.logger.warn(this.serialize(format), this.maybeSerialize(arg1), this.maybeSerialize(arg2)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.WARN, null, format, null, new Object[] {arg1, arg2}, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + null, + FQCN, + LocationAwareLogger.WARN_INT, + this.serialize(format), + new Object[] {this.maybeSerialize(arg1), this.maybeSerialize(arg2)}, + null + ); + } else { + this.logger.warn(this.serialize(format), this.maybeSerialize(arg1), this.maybeSerialize(arg2)); + } + } finally { + this.closeContext(scope); } } @@ -1662,17 +2113,22 @@ public void warn(final @NotNull Component format, final @Nullable Object arg1, f public void warn(final @NotNull Component format, final @Nullable Object @NotNull... arguments) { if (!this.isWarnEnabled()) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - null, - FQCN, - LocationAwareLogger.WARN_INT, - this.serialize(format), - this.maybeSerialize(arguments), - null - ); - } else { - this.logger.warn(this.serialize(format), this.maybeSerialize(arguments)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.WARN, null, format, null, arguments, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + null, + FQCN, + LocationAwareLogger.WARN_INT, + this.serialize(format), + this.maybeSerialize(arguments), + null + ); + } else { + this.logger.warn(this.serialize(format), this.maybeSerialize(arguments)); + } + } finally { + this.closeContext(scope); } } @@ -1680,17 +2136,22 @@ public void warn(final @NotNull Component format, final @Nullable Object @NotNul public void warn(final @NotNull Component msg, final @Nullable Throwable t) { if (!this.isWarnEnabled()) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - null, - FQCN, - LocationAwareLogger.WARN_INT, - this.serialize(msg), - null, - UnpackedComponentThrowable.unpack(t, this.serializer) - ); - } else { - this.logger.warn(this.serialize(msg), UnpackedComponentThrowable.unpack(t, this.serializer)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.WARN, null, msg, null, null, t); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + null, + FQCN, + LocationAwareLogger.WARN_INT, + this.serialize(msg), + null, + UnpackedComponentThrowable.unpack(t, this.serializer) + ); + } else { + this.logger.warn(this.serialize(msg), UnpackedComponentThrowable.unpack(t, this.serializer)); + } + } finally { + this.closeContext(scope); } } @@ -1698,17 +2159,22 @@ public void warn(final @NotNull Component msg, final @Nullable Throwable t) { public void warn(final @NotNull Marker marker, final @NotNull Component msg) { if (!this.isWarnEnabled(marker)) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - marker, - FQCN, - LocationAwareLogger.WARN_INT, - this.serialize(msg), - null, - null - ); - } else { - this.logger.warn(marker, this.serialize(msg)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.WARN, marker, msg, null, null, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + marker, + FQCN, + LocationAwareLogger.WARN_INT, + this.serialize(msg), + null, + null + ); + } else { + this.logger.warn(marker, this.serialize(msg)); + } + } finally { + this.closeContext(scope); } } @@ -1716,17 +2182,22 @@ public void warn(final @NotNull Marker marker, final @NotNull Component msg) { public void warn(final @NotNull Marker marker, final @NotNull Component format, final @Nullable Object arg) { if (!this.isWarnEnabled(marker)) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - marker, - FQCN, - LocationAwareLogger.WARN_INT, - this.serialize(format), - new Object[] {this.maybeSerialize(arg)}, - null - ); - } else { - this.logger.warn(marker, this.serialize(format), this.maybeSerialize(arg)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.WARN, marker, format, null, new Object[] {arg}, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + marker, + FQCN, + LocationAwareLogger.WARN_INT, + this.serialize(format), + new Object[] {this.maybeSerialize(arg)}, + null + ); + } else { + this.logger.warn(marker, this.serialize(format), this.maybeSerialize(arg)); + } + } finally { + this.closeContext(scope); } } @@ -1734,17 +2205,22 @@ public void warn(final @NotNull Marker marker, final @NotNull Component format, public void warn(final @NotNull Marker marker, final @NotNull Component format, final @Nullable Object arg1, final @Nullable Object arg2) { if (!this.isWarnEnabled(marker)) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - marker, - FQCN, - LocationAwareLogger.WARN_INT, - this.serialize(format), - new Object[] {this.maybeSerialize(arg1), this.maybeSerialize(arg2)}, - null - ); - } else { - this.logger.warn(marker, this.serialize(format), this.maybeSerialize(arg1), this.maybeSerialize(arg2)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.WARN, marker, format, null, new Object[] {arg1, arg2}, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + marker, + FQCN, + LocationAwareLogger.WARN_INT, + this.serialize(format), + new Object[] {this.maybeSerialize(arg1), this.maybeSerialize(arg2)}, + null + ); + } else { + this.logger.warn(marker, this.serialize(format), this.maybeSerialize(arg1), this.maybeSerialize(arg2)); + } + } finally { + this.closeContext(scope); } } @@ -1752,17 +2228,22 @@ public void warn(final @NotNull Marker marker, final @NotNull Component format, public void warn(final @NotNull Marker marker, final @NotNull Component format, final @Nullable Object @NotNull... argArray) { if (!this.isWarnEnabled(marker)) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - marker, - FQCN, - LocationAwareLogger.WARN_INT, - this.serialize(format), - this.maybeSerialize(argArray), - null - ); - } else { - this.logger.warn(marker, this.serialize(format), this.maybeSerialize(argArray)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.WARN, marker, format, null, argArray, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + marker, + FQCN, + LocationAwareLogger.WARN_INT, + this.serialize(format), + this.maybeSerialize(argArray), + null + ); + } else { + this.logger.warn(marker, this.serialize(format), this.maybeSerialize(argArray)); + } + } finally { + this.closeContext(scope); } } @@ -1770,17 +2251,22 @@ public void warn(final @NotNull Marker marker, final @NotNull Component format, public void warn(final @NotNull Marker marker, final @NotNull Component msg, final @Nullable Throwable t) { if (!this.isWarnEnabled(marker)) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - marker, - FQCN, - LocationAwareLogger.WARN_INT, - this.serialize(msg), - null, - UnpackedComponentThrowable.unpack(t, this.serializer) - ); - } else { - this.logger.warn(marker, this.serialize(msg), UnpackedComponentThrowable.unpack(t, this.serializer)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.WARN, marker, msg, null, null, t); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + marker, + FQCN, + LocationAwareLogger.WARN_INT, + this.serialize(msg), + null, + UnpackedComponentThrowable.unpack(t, this.serializer) + ); + } else { + this.logger.warn(marker, this.serialize(msg), UnpackedComponentThrowable.unpack(t, this.serializer)); + } + } finally { + this.closeContext(scope); } } @@ -1788,17 +2274,22 @@ public void warn(final @NotNull Marker marker, final @NotNull Component msg, fin public void error(final @NotNull Component format) { if (!this.isErrorEnabled()) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - null, - FQCN, - LocationAwareLogger.ERROR_INT, - this.serialize(format), - null, - null - ); - } else { - this.logger.error(this.serialize(format)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.ERROR, null, format, null, null, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + null, + FQCN, + LocationAwareLogger.ERROR_INT, + this.serialize(format), + null, + null + ); + } else { + this.logger.error(this.serialize(format)); + } + } finally { + this.closeContext(scope); } } @@ -1806,17 +2297,22 @@ public void error(final @NotNull Component format) { public void error(final @NotNull Component format, final @Nullable Object arg) { if (!this.isErrorEnabled()) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - null, - FQCN, - LocationAwareLogger.ERROR_INT, - this.serialize(format), - new Object[] {this.maybeSerialize(arg)}, - null - ); - } else { - this.logger.error(this.serialize(format), this.maybeSerialize(arg)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.ERROR, null, format, null, new Object[] {arg}, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + null, + FQCN, + LocationAwareLogger.ERROR_INT, + this.serialize(format), + new Object[] {this.maybeSerialize(arg)}, + null + ); + } else { + this.logger.error(this.serialize(format), this.maybeSerialize(arg)); + } + } finally { + this.closeContext(scope); } } @@ -1824,17 +2320,22 @@ public void error(final @NotNull Component format, final @Nullable Object arg) { public void error(final @NotNull Component format, final @Nullable Object arg1, final @Nullable Object arg2) { if (!this.isErrorEnabled()) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - null, - FQCN, - LocationAwareLogger.ERROR_INT, - this.serialize(format), - new Object[] {this.maybeSerialize(arg1), this.maybeSerialize(arg2)}, - null - ); - } else { - this.logger.error(this.serialize(format), this.maybeSerialize(arg1), this.maybeSerialize(arg2)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.ERROR, null, format, null, new Object[] {arg1, arg2}, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + null, + FQCN, + LocationAwareLogger.ERROR_INT, + this.serialize(format), + new Object[] {this.maybeSerialize(arg1), this.maybeSerialize(arg2)}, + null + ); + } else { + this.logger.error(this.serialize(format), this.maybeSerialize(arg1), this.maybeSerialize(arg2)); + } + } finally { + this.closeContext(scope); } } @@ -1842,17 +2343,22 @@ public void error(final @NotNull Component format, final @Nullable Object arg1, public void error(final @NotNull Component format, final @Nullable Object @NotNull... arguments) { if (!this.isErrorEnabled()) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - null, - FQCN, - LocationAwareLogger.ERROR_INT, - this.serialize(format), - this.maybeSerialize(arguments), - null - ); - } else { - this.logger.error(this.serialize(format), this.maybeSerialize(arguments)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.ERROR, null, format, null, arguments, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + null, + FQCN, + LocationAwareLogger.ERROR_INT, + this.serialize(format), + this.maybeSerialize(arguments), + null + ); + } else { + this.logger.error(this.serialize(format), this.maybeSerialize(arguments)); + } + } finally { + this.closeContext(scope); } } @@ -1860,17 +2366,22 @@ public void error(final @NotNull Component format, final @Nullable Object @NotNu public void error(final @NotNull Component msg, final @Nullable Throwable t) { if (!this.isErrorEnabled()) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - null, - FQCN, - LocationAwareLogger.ERROR_INT, - this.serialize(msg), - null, - UnpackedComponentThrowable.unpack(t, this.serializer) - ); - } else { - this.logger.error(this.serialize(msg), UnpackedComponentThrowable.unpack(t, this.serializer)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.ERROR, null, msg, null, null, t); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + null, + FQCN, + LocationAwareLogger.ERROR_INT, + this.serialize(msg), + null, + UnpackedComponentThrowable.unpack(t, this.serializer) + ); + } else { + this.logger.error(this.serialize(msg), UnpackedComponentThrowable.unpack(t, this.serializer)); + } + } finally { + this.closeContext(scope); } } @@ -1878,17 +2389,22 @@ public void error(final @NotNull Component msg, final @Nullable Throwable t) { public void error(final @NotNull Marker marker, final @NotNull Component msg) { if (!this.isErrorEnabled(marker)) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - marker, - FQCN, - LocationAwareLogger.ERROR_INT, - this.serialize(msg), - null, - null - ); - } else { - this.logger.error(marker, this.serialize(msg)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.ERROR, marker, msg, null, null, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + marker, + FQCN, + LocationAwareLogger.ERROR_INT, + this.serialize(msg), + null, + null + ); + } else { + this.logger.error(marker, this.serialize(msg)); + } + } finally { + this.closeContext(scope); } } @@ -1896,17 +2412,22 @@ public void error(final @NotNull Marker marker, final @NotNull Component msg) { public void error(final @NotNull Marker marker, final @NotNull Component format, final @Nullable Object arg) { if (!this.isErrorEnabled(marker)) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - marker, - FQCN, - LocationAwareLogger.ERROR_INT, - this.serialize(format), - new Object[] {this.maybeSerialize(arg)}, - null - ); - } else { - this.logger.error(marker, this.serialize(format), this.maybeSerialize(arg)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.ERROR, marker, format, null, new Object[] {arg}, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + marker, + FQCN, + LocationAwareLogger.ERROR_INT, + this.serialize(format), + new Object[] {this.maybeSerialize(arg)}, + null + ); + } else { + this.logger.error(marker, this.serialize(format), this.maybeSerialize(arg)); + } + } finally { + this.closeContext(scope); } } @@ -1914,17 +2435,22 @@ public void error(final @NotNull Marker marker, final @NotNull Component format, public void error(final @NotNull Marker marker, final @NotNull Component format, final @Nullable Object arg1, final @Nullable Object arg2) { if (!this.isErrorEnabled(marker)) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - marker, - FQCN, - LocationAwareLogger.ERROR_INT, - this.serialize(format), - new Object[] {this.maybeSerialize(arg1), this.maybeSerialize(arg2)}, - null - ); - } else { - this.logger.error(marker, this.serialize(format), this.maybeSerialize(arg1), this.maybeSerialize(arg2)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.ERROR, marker, format, null, new Object[] {arg1, arg2}, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + marker, + FQCN, + LocationAwareLogger.ERROR_INT, + this.serialize(format), + new Object[] {this.maybeSerialize(arg1), this.maybeSerialize(arg2)}, + null + ); + } else { + this.logger.error(marker, this.serialize(format), this.maybeSerialize(arg1), this.maybeSerialize(arg2)); + } + } finally { + this.closeContext(scope); } } @@ -1932,17 +2458,22 @@ public void error(final @NotNull Marker marker, final @NotNull Component format, public void error(final @NotNull Marker marker, final @NotNull Component format, final @Nullable Object @NotNull... argArray) { if (!this.isErrorEnabled(marker)) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - marker, - FQCN, - LocationAwareLogger.ERROR_INT, - this.serialize(format), - this.maybeSerialize(argArray), - null - ); - } else { - this.logger.error(marker, this.serialize(format), this.maybeSerialize(argArray)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.ERROR, marker, format, null, argArray, null); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + marker, + FQCN, + LocationAwareLogger.ERROR_INT, + this.serialize(format), + this.maybeSerialize(argArray), + null + ); + } else { + this.logger.error(marker, this.serialize(format), this.maybeSerialize(argArray)); + } + } finally { + this.closeContext(scope); } } @@ -1950,17 +2481,22 @@ public void error(final @NotNull Marker marker, final @NotNull Component format, public void error(final @NotNull Marker marker, final @NotNull Component msg, final @Nullable Throwable t) { if (!this.isErrorEnabled(marker)) return; - if (this.isLocationAware) { - ((LocationAwareLogger) this.logger).log( - marker, - FQCN, - LocationAwareLogger.ERROR_INT, - this.serialize(msg), - null, - UnpackedComponentThrowable.unpack(t, this.serializer) - ); - } else { - this.logger.error(marker, this.serialize(msg), UnpackedComponentThrowable.unpack(t, this.serializer)); + final ComponentLogContextInjector.@Nullable Scope scope = this.beginContext(Level.ERROR, marker, msg, null, null, t); + try { + if (this.isLocationAware) { + ((LocationAwareLogger) this.logger).log( + marker, + FQCN, + LocationAwareLogger.ERROR_INT, + this.serialize(msg), + null, + UnpackedComponentThrowable.unpack(t, this.serializer) + ); + } else { + this.logger.error(marker, this.serialize(msg), UnpackedComponentThrowable.unpack(t, this.serializer)); + } + } finally { + this.closeContext(scope); } } } diff --git a/text-logger-slf4j/src/test/java/net/kyori/adventure/text/logger/slf4j/ComponentLoggerTest.java b/text-logger-slf4j/src/test/java/net/kyori/adventure/text/logger/slf4j/ComponentLoggerTest.java index 592451337b..b607835ce2 100644 --- a/text-logger-slf4j/src/test/java/net/kyori/adventure/text/logger/slf4j/ComponentLoggerTest.java +++ b/text-logger-slf4j/src/test/java/net/kyori/adventure/text/logger/slf4j/ComponentLoggerTest.java @@ -28,7 +28,11 @@ import com.github.valfirst.slf4jtest.TestLoggerFactory; import com.github.valfirst.slf4jtest.TestLoggerFactoryExtension; import com.google.common.collect.ImmutableList; +import java.lang.reflect.Proxy; import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Function; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.util.ComponentMessageThrowable; @@ -36,17 +40,22 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.slf4j.Logger; import org.slf4j.Marker; import org.slf4j.MarkerFactory; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @ExtendWith(TestLoggerFactoryExtension.class) public class ComponentLoggerTest { private static final TestLogger LOGGER = TestLoggerFactory.getTestLogger(ComponentLoggerTest.class); + private static final Function PLAIN_SERIALIZER = Handler.LoggerHelperImpl.INSTANCE.plainSerializer(); private static final Marker MARKED = MarkerFactory.getMarker("MARKED"); @@ -54,6 +63,10 @@ ComponentLogger makeLogger() { return ComponentLogger.logger(); } + ComponentLogger makeLogger(final @Nullable ComponentLogContextInjector injector) { + return new WrappingComponentLoggerImpl(LOGGER, PLAIN_SERIALIZER, injector); + } + @Test void testCallerLogger() { final ComponentLogger logger = ComponentLogger.logger(); @@ -158,6 +171,104 @@ void testComponentAsArgToPlainLog() { ); } + @Test + void testInjectorReceivesRawComponentRecord() { + final Component format = Component.text("Hello ").append(Component.text("{}", NamedTextColor.BLUE)); + final Component arg = Component.text("friend", NamedTextColor.RED); + final AtomicReference seen = new AtomicReference<>(); + + this.makeLogger(record -> { + seen.set(record); + return null; + }).info(format, arg); + + final ComponentLogRecord captured = seen.get(); + assertNotNull(captured); + assertEquals(org.slf4j.event.Level.INFO, captured.level()); + assertSame(format, captured.componentFormatOrMessage()); + assertNull(captured.stringFormatOrMessage()); + assertNotNull(captured.arguments()); + assertEquals(1, captured.arguments().length); + assertSame(arg, captured.arguments()[0]); + assertNull(captured.throwable()); + assertEquals(LOGGER.getLoggingEvents(), ImmutableList.of(LoggingEvent.info("Hello {}", "friend"))); + } + + @Test + void testInjectorReceivesRawThrowableForStringRecord() { + final RichTestException throwable = new RichTestException(Component.text("rich")); + final AtomicReference seen = new AtomicReference<>(); + + this.makeLogger(record -> { + seen.set(record); + return null; + }).warn("warn text", throwable); + + final ComponentLogRecord captured = seen.get(); + assertNotNull(captured); + assertEquals(org.slf4j.event.Level.WARN, captured.level()); + assertEquals("warn text", captured.stringFormatOrMessage()); + assertNull(captured.componentFormatOrMessage()); + assertNull(captured.arguments()); + assertSame(throwable, captured.throwable()); + } + + @Test + void testInjectorScopeClosedOnSuccessAndExceptionsSwallowed() { + final AtomicInteger beginCalls = new AtomicInteger(); + final AtomicInteger closeCalls = new AtomicInteger(); + + this.makeLogger(record -> { + beginCalls.incrementAndGet(); + return () -> { + closeCalls.incrementAndGet(); + throw new IllegalStateException("close fail"); + }; + }).info("Hello world"); + + assertEquals(1, beginCalls.get()); + assertEquals(1, closeCalls.get()); + assertEquals(LOGGER.getLoggingEvents(), ImmutableList.of(LoggingEvent.info("Hello world"))); + } + + @Test + void testInjectorBeginFailureIsSwallowed() { + this.makeLogger(record -> { + throw new IllegalStateException("begin fail"); + }).info("still logs"); + + assertEquals(LOGGER.getLoggingEvents(), ImmutableList.of(LoggingEvent.info("still logs"))); + } + + @Test + void testInjectorScopeClosedWhenUnderlyingLoggerThrows() { + final AtomicInteger closeCalls = new AtomicInteger(); + final Logger throwingLogger = (Logger) Proxy.newProxyInstance( + Logger.class.getClassLoader(), + new Class[] {Logger.class}, + (proxy, method, args) -> { + if (method.getName().equals("isInfoEnabled")) { + return true; + } else if (method.getName().equals("info") && method.getParameterCount() == 1) { + throw new IllegalStateException("logger fail"); + } else if (method.getName().equals("getName")) { + return "throwing"; + } + + if (method.getReturnType() == boolean.class) return false; + return null; + } + ); + final ComponentLogger logger = new WrappingComponentLoggerImpl( + throwingLogger, + PLAIN_SERIALIZER, + record -> () -> closeCalls.incrementAndGet() + ); + + assertThrows(IllegalStateException.class, () -> logger.info("hello")); + assertEquals(1, closeCalls.get()); + } + @Test @Disabled("We cannot implement this without forcing a binary dep at the moment") void testFluentApi() {