This is an automated email from the ASF dual-hosted git repository.
rgupta pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j-kotlin.git
The following commit(s) were added to refs/heads/main by this push:
new 4601fde Move logger property to `extension` package (#137)
4601fde is described below
commit 4601fdec3a586abf14deec1fc1af563c5a32f126
Author: Raman Gupta <[email protected]>
AuthorDate: Wed Apr 1 07:07:42 2026 -0400
Move logger property to `extension` package (#137)
* Move logger property to `extension` package
The `logger` property conflicts with explicitly defined logger properties.
Given the performance considerations of the `logger` property, move it to
a separate package so imports of it are explicit and non-conflicting.
Resolves #136
* Logger extension: update docs
---
.../kotlin/sample/LoggingAppExtensionProperty.kt | 2 +-
.../apache/logging/log4j/kotlin/LoggingFactory.kt | 4 ++
.../kotlin/extension/LoggingFactoryExtension.kt | 43 ++++++++++++++++++++++
.../.1.x.x/logger-extension-separate-package.xml | 8 ++++
src/site/antora/modules/ROOT/pages/index.adoc | 2 +-
5 files changed, 57 insertions(+), 2 deletions(-)
diff --git
a/log4j-api-kotlin-sample/src/main/kotlin/org/apache/logging/log4j/kotlin/sample/LoggingAppExtensionProperty.kt
b/log4j-api-kotlin-sample/src/main/kotlin/org/apache/logging/log4j/kotlin/sample/LoggingAppExtensionProperty.kt
index f3f95ff..c48edc1 100644
---
a/log4j-api-kotlin-sample/src/main/kotlin/org/apache/logging/log4j/kotlin/sample/LoggingAppExtensionProperty.kt
+++
b/log4j-api-kotlin-sample/src/main/kotlin/org/apache/logging/log4j/kotlin/sample/LoggingAppExtensionProperty.kt
@@ -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")
diff --git
a/log4j-api-kotlin/src/main/kotlin/org/apache/logging/log4j/kotlin/LoggingFactory.kt
b/log4j-api-kotlin/src/main/kotlin/org/apache/logging/log4j/kotlin/LoggingFactory.kt
index d7dd316..859968b 100644
---
a/log4j-api-kotlin/src/main/kotlin/org/apache/logging/log4j/kotlin/LoggingFactory.kt
+++
b/log4j-api-kotlin/src/main/kotlin/org/apache/logging/log4j/kotlin/LoggingFactory.kt
@@ -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)
diff --git
a/log4j-api-kotlin/src/main/kotlin/org/apache/logging/log4j/kotlin/extension/LoggingFactoryExtension.kt
b/log4j-api-kotlin/src/main/kotlin/org/apache/logging/log4j/kotlin/extension/LoggingFactoryExtension.kt
new file mode 100644
index 0000000..3932fe8
--- /dev/null
+++
b/log4j-api-kotlin/src/main/kotlin/org/apache/logging/log4j/kotlin/extension/LoggingFactoryExtension.kt
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+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)
diff --git a/src/changelog/.1.x.x/logger-extension-separate-package.xml
b/src/changelog/.1.x.x/logger-extension-separate-package.xml
new file mode 100644
index 0000000..2386748
--- /dev/null
+++ b/src/changelog/.1.x.x/logger-extension-separate-package.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="https://logging.apache.org/xml/ns"
+ xsi:schemaLocation="https://logging.apache.org/xml/ns
https://logging.apache.org/xml/ns/log4j-changelog-0.xsd"
+ type="updated">
+ <issue id="137"
link="https://github.com/apache/logging-log4j-kotlin/pull/137"/>
+ <description format="asciidoc">Move the logger extension function to a
separate `extension` package</description>
+</entry>
diff --git a/src/site/antora/modules/ROOT/pages/index.adoc
b/src/site/antora/modules/ROOT/pages/index.adoc
index 473865b..494e404 100644
--- a/src/site/antora/modules/ROOT/pages/index.adoc
+++ b/src/site/antora/modules/ROOT/pages/index.adoc
@@ -193,7 +193,7 @@ You can use the `logger` extension property to dynamically
inject a logger at t
[source,kotlin]
----
-import org.apache.logging.log4j.kotlin.logger
+import org.apache.logging.log4j.kotlin.extension.logger
class DbTableService {