Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package org.apache.logging.log4j.kotlin.sample

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings
import org.apache.logging.log4j.kotlin.ContextMap
import org.apache.logging.log4j.kotlin.logger
import org.apache.logging.log4j.kotlin.extension.logger
import java.util.Random

@SuppressFBWarnings("PREDICTABLE_RANDOM", "DMI_RANDOM_USED_ONLY_ONCE")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ inline fun <reified T : Any> T.logger() = loggerOf(T::class.java)
*
* @since 1.3.0
*/
@Deprecated(
"Replace with extension.logger to avoid unintended consequences with explicitly declared logger properties. This will be removed in the next major release.",
replaceWith = ReplaceWith("logger", "org.apache.logging.log4j.kotlin.extension.logger")
)
inline val <reified T> T.logger: KotlinLogger
get() = cachedLoggerOf(T::class.java)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.apache.logging.log4j.kotlin.extension

import org.apache.logging.log4j.kotlin.KotlinLogger
import org.apache.logging.log4j.kotlin.cachedLoggerOf

/**
* Provides a logger named after the receiver object's class.
*
* Simply import this property and use it.
*
* ```
* import org.apache.logging.log4j.kotlin.extension.logger
*
* class MyClass {
* // use `logger` as necessary
* }
* ```
*
* Note that this is significantly slower than creating a logger explicitly, as it requires a lookup of the
* logger on each call via the property getter. We attempt to minimize the overhead of this by caching the
* loggers, but according to microbenchmarks, it is still about 3.5 times slower than creating a logger once
* and using it (about 4.2 nanoseconds per call instead of 1.2 nanoseconds).
*
* @since 1.3.0
*/
inline val <reified T> T.logger: KotlinLogger
get() = cachedLoggerOf(T::class.java)
Loading